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