2020-06-08 23:08:48 +08:00
|
|
|
#!/usr/bin/env python3
|
2020-03-30 00:34:08 +08:00
|
|
|
from pexpect_helper import SpawnedProc, control
|
2020-06-08 23:08:48 +08:00
|
|
|
|
|
|
|
sp = SpawnedProc()
|
2022-06-05 06:33:55 +08:00
|
|
|
send, sendline, sleep, expect_prompt, expect_re, expect_str = (
|
|
|
|
sp.send,
|
|
|
|
sp.sendline,
|
|
|
|
sp.sleep,
|
|
|
|
sp.expect_prompt,
|
|
|
|
sp.expect_re,
|
|
|
|
sp.expect_str,
|
|
|
|
)
|
2020-06-08 23:08:48 +08:00
|
|
|
expect_prompt()
|
|
|
|
|
2024-06-27 11:20:24 +08:00
|
|
|
# Test --showing-suggestion before we dirty the history
|
|
|
|
sendline("echo hello")
|
|
|
|
expect_prompt()
|
|
|
|
sendline("function debug; commandline --showing-suggestion; set -g cmd_status $status; end")
|
|
|
|
expect_prompt()
|
|
|
|
sendline("bind ctrl-p debug");
|
|
|
|
expect_prompt()
|
|
|
|
send("echo hell")
|
|
|
|
sleep(0.1) # wait for suggestion to appear under CI
|
|
|
|
send(control("p"))
|
|
|
|
sendline("")
|
|
|
|
expect_prompt("hell")
|
|
|
|
sendline("echo cmd_status: $cmd_status")
|
|
|
|
expect_prompt("cmd_status: 0")
|
|
|
|
send("echo goodb")
|
|
|
|
sleep(0.1) # wait for suggestion to appear under CI
|
|
|
|
send(control("p"))
|
|
|
|
sendline("")
|
|
|
|
expect_prompt("goodb")
|
|
|
|
sendline("echo cmd_status: $cmd_status")
|
|
|
|
expect_prompt("cmd_status: 1")
|
|
|
|
|
2020-06-08 23:08:48 +08:00
|
|
|
sendline("bind '~' 'handle_tilde'")
|
|
|
|
expect_prompt()
|
|
|
|
|
|
|
|
# printing the current buffer should not remove quoting
|
2020-06-08 23:32:56 +08:00
|
|
|
sendline(
|
|
|
|
"function handle_tilde; echo; echo '@GUARD:1@'; commandline -b; echo '@/GUARD:1@'; commandline -b ''; end"
|
|
|
|
)
|
2020-06-08 23:08:48 +08:00
|
|
|
expect_prompt()
|
2020-06-08 23:32:56 +08:00
|
|
|
sendline("echo \en one \"two three\" four'five six'{7} 'eight~")
|
2020-06-08 23:08:48 +08:00
|
|
|
expect_prompt("\r\n@GUARD:1@\r\n(.*)\r\n@/GUARD:1@\r\n")
|
|
|
|
|
|
|
|
# printing the buffer with -o should remove quoting
|
2020-06-08 23:32:56 +08:00
|
|
|
sendline(
|
2024-01-22 14:42:45 +08:00
|
|
|
"function handle_tilde; echo; echo '@GUARD:2@'; commandline -bx; echo '@/GUARD:2@'; commandline -b ''; end"
|
2020-06-08 23:32:56 +08:00
|
|
|
)
|
2020-06-08 23:08:48 +08:00
|
|
|
expect_prompt()
|
|
|
|
sendline("echo one \"two three\" four'five six'{7} 'eight~")
|
|
|
|
expect_prompt("\r\n@GUARD:2@\r\n(.*)\r\n@/GUARD:2@\r\n")
|
2020-09-12 01:23:26 +08:00
|
|
|
|
|
|
|
# Check that we don't infinitely loop here.
|
|
|
|
sendline("function fish_mode_prompt; commandline -f repaint; end")
|
|
|
|
expect_prompt()
|
|
|
|
|
|
|
|
sendline("echo foo")
|
|
|
|
expect_prompt("foo")
|
2021-07-21 04:18:03 +08:00
|
|
|
|
|
|
|
# commandline is empty when a command is executed.
|
|
|
|
sendline("set what (commandline)")
|
|
|
|
expect_prompt()
|
|
|
|
sendline('echo "<$what>"')
|
|
|
|
expect_prompt("<>")
|
2021-07-22 06:35:22 +08:00
|
|
|
|
|
|
|
# Test for undocumented -I flag.
|
|
|
|
# TODO: consider removing.
|
|
|
|
sendline("commandline -I foo")
|
|
|
|
expect_prompt("foo")
|
2021-07-28 00:49:55 +08:00
|
|
|
|
|
|
|
# See that the commandline is updated immediately inside completions.
|
|
|
|
sendline("complete -c foo -xa '(commandline)'")
|
|
|
|
expect_prompt()
|
|
|
|
send("foo bar \t")
|
2024-04-13 07:59:07 +08:00
|
|
|
expect_str("foo bar 'foo bar '")
|
2022-06-05 06:33:55 +08:00
|
|
|
send("\b" * 64)
|
|
|
|
|
|
|
|
# Commandline works when run on its own (#8807).
|
|
|
|
sendline("commandline whatever")
|
|
|
|
expect_re("prompt [0-9]+>whatever")
|
2020-03-30 00:34:08 +08:00
|
|
|
|
|
|
|
# Test --current-process output
|
|
|
|
send(control("u"))
|
2024-03-30 23:10:12 +08:00
|
|
|
sendline(r"bind ctrl-b 'set tmp (commandline --current-process)'")
|
2020-03-30 00:34:08 +08:00
|
|
|
expect_prompt()
|
|
|
|
send("echo process1; echo process2")
|
|
|
|
send(control("a"))
|
|
|
|
send(control("b"))
|
|
|
|
send(control("k"))
|
2022-11-13 06:25:47 +08:00
|
|
|
sendline("echo first process is [$tmp]")
|
|
|
|
expect_str("first process is [echo process1]")
|
2020-03-30 00:34:08 +08:00
|
|
|
|
|
|
|
send("echo process # comment")
|
|
|
|
send(control("a"))
|
|
|
|
send(control("b"))
|
|
|
|
send(control("k"))
|
2022-11-13 06:25:47 +08:00
|
|
|
sendline('echo "process extent is [$tmp]"')
|
|
|
|
expect_str("process extent is [echo process # comment]")
|
2020-03-30 00:34:08 +08:00
|
|
|
|
2023-04-28 23:41:29 +08:00
|
|
|
# DISABLED because it keeps failing under ASAN
|
2024-03-30 23:10:12 +08:00
|
|
|
# sendline(r"bind ctrl-b 'set tmp (commandline --current-process | count)'")
|
2023-04-28 23:41:29 +08:00
|
|
|
# sendline(r'commandline "echo line1 \\" "# comment" "line2"')
|
|
|
|
# send(control("b"))
|
|
|
|
# send(control("u") * 6)
|
|
|
|
# sendline('echo "process spans $tmp lines"')
|
|
|
|
# expect_str("process spans 3 lines")
|