mirror of
https://github.com/fish-shell/fish-shell
synced 2024-11-14 08:58:01 +00:00
8b67a1b26f
I noticed while fixing issue #2702 that the fish program being tested was sourcing config.fish files outside of the current build. This also happens when Travis CI runs the tests but isn't an issue there because of how Travis is configured to execute the tests. I also noticed that running `make test` was polluting my personal fish history; which will become a bigger problem if and when the fishd universal var file is moved from $XDG_CONFIG_HOME to $XDG_DATA_HOME. This change makes it possible for an individual to run the tests on their local machine secure in the knowledge that only the config.fish and related files from their git repository will be used and doing so won't pollute their personal fish history. Resolves #469
75 lines
2 KiB
Fish
75 lines
2 KiB
Fish
# Fishscript tests
|
|
#
|
|
# 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.
|
|
|
|
# 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
|
|
set files_to_test *.in
|
|
end
|
|
|
|
source test_util.fish (status -f) $argv; or exit
|
|
|
|
say -o cyan "Testing high level script functionality"
|
|
|
|
function test_file
|
|
set -l file $argv[1]
|
|
set -l base (basename $file .in)
|
|
|
|
echo -n "Testing file $file ... "
|
|
|
|
../test/root/bin/fish <$file >$base.tmp.out ^$base.tmp.err
|
|
set -l tmp_status $status
|
|
set -l res ok
|
|
|
|
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
|
|
else
|
|
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
|
|
end
|
|
end
|
|
|
|
set -l failed
|
|
for i in $files_to_test
|
|
if not test_file $i
|
|
set failed $failed $i
|
|
end
|
|
end
|
|
|
|
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
|
|
end
|