2020-07-21 18:31:32 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
from pexpect_helper import SpawnedProc
|
2024-04-12 09:41:29 +00:00
|
|
|
import os
|
2021-02-24 18:52:51 +00:00
|
|
|
import platform
|
2020-07-21 18:31:32 +00:00
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
|
2024-04-12 09:27:10 +00:00
|
|
|
if "CI" in os.environ and platform.system() == "Darwin":
|
|
|
|
sys.exit(127)
|
|
|
|
|
2020-07-21 18:31:32 +00:00
|
|
|
sp = SpawnedProc()
|
|
|
|
send, sendline, sleep, expect_prompt, expect_re, expect_str = (
|
|
|
|
sp.send,
|
|
|
|
sp.sendline,
|
|
|
|
sp.sleep,
|
|
|
|
sp.expect_prompt,
|
|
|
|
sp.expect_re,
|
|
|
|
sp.expect_str,
|
|
|
|
)
|
|
|
|
expect_prompt()
|
|
|
|
|
2021-02-24 18:52:51 +00:00
|
|
|
# Hack: NetBSD's sleep likes quitting when waking up
|
|
|
|
# (but also does so under /bin/sh)
|
2022-06-16 16:43:28 +00:00
|
|
|
testproc = "sleep 500" if platform.system() != "NetBSD" else "cat"
|
2021-02-24 18:52:51 +00:00
|
|
|
sendline(testproc)
|
2020-07-21 18:31:32 +00:00
|
|
|
sendline("set -l foo bar; echo $foo")
|
2020-11-13 14:09:39 +00:00
|
|
|
expect_str("")
|
2024-03-30 15:10:12 +00:00
|
|
|
sleep(1.2)
|
2020-07-21 18:31:32 +00:00
|
|
|
|
2020-11-13 14:09:39 +00:00
|
|
|
# ctrl-z - send job to background
|
2020-07-21 18:31:32 +00:00
|
|
|
send("\x1A")
|
2024-03-30 15:10:12 +00:00
|
|
|
sleep(1.2)
|
2020-07-21 18:31:32 +00:00
|
|
|
expect_prompt()
|
|
|
|
sendline("set -l foo bar; echo $foo")
|
|
|
|
expect_str("bar")
|
|
|
|
|
|
|
|
expect_prompt()
|
|
|
|
sendline("fg")
|
2021-11-04 06:33:02 +00:00
|
|
|
expect_str("Send job 1 (" + testproc + ") to foreground")
|
2020-11-13 14:09:39 +00:00
|
|
|
sleep(0.2)
|
2020-07-21 18:31:32 +00:00
|
|
|
sendline("set -l foo bar; echo $foo")
|
2020-11-13 14:09:39 +00:00
|
|
|
expect_str("")
|
|
|
|
# ctrl-c - cancel
|
|
|
|
send("\x03")
|
2020-07-21 18:31:32 +00:00
|
|
|
|
|
|
|
expect_prompt()
|
|
|
|
sendline("set -l foo bar; echo $foo")
|
|
|
|
expect_str("bar")
|
2021-02-07 18:52:32 +00:00
|
|
|
|
|
|
|
expect_prompt()
|
|
|
|
|
|
|
|
# Regression test for #7483.
|
|
|
|
# Ensure we can background a job after a different backgrounded job completes.
|
|
|
|
sendline("sleep 1")
|
|
|
|
sleep(0.1)
|
|
|
|
|
|
|
|
# ctrl-z - send job to background
|
|
|
|
send("\x1A")
|
|
|
|
sleep(0.2)
|
|
|
|
expect_prompt("has stopped")
|
|
|
|
|
|
|
|
# Bring back to fg.
|
|
|
|
sendline("fg")
|
|
|
|
sleep(1.0)
|
|
|
|
|
|
|
|
# Now sleep is done, right?
|
|
|
|
expect_prompt()
|
|
|
|
sendline("jobs")
|
|
|
|
expect_prompt("jobs: There are no jobs")
|
|
|
|
|
|
|
|
# Ensure we can do it again.
|
2021-11-04 06:33:02 +00:00
|
|
|
sendline("sleep 5")
|
2021-02-07 18:52:32 +00:00
|
|
|
sleep(0.2)
|
|
|
|
send("\x1A")
|
|
|
|
sleep(0.1)
|
|
|
|
expect_prompt("has stopped")
|
|
|
|
sendline("fg")
|
|
|
|
sleep(0.1) # allow tty to transfer
|
|
|
|
send("\x03") # control-c to cancel it
|
|
|
|
|
|
|
|
expect_prompt()
|
|
|
|
sendline("jobs")
|
|
|
|
expect_prompt("jobs: There are no jobs")
|
|
|
|
|
|
|
|
# Regression test for #2214: foregrounding from a key binding works!
|
2024-03-30 15:10:12 +00:00
|
|
|
sendline(r"bind ctrl-r 'fg >/dev/null 2>/dev/null'")
|
2021-02-07 18:52:32 +00:00
|
|
|
expect_prompt()
|
|
|
|
sendline("$fish_test_helper print_stop_cont")
|
|
|
|
sleep(0.2)
|
|
|
|
|
|
|
|
send("\x1A") # ctrl-z
|
|
|
|
expect_prompt("SIGTSTP")
|
|
|
|
sleep(0.1)
|
|
|
|
send("\x12") # ctrl-r, placing fth in foreground
|
|
|
|
expect_str("SIGCONT")
|
|
|
|
|
|
|
|
# Do it again.
|
2021-03-11 05:02:32 +00:00
|
|
|
send("\x1A")
|
|
|
|
expect_str("SIGTSTP")
|
|
|
|
sleep(0.1)
|
|
|
|
send("\x12")
|
|
|
|
expect_str("SIGCONT")
|
2021-02-07 18:52:32 +00:00
|
|
|
|
|
|
|
# End fth by sending it anything.
|
|
|
|
send("\x12")
|
|
|
|
sendline("derp")
|
|
|
|
expect_prompt()
|