From 30d0315b6070f951fe1c54cbae4dba120ab47be2 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 30 Aug 2020 14:17:02 -0700 Subject: [PATCH] Add a test that fish_exit handlers run on receipt of SIGHUP --- tests/pexpects/exit_handlers.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 tests/pexpects/exit_handlers.py diff --git a/tests/pexpects/exit_handlers.py b/tests/pexpects/exit_handlers.py new file mode 100644 index 000000000..ffe7a9eed --- /dev/null +++ b/tests/pexpects/exit_handlers.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python3 +from pexpect_helper import SpawnedProc +import os +import signal +import tempfile +from time import sleep + +# Ensure that on-exit handlers run even if we get SIGHUP. +with tempfile.NamedTemporaryFile(mode="r", encoding="utf8") as tf: + sp = SpawnedProc() + fish_pid = sp.spawn.pid + sp.expect_prompt() + sp.sendline( + "function myexit --on-event fish_exit; /bin/echo $fish_pid > {filename}; end".format( + filename=tf.name + ) + ) + sp.expect_prompt() + os.kill(fish_pid, signal.SIGHUP) + # Note that fish's SIGHUP handling in interactive mode races with the call to select. + # So actually close its stdin, like a terminal emulator would do. + sp.spawn.close(force=False) + sp.spawn.wait() + tf.seek(0) + line = tf.readline().strip() + if line != str(fish_pid): + colors = sp.colors() + print( + """{RED}Failed to find pid written by exit handler{RESET}""".format( + **colors + ) + ) + print("""Expected '{}', found '{}'""".format(fish_pid, line))