2020-09-17 00:22:12 +08:00
|
|
|
#!/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")
|
|
|
|
|
2020-11-22 21:39:48 +08:00
|
|
|
sendline(
|
|
|
|
"""function t
|
2020-09-17 00:22:12 +08:00
|
|
|
test -t 0 && echo stdin
|
|
|
|
test -t 1 && echo stdout
|
|
|
|
test -t 2 && echo stderr
|
2020-11-22 21:39:48 +08:00
|
|
|
end"""
|
|
|
|
)
|
2020-09-17 00:22:12 +08:00
|
|
|
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()
|
2020-09-17 02:58:07 +08:00
|
|
|
|
|
|
|
sendline("isatty stdin && echo yes")
|
|
|
|
expect_str("yes")
|
|
|
|
expect_prompt()
|
|
|
|
|
|
|
|
sendline("cat </dev/null | isatty stdin || echo no")
|
|
|
|
expect_str("no")
|
|
|
|
expect_prompt()
|