2022-01-31 05:15:50 +08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import os
|
2024-03-30 23:10:12 +08:00
|
|
|
import platform
|
2022-01-31 05:15:50 +08:00
|
|
|
import signal
|
2024-03-30 23:10:12 +08:00
|
|
|
import sys
|
2022-01-31 05:15:50 +08:00
|
|
|
from pexpect_helper import SpawnedProc
|
|
|
|
|
|
|
|
|
|
|
|
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 23:10:12 +08:00
|
|
|
|
|
|
|
if platform.system() == "FreeBSD": # Spurious failure.
|
|
|
|
sys.exit(127)
|
|
|
|
|
2022-01-31 05:15:50 +08: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-17 06:02:15 +08:00
|
|
|
sendline(r"set -g wacky_count 0")
|
|
|
|
expect_prompt()
|
2022-01-31 05:15:50 +08: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-17 06:02:15 +08: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-31 05:15:50 +08:00
|
|
|
expect_prompt()
|
|
|
|
|
2024-03-30 23:10:12 +08:00
|
|
|
sendline(r"bind a,b,c,\e,d,e,f wacky_handler")
|
2022-01-31 05:15:50 +08:00
|
|
|
expect_prompt()
|
|
|
|
|
|
|
|
# We can respond to SIGUSR1.
|
2024-03-30 23:10:12 +08:00
|
|
|
sleep(1)
|
2022-01-31 05:15:50 +08: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-17 06:02:15 +08:00
|
|
|
expect_str(r"Wacky Handler 1")
|
2022-01-31 05:15:50 +08: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-17 06:02:15 +08:00
|
|
|
expect_str(r"Wacky Handler 2")
|
2022-01-31 05:15:50 +08:00
|
|
|
sendline(r"")
|
|
|
|
expect_prompt()
|
|
|
|
|
|
|
|
# As before but it comes after the ESC.
|
2022-09-17 06:05:38 +08:00
|
|
|
# The signal will arrive while we are waiting in readch_timed().
|
2022-01-31 05:15:50 +08: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-17 06:02:15 +08:00
|
|
|
expect_str(r"Wacky Handler 3")
|
2022-01-31 05:15:50 +08:00
|
|
|
sendline(r"")
|
|
|
|
expect_prompt()
|