fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

Daniel Rainerstyle: replace black with ruff for Python formatting5ade4a037

master
2.1 KiB97 linesraw
1#!/usr/bin/env python3
2import os
3import platform
4import signal
5import sys
6from pexpect_helper import SpawnedProc
7
8if "CI" in os.environ and platform.system() in ["Darwin", "FreeBSD"]:
9    sys.exit(127)
10
11sp = SpawnedProc()
12send, sendline, sleep, expect_prompt, expect_str, expect_re = (
13    sp.send,
14    sp.sendline,
15    sp.sleep,
16    sp.expect_prompt,
17    sp.expect_str,
18    sp.expect_re,
19)
20
21# Ensure that signals don't tear escape sequences. See #8628.
22expect_prompt()
23
24# Allow for long delays before matching escape.
25sendline(r"set -g fish_escape_delay_ms 2000")
26expect_prompt()
27
28# Set up a handler for SIGUSR1.
29sendline(r"set -g sigusr1_count 0")
30expect_prompt()
31sendline(r"set -g wacky_count 0")
32expect_prompt()
33
34sendline(
35    r"""
36    function usr1_handler --on-signal SIGUSR1;
37        set sigusr1_count (math $sigusr1_count + 1);
38        echo Got SIGUSR1 $sigusr1_count;
39        commandline -f repaint;
40    end
41""".strip().replace("\n", os.linesep)
42)
43expect_prompt()
44
45# Set up a wacky binding with an escape.
46sendline(
47    r"""
48    function wacky_handler
49        set wacky_count (math $wacky_count + 1);
50        echo Wacky Handler $wacky_count
51    end
52""".strip().replace("\n", os.linesep)
53)
54expect_prompt()
55
56sendline(r"bind a,b,c,\e,d,e,f wacky_handler")
57expect_prompt()
58
59sendline("echo 'Catch' 'up'")
60expect_prompt("Catch up")
61
62# We can respond to SIGUSR1.
63sleep(1)
64os.kill(sp.spawn.pid, signal.SIGUSR1)
65expect_str(r"Got SIGUSR1 1")
66sendline(r"")
67expect_prompt()
68
69# Our wacky binding works.
70send("abc\x1bdef")
71expect_str(r"Wacky Handler 1")
72sendline(r"")
73expect_prompt()
74
75# Now we interleave the sequence with SIGUSR1.
76# What we expect to happen is that the signal is "shuffled to the front" ahead of the key events.
77send("abc")
78sleep(0.05)
79os.kill(sp.spawn.pid, signal.SIGUSR1)
80sleep(0.05)
81send("\x1bdef")
82expect_str(r"Got SIGUSR1 2")
83expect_str(r"Wacky Handler 2")
84sendline(r"")
85expect_prompt()
86
87# As before but it comes after the ESC.
88# The signal will arrive while we are waiting in readch_timed().
89send("abc\x1b")
90sleep(0.05)
91os.kill(sp.spawn.pid, signal.SIGUSR1)
92sleep(0.05)
93send("def")
94expect_str(r"Got SIGUSR1 3")
95expect_str(r"Wacky Handler 3")
96sendline(r"")
97expect_prompt()