示例#1
0
#!/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,
)
expect_prompt()

# Clear twice (regression test for #7280).
send("\f")
expect_prompt(increment=False)
send("\f")
expect_prompt(increment=False)

# Fish should start in default-mode (i.e., emacs) bindings. The default escape
# timeout is 30ms.
#
# Because common CI systems are awful, we have to increase this:

sendline("set -g fish_escape_delay_ms 120")
expect_prompt("")

# Verify the emacs transpose word (\et) behavior using various delays,
# including none, after the escape character.
#!/usr/bin/env python3
from pexpect_helper import SpawnedProc
import os
import signal
import tempfile
from time import sleep

# Ensure that on-exit handlers run even if we get SIGHUP.
with tempfile.NamedTemporaryFile(mode="r", encoding="utf8") as tf:
    sp = SpawnedProc()
    ghoti_pid = sp.spawn.pid
    sp.expect_prompt()
    sp.sendline(
        "function myexit --on-event ghoti_exit; /bin/echo $ghoti_pid > {filename}; end".format(
            filename=tf.name
        )
    )
    sp.expect_prompt()
    os.kill(ghoti_pid, signal.SIGHUP)
    # Note that ghoti's SIGHUP handling in interactive mode races with the call to select.
    # So actually close its stdin, like a terminal emulator would do.
    sp.spawn.close(force=False)
    sp.spawn.wait()
    tf.seek(0)
    line = tf.readline().strip()
    if line != str(ghoti_pid):
        colors = sp.colors()
        print(
            """{RED}Failed to find pid written by exit handler{RESET}""".format(
                **colors
            )
示例#3
0
#!/usr/bin/env python3
from pexpect_helper import SpawnedProc
import subprocess
import sys
import time
import os

env = os.environ.copy()
env["TERM"] = "xterm"

sp = SpawnedProc(env=env)
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()

# See that --print-colors prints the colors colored.
# Note that we don't check *all* of them, just a few.
sendline("set_color --print-colors")
expect_str("black")
expect_str("blue")
expect_str("brblack")
expect_str("brblue")
expect_str("brcyan")
expect_str("brgreen")
expect_str("brmagenta")
示例#4
0
#!/usr/bin/env python3
from pexpect_helper import SpawnedProc
import subprocess
import sys
import signal
import time
import os

sp = SpawnedProc()
send, sendline, sleep, expect_prompt, expect_re = (
    sp.send,
    sp.sendline,
    sp.sleep,
    sp.expect_prompt,
    sp.expect_re,
)

# Helper to print an error and exit.
def error_and_exit(text):
    keys = sp.colors()
    print("{RED}Test failed: {NORMAL}{TEXT}".format(TEXT=text, **keys))
    sys.exit(1)


fish_pid = sp.spawn.pid

# Launch fish_test_helper.
expect_prompt()
exe_path = os.environ.get("fish_test_helper")
sp.sendline(exe_path + " nohup_wait")
示例#5
0
#!/usr/bin/env python3
from pexpect_helper import SpawnedProc

sp = SpawnedProc(timeout=10)
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
import os
import signal
import subprocess
import sys

expect_prompt()

sendline("sleep 10 &")
expect_prompt()

send("\x03")
sleep(0.010)
sendline("jobs")
expect_prompt("sleep.10")
sendline("kill %1")
expect_prompt()
示例#6
0
#!/usr/bin/env python3
from pexpect_helper import SpawnedProc
import platform

# Set a 0 terminal size
sp = SpawnedProc(args=["-d", "term-support"], dimensions=(0, 0))
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()
# Now confirm it defaulted to 80x24
sendline("echo $COLUMNS $LINES")
expect_str("80 24")
expect_str(
    "term-support: Terminal has 0 columns, falling back to default width")
expect_str("term-support: Terminal has 0 rows, falling back to default height")
expect_prompt()

sendline("stty -a")
expect_prompt()
# Confirm flow control in the shell is disabled - we should ignore the ctrl-s in there.
sendline("echo hello\x13hello")
expect_prompt("hellohello")

# Confirm it is off for external commands
示例#7
0
#
# This is meant to verify just a few of the most basic behaviors of the
# interactive history to hopefully keep regressions from happening. It is not
# meant to be a comprehensive test of the history subsystem. Those types of
# tests belong in the src/fish_tests.cpp module.
#

# The history function might pipe output through the user's pager. We don't
# want something like `less` to complicate matters so force the use of `cat`.
from pexpect_helper import SpawnedProc
import os

os.environ["PAGER"] = "cat"
os.environ["TERM"] = "xterm"

sp = SpawnedProc(env=os.environ.copy())

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()

# ==========
# Start by ensuring we're not affected by earlier tests. Clear the history.
sendline("builtin history clear")
expect_prompt()
示例#8
0
#!/usr/bin/env python3
import os
from pexpect_helper import SpawnedProc
import signal

sp = SpawnedProc()
send, sendline, sleep, expect_str, expect_prompt = (
    sp.send,
    sp.sendline,
    sp.sleep,
    sp.expect_str,
    sp.expect_prompt,
)
expect_prompt()

timeout = 0.15

if "CI" in os.environ:
    # This doesn't work under tsan.
    import sys
    print("SKIPPING cancel_event.py")
    sys.exit(0)

# Verify that cancel-commandline does what we expect - see #7384.
send("not executed")
sleep(timeout)
os.kill(sp.spawn.pid, signal.SIGINT)
sp.expect_str("not executed^C")
expect_prompt(increment=False)

sendline("function cancelhandler --on-event fish_cancel ; echo yay cancelled ; end")
#!/usr/bin/env python3
from pexpect_helper import SpawnedProc
import os
import signal

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")
expect_prompt("\r\nready to go\r\n")
send(
    "function add_change --on-variable fish_bind_mode ; set -g MODE_CHANGES $MODE_CHANGES $fish_bind_mode ; end\r"
)
expect_prompt()

# normal mode
send("\033")
sleep(0.050)

# insert mode
send("i")
sleep(0.050)

# back to normal mode
send("\033")
sleep(0.050)
示例#10
0
#!/usr/bin/env python3
from pexpect_helper import SpawnedProc
import subprocess
import sys
import time

sp = SpawnedProc(args=["-d", "reader"])
sp.expect_prompt()

# Verify we correctly diable mouse tracking.

# Five char sequence.
sp.send("\x1b[tDE")
sp.expect_str("reader: Disabling mouse tracking")

# Six char sequence.
sp.send("\x1b[MABC")
sp.expect_str("reader: Disabling mouse tracking")

# Nine char sequences.
sp.send("\x1b[TABCDEF")
sp.expect_str("reader: Disabling mouse tracking")

# Extended SGR sequences.
sp.send("\x1b[<fooM")
sp.expect_str("reader: Disabling mouse tracking")

sp.send("\x1b[<foobarm")
sp.expect_str("reader: Disabling mouse tracking")

sp.sendline("echo done")