2014-10-03 03:31:46 +08:00
|
|
|
# Fishscript tests
|
2016-02-07 10:08:22 +08:00
|
|
|
#
|
|
|
|
# There is no shebang line because you shouldn't be running this by hand. You
|
|
|
|
# should be running it via `make test` to ensure the environment is properly
|
|
|
|
# setup.
|
2005-09-20 21:31:55 +08:00
|
|
|
|
2017-01-29 12:37:32 +08:00
|
|
|
# Set this var to modify behavior of the code being tests. Such as avoiding running
|
|
|
|
# `fish_update_completions` when running tests.
|
|
|
|
set -x FISH_UNIT_TESTS_RUNNING 1
|
|
|
|
|
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
|
|
|
|
if set -q argv[1]
|
|
|
|
set files_to_test $argv.in
|
|
|
|
else
|
2019-06-10 02:13:31 +08:00
|
|
|
set files_to_test *.in checks/*.fish
|
2014-12-24 04:20:44 +08:00
|
|
|
end
|
|
|
|
|
2016-09-20 13:08:33 +08:00
|
|
|
# These env vars should not be inherited from the user environment because they can affect the
|
|
|
|
# behavior of the tests. So either remove them or set them to a known value.
|
|
|
|
# See also tests/interactive.fish.
|
|
|
|
set TERM xterm
|
|
|
|
set -e ITERM_PROFILE
|
|
|
|
|
2017-07-04 01:16:31 +08:00
|
|
|
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
|
|
|
|
2019-06-10 02:13:31 +08:00
|
|
|
function test_in_file
|
2014-10-03 03:31:46 +08:00
|
|
|
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 ... "
|
2018-09-04 05:13:31 +08:00
|
|
|
set starttime (date +%s)
|
2013-01-14 08:33:40 +08:00
|
|
|
|
2018-04-02 04:43:05 +08:00
|
|
|
../test/root/bin/fish <$file >$base.tmp.out 2>$base.tmp.err
|
2016-07-06 14:12:28 +08:00
|
|
|
set -l exit_status $status
|
2014-10-03 03:31:46 +08:00
|
|
|
set -l res ok
|
2018-09-04 05:13:31 +08:00
|
|
|
set test_duration (math (date +%s) - $starttime)
|
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
|
|
|
|
|
2016-07-06 14:12:28 +08:00
|
|
|
if test $out_status -eq 0 -a $err_status -eq 0 -a $exit_status -eq 0
|
2018-09-04 05:13:31 +08:00
|
|
|
say green "ok ($test_duration sec)"
|
2014-10-03 03:31:46 +08:00
|
|
|
# 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:"
|
2019-03-29 07:23:32 +08:00
|
|
|
colordiff -u $base.out $base.tmp.out
|
2014-10-03 03:31:46 +08:00
|
|
|
end
|
|
|
|
if test $err_status -ne 0
|
|
|
|
say yellow "Error output differs for file $file. Diff follows:"
|
2019-03-29 07:23:32 +08:00
|
|
|
colordiff -u $base.err $base.tmp.err
|
2014-10-03 03:31:46 +08:00
|
|
|
end
|
2016-07-06 14:12:28 +08:00
|
|
|
if test $exit_status -ne 0
|
2014-10-03 03:31:46 +08:00
|
|
|
say yellow "Exit status differs for file $file."
|
2016-07-06 14:12:28 +08:00
|
|
|
echo "Unexpected test exit status $exit_status."
|
2014-10-03 03:31:46 +08:00
|
|
|
end
|
|
|
|
return 1
|
2014-09-05 13:26:10 +08:00
|
|
|
end
|
2010-10-03 11:46:26 +08:00
|
|
|
end
|
|
|
|
|
2019-06-26 02:57:37 +08:00
|
|
|
set -g python (__fish_anypython)
|
|
|
|
|
2019-06-10 02:13:31 +08:00
|
|
|
function test_littlecheck_file
|
|
|
|
set -l file $argv[1]
|
2019-06-26 02:57:37 +08:00
|
|
|
echo -n "Testing file $file ... "
|
|
|
|
set starttime (date +%s)
|
2019-06-26 01:25:36 +08:00
|
|
|
$python ../littlecheck.py -s fish=../test/root/bin/fish $file
|
2019-06-26 02:57:37 +08:00
|
|
|
set -l exit_status $status
|
|
|
|
set -l res ok
|
|
|
|
set test_duration (math (date +%s) - $starttime)
|
|
|
|
if test $exit_status -eq 0
|
|
|
|
say green "ok ($test_duration sec)"
|
|
|
|
end
|
2019-07-03 04:50:16 +08:00
|
|
|
return $exit_status
|
2019-06-10 02:13:31 +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
|
2019-06-10 02:13:31 +08:00
|
|
|
if string match --quiet '*.fish' $i
|
|
|
|
if not test_littlecheck_file $i
|
|
|
|
# littlecheck test
|
|
|
|
set failed $failed $i
|
|
|
|
end
|
|
|
|
else
|
|
|
|
# .in test
|
|
|
|
if not test_in_file $i
|
|
|
|
set failed $failed $i
|
|
|
|
end
|
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
|