2005-09-20 21:31:55 +08:00
|
|
|
#!/usr/local/bin/fish
|
|
|
|
#
|
2014-10-03 03:31:46 +08:00
|
|
|
# Fishscript tests
|
2005-09-20 21:31:55 +08:00
|
|
|
|
2014-12-24 04:20:44 +08:00
|
|
|
# Change to directory containing this script
|
|
|
|
cd (dirname (status -f))
|
|
|
|
|
|
|
|
# Test files specified on commandline, or all *.in files
|
|
|
|
set -q argv[1]
|
|
|
|
if set -q argv[1]
|
|
|
|
set files_to_test $argv.in
|
|
|
|
else
|
|
|
|
set files_to_test *.in
|
|
|
|
end
|
|
|
|
|
|
|
|
source test_util.fish (status -f) $argv; or exit
|
2010-10-03 11:46:26 +08:00
|
|
|
|
2014-10-03 03:31:46 +08:00
|
|
|
say -o cyan "Testing high level script functionality"
|
2010-10-03 11:46:26 +08:00
|
|
|
|
2014-10-03 03:31:46 +08:00
|
|
|
function test_file
|
|
|
|
set -l file $argv[1]
|
|
|
|
set -l base (basename $file .in)
|
2010-10-03 11:46:26 +08:00
|
|
|
|
2014-10-03 03:31:46 +08:00
|
|
|
echo -n "Testing file $file ... "
|
2013-01-14 08:33:40 +08:00
|
|
|
|
2014-10-03 03:31:46 +08:00
|
|
|
../fish <$file >$base.tmp.out ^$base.tmp.err
|
|
|
|
set -l tmp_status $status
|
|
|
|
set -l res ok
|
2014-09-05 13:26:10 +08:00
|
|
|
|
2014-10-03 03:31:46 +08:00
|
|
|
diff $base.tmp.out $base.out >/dev/null
|
|
|
|
set -l out_status $status
|
|
|
|
diff $base.tmp.err $base.err >/dev/null
|
|
|
|
set -l err_status $status
|
|
|
|
set -l exp_status (cat $base.status)[1]
|
|
|
|
|
|
|
|
if test $out_status -eq 0 -a $err_status -eq 0 -a $exp_status -eq $tmp_status
|
|
|
|
say green "ok"
|
|
|
|
# clean up tmp files
|
|
|
|
rm -f $base.tmp.{err,out}
|
|
|
|
return 0
|
2014-09-05 13:26:10 +08:00
|
|
|
else
|
2014-10-03 03:31:46 +08:00
|
|
|
say red "fail"
|
|
|
|
if test $out_status -ne 0
|
|
|
|
say yellow "Output differs for file $file. Diff follows:"
|
|
|
|
colordiff -u $base.tmp.out $base.out
|
|
|
|
end
|
|
|
|
if test $err_status -ne 0
|
|
|
|
say yellow "Error output differs for file $file. Diff follows:"
|
|
|
|
colordiff -u $base.tmp.err $base.err
|
|
|
|
end
|
|
|
|
if test $exp_status -ne $tmp_status
|
|
|
|
say yellow "Exit status differs for file $file."
|
|
|
|
echo "Expected $exp_status, got $tmp_status."
|
|
|
|
end
|
|
|
|
return 1
|
2014-09-05 13:26:10 +08:00
|
|
|
end
|
2010-10-03 11:46:26 +08:00
|
|
|
end
|
|
|
|
|
2014-10-03 03:31:46 +08:00
|
|
|
set -l failed
|
2014-12-24 04:20:44 +08:00
|
|
|
for i in $files_to_test
|
2014-10-03 03:31:46 +08:00
|
|
|
if not test_file $i
|
|
|
|
set failed $failed $i
|
2014-09-05 13:26:10 +08:00
|
|
|
end
|
2014-10-03 03:31:46 +08:00
|
|
|
end
|
2005-09-20 21:31:55 +08:00
|
|
|
|
2014-10-03 03:31:46 +08:00
|
|
|
set failed (count $failed)
|
|
|
|
if test $failed -eq 0
|
|
|
|
say green "All tests completed successfully"
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
set plural (test $failed -eq 1; or echo s)
|
|
|
|
say red "$failed test$plural failed"
|
|
|
|
exit 1
|
2005-09-20 21:31:55 +08:00
|
|
|
end
|