2020-10-07 08:49:07 +08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import os
|
|
|
|
from pexpect_helper import SpawnedProc
|
|
|
|
import signal
|
|
|
|
|
|
|
|
sp = SpawnedProc()
|
2020-11-22 21:39:48 +08:00
|
|
|
send, sendline, sleep, expect_str, expect_prompt = (
|
|
|
|
sp.send,
|
|
|
|
sp.sendline,
|
|
|
|
sp.sleep,
|
|
|
|
sp.expect_str,
|
|
|
|
sp.expect_prompt,
|
|
|
|
)
|
2020-10-07 08:49:07 +08:00
|
|
|
expect_prompt()
|
|
|
|
|
2021-07-13 00:45:46 +08:00
|
|
|
timeout = 0.15
|
2021-07-13 00:54:40 +08:00
|
|
|
|
2021-07-13 00:45:46 +08:00
|
|
|
if "CI" in os.environ:
|
2021-12-29 13:35:30 +08:00
|
|
|
# This doesn't work under TSan, because TSan prevents select() being
|
|
|
|
# interrupted by a signal.
|
2021-07-13 00:54:40 +08:00
|
|
|
import sys
|
2022-06-17 00:43:28 +08:00
|
|
|
|
2021-07-13 00:54:40 +08:00
|
|
|
print("SKIPPING cancel_event.py")
|
|
|
|
sys.exit(0)
|
2021-07-13 00:45:46 +08:00
|
|
|
|
2020-10-07 08:49:07 +08:00
|
|
|
# Verify that cancel-commandline does what we expect - see #7384.
|
|
|
|
send("not executed")
|
2021-07-13 00:45:46 +08:00
|
|
|
sleep(timeout)
|
2020-10-07 08:49:07 +08:00
|
|
|
os.kill(sp.spawn.pid, signal.SIGINT)
|
2023-12-28 21:41:30 +08:00
|
|
|
sendline("echo marker")
|
|
|
|
sp.expect_str("marker")
|
|
|
|
expect_prompt()
|
2020-10-07 08:49:07 +08:00
|
|
|
|
|
|
|
sendline("function cancelhandler --on-event fish_cancel ; echo yay cancelled ; end")
|
|
|
|
expect_prompt()
|
|
|
|
send("still not executed")
|
2021-07-13 00:45:46 +08:00
|
|
|
sleep(timeout)
|
2020-10-07 08:49:07 +08:00
|
|
|
os.kill(sp.spawn.pid, signal.SIGINT)
|
2023-12-28 21:41:30 +08:00
|
|
|
expect_str("yay cancelled")
|
|
|
|
sendline("echo marker")
|
|
|
|
sp.expect_str("marker")
|
|
|
|
expect_prompt()
|