mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-05 16:21:15 -03:00
builtin test: Let -t work for the standard streams
Since builtins don't actually have the streams connected, but instead read input via the io_streams_t objects, this would just always say what *fish's* fds were. Instead, pass along some of the stream data to check those specifically - nobody cares that `test`s fd 0 *technically* is stdin. What they want to know is that, if they used another program in that place, it would connect to the TTY. This is pretty hacky - I abused static variables for this, but since it's two bools and an int it's probably okay. See #1228. Fixes #4766.
This commit is contained in:
59
tests/pexpects/isatty.py
Normal file
59
tests/pexpects/isatty.py
Normal file
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env python3
|
||||
from pexpect_helper import SpawnedProc
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
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()
|
||||
|
||||
sendline("test -t 0; echo $status")
|
||||
expect_prompt("0")
|
||||
|
||||
sendline("""function t
|
||||
test -t 0 && echo stdin
|
||||
test -t 1 && echo stdout
|
||||
test -t 2 && echo stderr
|
||||
end""")
|
||||
expect_prompt()
|
||||
|
||||
sendline("t")
|
||||
expect_str("stdin")
|
||||
expect_str("stdout")
|
||||
expect_str("stderr")
|
||||
expect_prompt()
|
||||
|
||||
sendline("cat </dev/null | t")
|
||||
expect_str("stdout")
|
||||
expect_str("stderr")
|
||||
expect_prompt()
|
||||
|
||||
sendline("t | cat")
|
||||
expect_str("stdin")
|
||||
expect_str("stderr")
|
||||
expect_prompt()
|
||||
|
||||
sendline("t 2>| cat")
|
||||
expect_str("stdin")
|
||||
expect_str("stdout")
|
||||
expect_prompt()
|
||||
|
||||
sendline("cat </dev/null | t | cat")
|
||||
expect_str("stderr")
|
||||
expect_prompt()
|
||||
sendline("cat </dev/null | t 2>| cat")
|
||||
expect_str("stdout")
|
||||
expect_prompt()
|
||||
|
||||
sendline("t </dev/null")
|
||||
expect_str("stdout")
|
||||
expect_str("stderr")
|
||||
expect_prompt()
|
||||
Reference in New Issue
Block a user