2021-03-18 18:23:31 +00:00
|
|
|
#! /bin/echo "interactive.fish must be run via the test driver!"
|
2016-02-07 02:08:22 +00:00
|
|
|
#
|
2021-03-18 18:23:31 +00:00
|
|
|
# Interactive tests using `pexpect`
|
2014-09-08 02:11:34 +00:00
|
|
|
|
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
|
2020-06-14 17:11:57 +00:00
|
|
|
cd (status dirname)
|
2015-12-23 23:24:45 +00:00
|
|
|
|
2020-06-13 17:28:42 +00:00
|
|
|
# Test files specified on commandline, or all pexpect files.
|
2021-03-18 18:23:31 +00:00
|
|
|
if set -q argv[1] && test -n "$argv[1]"
|
|
|
|
set pexpect_files_to_test pexpects/$argv
|
2021-01-07 15:51:20 +00:00
|
|
|
else if set -q FISH_PEXPECT_FILES
|
|
|
|
set pexpect_files_to_test (string replace -r '^.*/(?=pexpects/)' '' -- $FISH_PEXPECT_FILES)
|
2015-12-23 23:24:45 +00:00
|
|
|
else
|
2021-03-18 18:23:31 +00:00
|
|
|
say -o cyan "Testing interactive functionality"
|
2020-03-02 23:20:29 +00:00
|
|
|
set pexpect_files_to_test pexpects/*.py
|
2015-12-23 23:24:45 +00:00
|
|
|
end
|
|
|
|
|
2021-03-18 18:23:31 +00:00
|
|
|
source test_util.fish || exit
|
2018-04-01 20:43:05 +00:00
|
|
|
cat interactive.config >>$XDG_CONFIG_HOME/fish/config.fish
|
2014-09-23 23:29:36 +00:00
|
|
|
|
2020-03-02 23:20:29 +00:00
|
|
|
function test_pexpect_file
|
|
|
|
set -l file $argv[1]
|
2021-03-18 18:23:31 +00:00
|
|
|
echo -n "Testing file $file:"
|
2020-03-02 23:20:29 +00:00
|
|
|
|
|
|
|
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)"
|
2021-05-23 13:25:12 +00:00
|
|
|
else if test "$exit_status" -eq 127
|
|
|
|
say blue "SKIPPED"
|
|
|
|
set exit_status 0
|
2020-03-02 23:20:29 +00:00
|
|
|
end
|
|
|
|
return $exit_status
|
|
|
|
end
|
|
|
|
|
2016-04-11 23:47:46 +00:00
|
|
|
set failed
|
2020-03-02 23:20:29 +00:00
|
|
|
|
2022-06-08 13:13:06 +00:00
|
|
|
# The test here looks wrong, but False sets exit status to 0, which is what we want
|
|
|
|
if python3 -c 'import sys; exit(sys.version_info > (3, 5))'
|
|
|
|
say red "pexpect tests disabled: python3 is too old"
|
|
|
|
set pexpect_files_to_test
|
|
|
|
end
|
2020-03-02 23:20:29 +00: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
|
2022-10-25 18:32:34 +00:00
|
|
|
# Retry pexpect tests under CI twice, as they are timing-sensitive and CI resource
|
|
|
|
# contention can cause tests to spuriously fail.
|
|
|
|
if set -qx CI
|
|
|
|
say yellow "Trying $i for a second time"
|
|
|
|
if not test_pexpect_file $i
|
|
|
|
set failed $failed $i
|
|
|
|
end
|
|
|
|
else
|
2020-11-09 18:26:27 +00:00
|
|
|
set failed $failed $i
|
|
|
|
end
|
2020-03-02 23:20:29 +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
|
2021-03-18 18:23:31 +00:00
|
|
|
if test (count $pexpect_files_to_test) -gt 1
|
|
|
|
say green "All interactive tests completed successfully"
|
|
|
|
else
|
|
|
|
say green "$pexpect_files_to_test completed successfully"
|
|
|
|
end
|
2014-09-23 23:29:36 +00:00
|
|
|
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
|