From 4e3dc51bc4feaa14c7c9213fb95c4c2b01526350 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Mon, 11 Nov 2024 16:44:15 -0600 Subject: [PATCH] Prevent test suite from hanging on panic --- src/panic.rs | 6 +++++- tests/test_driver.sh | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/panic.rs b/src/panic.rs index 04e7db38d..12a91d42e 100644 --- a/src/panic.rs +++ b/src/panic.rs @@ -16,7 +16,11 @@ use crate::{ pub static AT_EXIT: OnceCell> = OnceCell::new(); pub fn panic_handler(main: impl FnOnce() -> i32 + UnwindSafe) -> ! { - if isatty(STDIN_FILENO) { + // The isatty() check will stop us from hanging in most fish tests, but not those + // running in a simulated terminal emulator environment (such as the tmux or pexpect + // tests). The FISH_FAST_FAIL environment variable is set in the test driver to + // prevent the test suite from hanging on panic. + if isatty(STDIN_FILENO) && std::env::var_os("FISH_FAST_FAIL").is_none() { let standard_hook = take_hook(); set_hook(Box::new(move |panic_info| { standard_hook(panic_info); diff --git a/tests/test_driver.sh b/tests/test_driver.sh index 5676c87fb..c439a5b24 100644 --- a/tests/test_driver.sh +++ b/tests/test_driver.sh @@ -61,6 +61,10 @@ export suppress_color # Source test util functions at startup fish_init_cmd="${fish_init_cmd} && source ${TESTS_ROOT}/test_util.fish"; +# Indicate that the fish panic handler shouldn't wait for input to prevent tests from hanging +FISH_FAST_FAIL=1 +export FISH_FAST_FAIL + # Run the test script, but don't exec so we can clean up after it succeeds/fails. Each test is # launched directly within its TMPDIR, so that the fish tests themselves do not need to refer to # TMPDIR (to ensure their output as displayed in case of failure by littlecheck is reproducible).