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
|
|
|
|
2016-07-01 04:21:10 +00:00
|
|
|
# This is a list of flakey tests that often succeed when rerun.
|
|
|
|
set TESTS_TO_RETRY bind.expect
|
|
|
|
|
2015-12-23 23:24:45 +00:00
|
|
|
# Change to directory containing this script
|
|
|
|
cd (dirname (status -f))
|
|
|
|
|
|
|
|
# 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
|
2016-02-07 02:08:22 +00:00
|
|
|
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"
|
|
|
|
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 ... "
|
2014-09-08 02:11:34 +00:00
|
|
|
begin
|
|
|
|
set -lx TERM dumb
|
2014-09-23 23:29:36 +00:00
|
|
|
expect -n -c 'source interactive.expect.rc' -f $file >$file.tmp.out ^$file.tmp.err
|
2014-09-08 02:11:34 +00:00
|
|
|
end
|
|
|
|
set -l tmp_status $status
|
2014-09-23 23:29:36 +00:00
|
|
|
set -l res ok
|
|
|
|
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
|
|
|
|
set -l exp_status (cat $file.status)[1]
|
2014-09-08 02:11:34 +00:00
|
|
|
|
2014-09-23 23:29:36 +00:00
|
|
|
if test $out_status -eq 0 -a $err_status -eq 0 -a $exp_status -eq $tmp_status
|
|
|
|
say green "ok"
|
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:"
|
|
|
|
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
|
|
|
|
if test $exp_status -ne $tmp_status
|
|
|
|
say yellow "Exit status differs for file $file."
|
|
|
|
echo "Expected $exp_status, got $tmp_status."
|
|
|
|
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-07-01 04:21:10 +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
|
2016-07-01 04:21:10 +00: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-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
|