#little awk testing suite uses simple scripts to help with testing awk programs BEGIN { FS=" " awkcmd="gawk " input="" desc="" want="" } /^[ \t]*\#/ { next } #skip comments $1 == "desc:" { for (i=2; i<=NF; i++) desc = desc $i " " next } $1 == "input:" { input = $2; next } $1 == "src:" { for (i=2; i<=NF; i++) { if($i == "|") awkcmd = awkcmd "| gawk " else awkcmd = awkcmd "-f " $i ".awk " } next } $1 == "want:" { next } { if(want == "") want = $0 else want = want "\n" $0 } function runsrc() { if(awkcmd == "gawk ") print "Invalid test file, no sources given" else { system("cat " input " |" awkcmd " > " tmpdir"/" testfile ".got") print want > tmpdir "/" testfile ".want" close("want.tmp") } } function testoutput() { if (!system("diff -s "tmpdir"/"testfile".got "tmpdir"/"testfile".want > /dev/null")) print "Result: PASSED" else { print "Result: FAILED, got "tmpdir"/"testfile".got" } } END { banner= "\n----[ Test " testfile " ]-------------" print banner print "Description: " desc runsrc() testoutput() }