2020-06-13 13:12:20 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
from pexpect_helper import SpawnedProc
|
|
|
|
|
|
|
|
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,
|
|
|
|
)
|
|
|
|
|
|
|
|
from time import sleep
|
|
|
|
from subprocess import call
|
2020-11-09 18:27:56 +00:00
|
|
|
import os
|
|
|
|
import signal
|
2023-11-19 18:45:27 +00:00
|
|
|
import sys
|
|
|
|
|
|
|
|
# Disable under SAN - keeps failing because the timing is too tight
|
|
|
|
if "FISH_CI_SAN" in os.environ:
|
|
|
|
sys.exit(0)
|
2020-06-13 13:12:20 +00:00
|
|
|
|
|
|
|
# Test job summary for interactive shells.
|
|
|
|
expect_prompt()
|
|
|
|
|
|
|
|
sendline("function fish_job_summary; string join ':' $argv; end")
|
|
|
|
expect_prompt()
|
|
|
|
|
|
|
|
# fish_job_summary is called when background job ends.
|
|
|
|
sendline("sleep 0.5 &")
|
|
|
|
expect_prompt()
|
2020-08-08 13:50:02 +00:00
|
|
|
expect_re("[0-9]+:0:sleep 0.5 &:ENDED", timeout=20)
|
2020-06-13 13:12:20 +00:00
|
|
|
sendline("")
|
|
|
|
expect_prompt()
|
|
|
|
|
|
|
|
# fish_job_summary is called when background job is signalled.
|
|
|
|
# cmd_line correctly prints only the actually backgrounded job.
|
2020-11-09 18:27:56 +00:00
|
|
|
sendline("false; sleep 20 &; true")
|
2020-06-13 13:12:20 +00:00
|
|
|
expect_prompt()
|
2020-11-09 18:27:56 +00:00
|
|
|
sendline("set -l my_pid $last_pid")
|
|
|
|
expect_prompt("")
|
2020-08-12 16:36:43 +00:00
|
|
|
sendline("jobs")
|
2020-08-12 22:04:53 +00:00
|
|
|
expect_re("Job.*Group.*(CPU)?.*State.*Command")
|
2020-11-09 18:27:56 +00:00
|
|
|
expect_re(".*running.*sleep 20 &")
|
2020-09-04 15:51:55 +00:00
|
|
|
expect_prompt()
|
2020-11-09 18:27:56 +00:00
|
|
|
sendline("echo $my_pid")
|
2024-04-02 20:40:45 +00:00
|
|
|
m = expect_re("\\d+\r\n")
|
2020-08-12 16:36:43 +00:00
|
|
|
expect_prompt()
|
2020-11-09 18:27:56 +00:00
|
|
|
os.kill(int(m.group()), signal.SIGTERM)
|
|
|
|
expect_re("[0-9]+:0:sleep 20 &:SIGTERM:Polite quit request", timeout=20)
|
2020-06-13 13:12:20 +00:00
|
|
|
sendline("")
|
|
|
|
expect_prompt()
|
|
|
|
|
|
|
|
# fish_job_summary is called when foreground job is signalled.
|
|
|
|
# cmd_line contains the entire pipeline. proc_id and proc_name are set in a pipeline.
|
|
|
|
sendline("true | sleep 6")
|
|
|
|
sleep(0.100)
|
2021-09-04 20:32:51 +00:00
|
|
|
# Beware: Mac pkill requires that the -P argument come before the process name,
|
|
|
|
# else the -P argument is ignored.
|
|
|
|
call(["pkill", "-KILL", "-P", str(sp.spawn.pid), "sleep"])
|
2020-08-08 13:50:02 +00:00
|
|
|
expect_re("[0-9]+:1:true|sleep 6:SIGKILL:Forced quit:[0-9]+:sleep", timeout=20)
|