fork/fish-shell

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

Łukasz WieczorekReformat with black.82750bbae

master
2.4 KiB106 linesraw
1#!/usr/bin/env python3
2from pexpect_helper import SpawnedProc
3import platform
4import subprocess
5import os
6
7sp = SpawnedProc()
8send, sendline, sleep, expect_prompt, expect_re, expect_str = (
9    sp.send,
10    sp.sendline,
11    sp.sleep,
12    sp.expect_prompt,
13    sp.expect_re,
14    sp.expect_str,
15)
16expect_prompt()
17
18# Hack: NetBSD's sleep likes quitting when waking up
19# (but also does so under /bin/sh)
20testproc = "sleep 500" if platform.system() != "NetBSD" else "cat"
21sendline(testproc)
22sendline("set -l foo 'bar'1; echo $foo")  # ignored because sleep is in fg
23sleep(1.2)
24
25# ctrl-z - send job to background
26send("\x1a")
27sleep(1.2)
28expect_prompt()
29sendline("set -l foo 'bar'2; echo $foo")
30expect_prompt("bar2")
31
32sendline("fg; set -l foo 'bar'3; echo $foo")
33expect_str("Send job 1 (" + testproc + ") to foreground")
34sleep(0.2)
35# Beware: Mac pkill requires that the -P argument come before the process name,
36# else the -P argument is ignored.
37subprocess.call(["pkill", "-INT", "-P", str(sp.spawn.pid), "sleep"])
38sleep(0.2)
39# Now fish reads the buffered input, since sleep never did!
40# Note fish doesn't report if a proc is killed via SIGINT.
41expect_prompt("bar3")
42
43sendline("set -l foo 'bar'4; echo $foo")
44expect_prompt("bar4")
45
46# Regression test for #7483.
47# Ensure we can background a job after a different backgrounded job completes.
48sendline("sleep 1")
49sleep(0.1)
50
51# ctrl-z - send job to background
52send("\x1a")
53sleep(0.2)
54expect_prompt("has stopped")
55
56# Bring back to fg.
57sendline("fg")
58sleep(1.0)
59
60# Now sleep is done, right?
61expect_prompt()
62sendline("jobs")
63expect_prompt("jobs: There are no jobs")
64
65# Ensure we can do it again.
66sendline("sleep 5")
67sleep(0.2)
68send("\x1a")
69sleep(0.1)
70expect_prompt("has stopped")
71sendline("fg")
72sleep(0.1)  # allow tty to transfer
73send("\x03")  # control-c to cancel it
74
75expect_prompt()
76sendline("jobs")
77expect_prompt("jobs: There are no jobs")
78
79if not os.environ.get("fish_test_helper", ""):
80    import sys
81
82    sys.exit(127)
83
84# Regression test for #2214: foregrounding from a key binding works!
85sendline(r"bind ctrl-r 'fg >/dev/null 2>/dev/null'")
86expect_prompt()
87sendline("$fish_test_helper print_stop_cont")
88sleep(0.2)
89
90send("\x1a")  # ctrl-z
91expect_prompt("SIGTSTP")
92sleep(0.1)
93send("\x12")  # ctrl-r, placing fth in foreground
94expect_str("SIGCONT")
95
96# Do it again.
97send("\x1a")
98expect_str("SIGTSTP")
99sleep(0.1)
100send("\x12")
101expect_str("SIGCONT")
102
103# End fth by sending it anything.
104send("\x12")
105sendline("derp")
106expect_prompt()