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