2020-06-08 23:12:49 +08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
from pexpect_helper import SpawnedProc
|
2021-07-12 07:50:21 +08:00
|
|
|
import os
|
2024-03-30 23:10:12 +08:00
|
|
|
import sys
|
2021-07-12 07:50:21 +08:00
|
|
|
import signal
|
2024-03-30 23:10:12 +08:00
|
|
|
import platform
|
|
|
|
|
2024-04-12 18:32:46 +08:00
|
|
|
if platform.system() == "FreeBSD": # Spurious failure. TODO Only disable this in CI.
|
|
|
|
sys.exit(127)
|
|
|
|
|
2024-03-30 23:10:12 +08:00
|
|
|
if "CI" in os.environ and platform.system() == "Darwin":
|
|
|
|
sys.exit(127)
|
2020-06-08 23:12:49 +08:00
|
|
|
|
|
|
|
sp = SpawnedProc()
|
|
|
|
send, sendline, sleep, expect_prompt = sp.send, sp.sendline, sp.sleep, sp.expect_prompt
|
|
|
|
expect_prompt()
|
|
|
|
|
|
|
|
send("set -g fish_key_bindings fish_vi_key_bindings\r")
|
|
|
|
expect_prompt()
|
|
|
|
|
|
|
|
send("echo ready to go\r")
|
2024-04-03 03:22:36 +08:00
|
|
|
expect_prompt(f"\r\n.*ready to go\r\n")
|
2020-06-08 23:32:56 +08:00
|
|
|
send(
|
|
|
|
"function add_change --on-variable fish_bind_mode ; set -g MODE_CHANGES $MODE_CHANGES $fish_bind_mode ; end\r"
|
|
|
|
)
|
2020-06-08 23:12:49 +08:00
|
|
|
expect_prompt()
|
|
|
|
|
2024-05-06 09:23:05 +08:00
|
|
|
sendline("echo 'Catch' 'up'")
|
|
|
|
expect_prompt("Catch up")
|
|
|
|
|
2020-06-08 23:12:49 +08:00
|
|
|
# normal mode
|
|
|
|
send("\033")
|
2024-03-30 23:10:12 +08:00
|
|
|
sleep(10 if "CI" in os.environ else 1)
|
2020-06-08 23:12:49 +08:00
|
|
|
|
|
|
|
# insert mode
|
|
|
|
send("i")
|
2024-03-30 23:10:12 +08:00
|
|
|
sleep(10 if "CI" in os.environ else 1)
|
2020-06-08 23:12:49 +08:00
|
|
|
|
|
|
|
# back to normal mode
|
|
|
|
send("\033")
|
2024-03-30 23:10:12 +08:00
|
|
|
sleep(10 if "CI" in os.environ else 1)
|
2020-06-08 23:12:49 +08:00
|
|
|
|
|
|
|
# insert mode again
|
|
|
|
send("i")
|
2024-03-30 23:10:12 +08:00
|
|
|
sleep(10 if "CI" in os.environ else 1)
|
2020-06-08 23:12:49 +08:00
|
|
|
|
|
|
|
send("echo mode changes: $MODE_CHANGES\r")
|
2024-04-03 03:22:36 +08:00
|
|
|
expect_prompt("\r\n.*mode changes: default insert default insert\r\n")
|
2021-07-12 07:50:21 +08:00
|
|
|
|
|
|
|
# Regression test for #8125.
|
|
|
|
# Control-C should return us to insert mode.
|
|
|
|
send("set -e MODE_CHANGES\r")
|
|
|
|
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 the last of bind_mode_events.py")
|
|
|
|
sys.exit(0)
|
2021-07-13 00:45:46 +08:00
|
|
|
|
2021-07-12 07:50:21 +08:00
|
|
|
# Put some text on the command line and then go back to normal mode.
|
|
|
|
send("echo stuff")
|
|
|
|
sp.expect_str("echo stuff")
|
|
|
|
send("\033")
|
2021-07-13 00:45:46 +08:00
|
|
|
sleep(timeout)
|
2021-07-12 07:50:21 +08:00
|
|
|
|
|
|
|
os.kill(sp.spawn.pid, signal.SIGINT)
|
2021-07-13 00:45:46 +08:00
|
|
|
sleep(timeout)
|
2021-07-12 07:50:21 +08:00
|
|
|
|
|
|
|
# We should be back in insert mode now.
|
|
|
|
send("echo mode changes: $MODE_CHANGES\r")
|
2024-04-03 03:22:36 +08:00
|
|
|
expect_prompt("\r\n.*mode changes: default insert\r\n")
|