2014-09-08 10:11:34 +08:00
|
|
|
# Interactive tests using `expect`
|
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.
|
2014-09-08 10:11:34 +08:00
|
|
|
|
2018-02-07 01:36:47 +08:00
|
|
|
if test "$TRAVIS_OS_NAME" = osx
|
|
|
|
echo "Skipping interactive tests on macOS on Travis"
|
|
|
|
exit 0
|
|
|
|
end
|
|
|
|
|
2016-04-12 07:47:46 +08:00
|
|
|
# This is a list of flakey tests that often succeed when rerun.
|
2018-12-17 00:46:21 +08:00
|
|
|
set -l TESTS_TO_RETRY bind.expect
|
2016-04-12 07:47:46 +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.
|
2018-12-17 00:46:21 +08:00
|
|
|
set -gx FISH_UNIT_TESTS_RUNNING 1
|
2017-01-29 12:37:32 +08:00
|
|
|
|
2015-12-24 07:24:45 +08:00
|
|
|
# Change to directory containing this script
|
|
|
|
cd (dirname (status -f))
|
|
|
|
|
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/test.fish.
|
2018-12-17 00:46:21 +08:00
|
|
|
set -gx TERM xterm
|
2016-09-20 13:08:33 +08:00
|
|
|
set -e ITERM_PROFILE
|
|
|
|
|
2015-12-24 07:24:45 +08:00
|
|
|
# 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
|
|
|
|
|
2018-04-02 04:43:05 +08:00
|
|
|
source test_util.fish (status -f) $argv
|
|
|
|
or exit
|
|
|
|
cat interactive.config >>$XDG_CONFIG_HOME/fish/config.fish
|
2014-09-24 07:29:36 +08:00
|
|
|
|
|
|
|
say -o cyan "Testing interactive functionality"
|
|
|
|
if not type -q expect
|
|
|
|
say red "Tests disabled: `expect` not found"
|
2017-02-01 10:44:02 +08:00
|
|
|
exit 1
|
2014-09-08 10:11:34 +08:00
|
|
|
end
|
|
|
|
|
2014-09-24 07:29:36 +08:00
|
|
|
function test_file
|
|
|
|
set -l file $argv[1]
|
|
|
|
echo -n "Testing file $file ... "
|
2018-09-04 05:13:31 +08:00
|
|
|
set starttime (date +%s)
|
2014-09-08 10:11:34 +08:00
|
|
|
begin
|
|
|
|
set -lx TERM dumb
|
2018-04-02 04:43:05 +08:00
|
|
|
expect -n -c 'source interactive.expect.rc' -f $file >$file.tmp.out 2>$file.tmp.err
|
2014-09-08 10:11:34 +08:00
|
|
|
end
|
2016-07-06 14:12:28 +08:00
|
|
|
set -l exit_status $status
|
2014-09-24 07:29:36 +08:00
|
|
|
set -l res ok
|
2018-09-04 05:13:31 +08:00
|
|
|
set test_duration (math (date +%s) - $starttime)
|
2014-09-24 07:29:36 +08:00
|
|
|
mv -f interactive.tmp.log $file.tmp.log
|
2014-09-08 10:11:34 +08:00
|
|
|
|
2014-09-24 07:29:36 +08:00
|
|
|
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
|
2014-09-08 10:11:34 +08:00
|
|
|
|
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-09-19 06:45:07 +08:00
|
|
|
# clean up tmp files
|
2014-09-24 07:29:36 +08:00
|
|
|
rm -f $file.tmp.{err,out,log}
|
|
|
|
return 0
|
2014-09-08 10:11:34 +08:00
|
|
|
else
|
2014-09-24 07:29:36 +08:00
|
|
|
say red "fail"
|
|
|
|
if test $out_status -ne 0
|
|
|
|
say yellow "Output differs for file $file. Diff follows:"
|
|
|
|
colordiff -u $file.tmp.out $file.out
|
|
|
|
end
|
|
|
|
if test $err_status -ne 0
|
|
|
|
say yellow "Error output differs for file $file. Diff follows:"
|
|
|
|
colordiff -u $file.tmp.err $file.err
|
|
|
|
end
|
2016-07-06 14:12:28 +08:00
|
|
|
if test $exit_status -ne 0
|
2014-09-24 07:29:36 +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-09-24 07:29:36 +08:00
|
|
|
end
|
|
|
|
if set -q SHOW_INTERACTIVE_LOG
|
2014-09-20 05:50:34 +08:00
|
|
|
# dump the interactive log
|
|
|
|
# primarily for use in travis where we can't check it manually
|
2014-09-24 07:29:36 +08:00
|
|
|
say yellow "Log for file $file:"
|
|
|
|
cat $file.tmp.log
|
2014-09-20 05:50:34 +08:00
|
|
|
end
|
2014-09-24 07:29:36 +08:00
|
|
|
return 1
|
2014-09-08 10:11:34 +08:00
|
|
|
end
|
|
|
|
end
|
2014-09-24 07:29:36 +08:00
|
|
|
|
2016-04-12 07:47:46 +08:00
|
|
|
set failed
|
2015-12-24 07:24:45 +08:00
|
|
|
for i in $files_to_test
|
2014-09-24 07:29:36 +08:00
|
|
|
if not test_file $i
|
2016-04-12 07:47:46 +08:00
|
|
|
# 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
|
2014-09-24 07:29:36 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-10-03 03:31:46 +08:00
|
|
|
set failed (count $failed)
|
2014-09-24 07:29:36 +08:00
|
|
|
if test $failed -eq 0
|
|
|
|
say green "All tests completed successfully"
|
|
|
|
exit 0
|
|
|
|
else
|
2014-09-24 13:50:28 +08:00
|
|
|
set plural (test $failed -eq 1; or echo s)
|
|
|
|
say red "$failed test$plural failed"
|
2014-09-24 07:29:36 +08:00
|
|
|
exit 1
|
|
|
|
end
|