2022-01-30 21:15:50 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import os
|
2024-03-30 15:10:12 +00:00
|
|
|
import platform
|
2022-01-30 21:15:50 +00:00
|
|
|
import signal
|
2024-03-30 15:10:12 +00:00
|
|
|
import sys
|
2022-01-30 21:15:50 +00:00
|
|
|
from pexpect_helper import SpawnedProc
|
|
|
|
|
2024-04-12 09:27:10 +00:00
|
|
|
if platform.system() == "FreeBSD": # Spurious failure. TODO Only disable this in CI.
|
|
|
|
sys.exit(127)
|
|
|
|
|
|
|
|
if "CI" in os.environ and platform.system() == "Darwin":
|
|
|
|
sys.exit(127)
|
2022-01-30 21:15:50 +00:00
|
|
|
|
|
|
|
sp = SpawnedProc()
|
|
|
|
send, sendline, sleep, expect_prompt, expect_str, expect_re = (
|
|
|
|
sp.send,
|
|
|
|
sp.sendline,
|
|
|
|
sp.sleep,
|
|
|
|
sp.expect_prompt,
|
|
|
|
sp.expect_str,
|
|
|
|
sp.expect_re,
|
|
|
|
)
|
2024-03-30 15:10:12 +00:00
|
|
|
|
2022-01-30 21:15:50 +00:00
|
|
|
# Ensure that signals don't tear escape sequences. See #8628.
|
|
|
|
expect_prompt()
|
|
|
|
|
|
|
|
# Allow for long delays before matching escape.
|
|
|
|
sendline(r"set -g fish_escape_delay_ms 2000")
|
|
|
|
expect_prompt()
|
|
|
|
|
|
|
|
# Set up a handler for SIGUSR1.
|
|
|
|
sendline(r"set -g sigusr1_count 0")
|
|
|
|
expect_prompt()
|
2022-09-16 22:02:15 +00:00
|
|
|
sendline(r"set -g wacky_count 0")
|
|
|
|
expect_prompt()
|
2022-01-30 21:15:50 +00:00
|
|
|
|
|
|
|
sendline(
|
|
|
|
r"""
|
|
|
|
function usr1_handler --on-signal SIGUSR1;
|
|
|
|
set sigusr1_count (math $sigusr1_count + 1);
|
|
|
|
echo Got SIGUSR1 $sigusr1_count;
|
|
|
|
commandline -f repaint;
|
|
|
|
end
|
|
|
|
""".strip().replace(
|
|
|
|
"\n", os.linesep
|
|
|
|
)
|
|
|
|
)
|
|
|
|
expect_prompt()
|
|
|
|
|
|
|
|
# Set up a wacky binding with an escape.
|
2022-09-16 22:02:15 +00:00
|
|
|
sendline(
|
|
|
|
r"""
|
|
|
|
function wacky_handler
|
|
|
|
set wacky_count (math $wacky_count + 1);
|
|
|
|
echo Wacky Handler $wacky_count
|
|
|
|
end
|
|
|
|
""".strip().replace(
|
|
|
|
"\n", os.linesep
|
|
|
|
)
|
|
|
|
)
|
2022-01-30 21:15:50 +00:00
|
|
|
expect_prompt()
|
|
|
|
|
2024-03-30 15:10:12 +00:00
|
|
|
sendline(r"bind a,b,c,\e,d,e,f wacky_handler")
|
2022-01-30 21:15:50 +00:00
|
|
|
expect_prompt()
|
|
|
|
|
2024-05-06 00:15:21 +00:00
|
|
|
sendline("echo 'Catch' 'up'")
|
|
|
|
expect_prompt("Catch up")
|
|
|
|
|
2022-01-30 21:15:50 +00:00
|
|
|
# We can respond to SIGUSR1.
|
2024-03-30 15:10:12 +00:00
|
|
|
sleep(1)
|
2022-01-30 21:15:50 +00:00
|
|
|
os.kill(sp.spawn.pid, signal.SIGUSR1)
|
|
|
|
expect_str(r"Got SIGUSR1 1")
|
|
|
|
sendline(r"")
|
|
|
|
expect_prompt()
|
|
|
|
|
|
|
|
# Our wacky binding works.
|
|
|
|
send("abc\x1bdef")
|
2022-09-16 22:02:15 +00:00
|
|
|
expect_str(r"Wacky Handler 1")
|
2022-01-30 21:15:50 +00:00
|
|
|
sendline(r"")
|
|
|
|
expect_prompt()
|
|
|
|
|
|
|
|
# Now we interleave the sequence with SIGUSR1.
|
|
|
|
# What we expect to happen is that the signal is "shuffled to the front" ahead of the key events.
|
|
|
|
send("abc")
|
|
|
|
sleep(0.05)
|
|
|
|
os.kill(sp.spawn.pid, signal.SIGUSR1)
|
|
|
|
sleep(0.05)
|
|
|
|
send("\x1bdef")
|
|
|
|
expect_str(r"Got SIGUSR1 2")
|
2022-09-16 22:02:15 +00:00
|
|
|
expect_str(r"Wacky Handler 2")
|
2022-01-30 21:15:50 +00:00
|
|
|
sendline(r"")
|
|
|
|
expect_prompt()
|
|
|
|
|
|
|
|
# As before but it comes after the ESC.
|
2022-09-16 22:05:38 +00:00
|
|
|
# The signal will arrive while we are waiting in readch_timed().
|
2022-01-30 21:15:50 +00:00
|
|
|
send("abc\x1b")
|
|
|
|
sleep(0.05)
|
|
|
|
os.kill(sp.spawn.pid, signal.SIGUSR1)
|
|
|
|
sleep(0.05)
|
|
|
|
send("def")
|
|
|
|
expect_str(r"Got SIGUSR1 3")
|
2022-09-16 22:02:15 +00:00
|
|
|
expect_str(r"Wacky Handler 3")
|
2022-01-30 21:15:50 +00:00
|
|
|
sendline(r"")
|
|
|
|
expect_prompt()
|