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
|
|
|
|
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
|
2020-06-15 01:11:57 +08:00
|
|
|
cd (status dirname)
|
2015-12-24 07:24:45 +08:00
|
|
|
|
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
|
|
|
|
|
2020-06-14 01:28:42 +08:00
|
|
|
# Test files specified on commandline, or all pexpect files.
|
2015-12-24 07:24:45 +08:00
|
|
|
if set -q argv[1]
|
2020-03-03 07:20:29 +08:00
|
|
|
set pexpect_files_to_test pexpects/$argv.py
|
2021-01-07 23:51:20 +08:00
|
|
|
else if set -q FISH_PEXPECT_FILES
|
|
|
|
set pexpect_files_to_test (string replace -r '^.*/(?=pexpects/)' '' -- $FISH_PEXPECT_FILES)
|
2015-12-24 07:24:45 +08:00
|
|
|
else
|
2020-03-03 07:20:29 +08:00
|
|
|
set pexpect_files_to_test pexpects/*.py
|
2015-12-24 07:24:45 +08:00
|
|
|
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"
|
2020-03-03 07:20:29 +08:00
|
|
|
function test_pexpect_file
|
|
|
|
set -l file $argv[1]
|
|
|
|
echo -n "Testing file $file ... "
|
|
|
|
|
|
|
|
begin
|
|
|
|
set starttime (timestamp)
|
|
|
|
set -lx TERM dumb
|
|
|
|
|
|
|
|
# Help the script find the pexpect_helper module in our parent directory.
|
|
|
|
set -lx --prepend PYTHONPATH (realpath $PWD/..)
|
|
|
|
set -lx fish ../test/root/bin/fish
|
|
|
|
set -lx fish_key_reader ../test/root/bin/fish_key_reader
|
|
|
|
set -lx fish_test_helper ../test/root/bin/fish_test_helper
|
|
|
|
|
|
|
|
# Note we require Python3.
|
|
|
|
python3 $file
|
|
|
|
end
|
|
|
|
|
|
|
|
set -l exit_status $status
|
|
|
|
if test "$exit_status" -eq 0
|
|
|
|
set test_duration (delta $starttime)
|
|
|
|
say green "ok ($test_duration $unit)"
|
|
|
|
end
|
|
|
|
return $exit_status
|
|
|
|
end
|
|
|
|
|
2016-04-12 07:47:46 +08:00
|
|
|
set failed
|
2020-03-03 07:20:29 +08:00
|
|
|
|
|
|
|
if not python3 -c 'import pexpect'
|
|
|
|
say red "pexpect tests disabled: `python3 -c 'import pexpect'` failed"
|
|
|
|
set pexpect_files_to_test
|
|
|
|
end
|
|
|
|
for i in $pexpect_files_to_test
|
|
|
|
if not test_pexpect_file $i
|
2020-11-10 02:26:27 +08:00
|
|
|
say yellow "Trying $i for a second time"
|
|
|
|
if not test_pexpect_file $i
|
|
|
|
set failed $failed $i
|
|
|
|
end
|
2020-03-03 07:20:29 +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
|
2020-03-29 01:41:44 +08:00
|
|
|
say green "All interactive tests completed successfully"
|
2014-09-24 07:29:36 +08:00
|
|
|
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
|