mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-12-18 20:53:40 +08:00
0c5015d467
This has been driving nuts for years. The output of the diff emitted when a test fails was always reversed, because the diff tool is called with `${difftool} ${new} ${old}` so all the `-` and `+` contexts are reversed, and the highlights are all screwed up. The output of a `make test` run should show what has changed from the baseline/expected, not how the expected differs from the actual. When considered from both the perspective of intentional changes to the test outputs and failed test outputs, it is desirable to see how the test output has changed from the previously expected, and not the other way around. (If you were used to the previous behavior, I apologize. But it was wrong.)
117 lines
3.4 KiB
Fish
117 lines
3.4 KiB
Fish
# Interactive tests using `expect`
|
|
#
|
|
# 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.
|
|
|
|
if test "$TRAVIS_OS_NAME" = osx
|
|
echo "Skipping interactive tests on macOS on Travis"
|
|
exit 0
|
|
end
|
|
|
|
# This is a list of flakey tests that often succeed when rerun.
|
|
set -l TESTS_TO_RETRY bind.expect
|
|
|
|
# Set this var to modify behavior of the code being tests. Such as avoiding running
|
|
# `fish_update_completions` when running tests.
|
|
set -gx FISH_UNIT_TESTS_RUNNING 1
|
|
|
|
# Change to directory containing this script
|
|
cd (dirname (status -f))
|
|
|
|
# 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/test.fish.
|
|
set -gx TERM xterm
|
|
set -e ITERM_PROFILE
|
|
|
|
# Test files specified on commandline, or all *.expect files
|
|
if set -q argv[1]
|
|
set files_to_test $argv.expect
|
|
else
|
|
set files_to_test *.expect
|
|
end
|
|
|
|
source test_util.fish (status -f) $argv
|
|
or exit
|
|
cat interactive.config >>$XDG_CONFIG_HOME/fish/config.fish
|
|
|
|
say -o cyan "Testing interactive functionality"
|
|
if not type -q expect
|
|
say red "Tests disabled: `expect` not found"
|
|
exit 0
|
|
end
|
|
|
|
function test_file
|
|
set -l file $argv[1]
|
|
echo -n "Testing file $file ... "
|
|
set starttime (date +%s)
|
|
begin
|
|
set -lx TERM dumb
|
|
expect -n -c 'source interactive.expect.rc' -f $file >$file.tmp.out 2>$file.tmp.err
|
|
end
|
|
set -l exit_status $status
|
|
set -l res ok
|
|
set test_duration (math (date +%s) - $starttime)
|
|
mv -f interactive.tmp.log $file.tmp.log
|
|
|
|
diff $file.tmp.out $file.out >/dev/null
|
|
set -l out_status $status
|
|
diff $file.tmp.err $file.err >/dev/null
|
|
set -l err_status $status
|
|
|
|
if test $out_status -eq 0 -a $err_status -eq 0 -a $exit_status -eq 0
|
|
say green "ok ($test_duration sec)"
|
|
# clean up tmp files
|
|
rm -f $file.tmp.{err,out,log}
|
|
return 0
|
|
else
|
|
say red "fail"
|
|
if test $out_status -ne 0
|
|
say yellow "Output differs for file $file. Diff follows:"
|
|
colordiff -u $file.out $file.tmp.out
|
|
end
|
|
if test $err_status -ne 0
|
|
say yellow "Error output differs for file $file. Diff follows:"
|
|
colordiff -u $file.err $file.tmp.err
|
|
end
|
|
if test $exit_status -ne 0
|
|
say yellow "Exit status differs for file $file."
|
|
echo "Unexpected test exit status $exit_status."
|
|
end
|
|
if set -q SHOW_INTERACTIVE_LOG
|
|
# dump the interactive log
|
|
# primarily for use in travis where we can't check it manually
|
|
say yellow "Log for file $file:"
|
|
cat $file.tmp.log
|
|
end
|
|
return 1
|
|
end
|
|
end
|
|
|
|
set failed
|
|
for i in $files_to_test
|
|
if not test_file $i
|
|
# Retry flakey tests once.
|
|
if contains $i $TESTS_TO_RETRY
|
|
say -o cyan "Rerunning test $i since it is known to be flakey"
|
|
rm -f $i.tmp.*
|
|
if not test_file $i
|
|
set failed $failed $i
|
|
end
|
|
else
|
|
set failed $failed $i
|
|
end
|
|
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
|