From 2962fbcf7ade8f14aa1b76ad4ca281b0a8d74058 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Thu, 18 Mar 2021 13:23:31 -0500 Subject: [PATCH] Add pexpect tests to new test driver --- cmake/Tests.cmake | 11 +++++++++++ tests/interactive.fish | 29 ++++++++++++----------------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/cmake/Tests.cmake b/cmake/Tests.cmake index 8e0c52461..a9cc6428f 100644 --- a/cmake/Tests.cmake +++ b/cmake/Tests.cmake @@ -135,3 +135,14 @@ foreach(CHECK ${FISH_CHECKS}) ) add_test_target("${CHECK_NAME}") endforeach(CHECK) + +FILE(GLOB PEXPECTS CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/tests/pexpects/*.py) +foreach(PEXPECT ${PEXPECTS}) + get_filename_component(PEXPECT ${PEXPECT} NAME) + add_test(NAME ${PEXPECT} + COMMAND sh ${CMAKE_CURRENT_BINARY_DIR}/tests/test_driver.sh + ${CMAKE_CURRENT_BINARY_DIR}/tests/interactive.fish ${PEXPECT} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests + ) + add_test_target("${PEXPECT}") +endforeach(PEXPECT) diff --git a/tests/interactive.fish b/tests/interactive.fish index 009cc0c6e..e90d812eb 100644 --- a/tests/interactive.fish +++ b/tests/interactive.fish @@ -1,8 +1,6 @@ -# Interactive tests using `expect` +#! /bin/echo "interactive.fish must be run via the test driver!" # -# 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. +# Interactive tests using `pexpect` # Set this var to modify behavior of the code being tests. Such as avoiding running # `fish_update_completions` when running tests. @@ -11,29 +9,22 @@ set -gx FISH_UNIT_TESTS_RUNNING 1 # Change to directory containing this script cd (status dirname) -# 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 -gx TERM xterm -set -e ITERM_PROFILE - # Test files specified on commandline, or all pexpect files. -if set -q argv[1] - set pexpect_files_to_test pexpects/$argv.py +if set -q argv[1] && test -n "$argv[1]" + set pexpect_files_to_test pexpects/$argv else if set -q FISH_PEXPECT_FILES set pexpect_files_to_test (string replace -r '^.*/(?=pexpects/)' '' -- $FISH_PEXPECT_FILES) else + say -o cyan "Testing interactive functionality" set pexpect_files_to_test pexpects/*.py end -source test_util.fish (status -f) $argv -or exit +source test_util.fish || exit cat interactive.config >>$XDG_CONFIG_HOME/fish/config.fish -say -o cyan "Testing interactive functionality" function test_pexpect_file set -l file $argv[1] - echo -n "Testing file $file ... " + echo -n "Testing file $file:" begin set starttime (timestamp) @@ -77,7 +68,11 @@ end set failed (count $failed) if test $failed -eq 0 - say green "All interactive tests completed successfully" + 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 exit 0 else set plural (test $failed -eq 1; or echo s)