summaryrefslogtreecommitdiff
path: root/tools/test.py
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2018-09-24 11:47:13 +0200
committerAnna Henningsen <anna@addaleax.net>2018-10-04 09:20:22 -0700
commitd0fc382c4b18a7021d0a93194bc4b304ed6f7d6f (patch)
tree268023ca916df2842ebc4123313954e95772eaad /tools/test.py
parentc7405fe9cb91124d966235467d6a9148e6bc9bd5 (diff)
downloadnode-new-d0fc382c4b18a7021d0a93194bc4b304ed6f7d6f.tar.gz
tools: allow input for TTY tests
Since faking TTY input is not otherwise fake-able, we need support in the test runner for it. PR-URL: https://github.com/nodejs/node/pull/23053 Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'tools/test.py')
-rwxr-xr-xtools/test.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/tools/test.py b/tools/test.py
index b6f91aa1eb..c5c9fb53c0 100755
--- a/tools/test.py
+++ b/tools/test.py
@@ -705,12 +705,23 @@ def CheckedUnlink(name):
PrintError("os.unlink() " + str(e))
break
-def Execute(args, context, timeout=None, env={}, faketty=False, disable_core_files=False):
+def Execute(args, context, timeout=None, env={}, faketty=False, disable_core_files=False, input=None):
if faketty:
import pty
(out_master, fd_out) = pty.openpty()
fd_in = fd_err = fd_out
pty_out = out_master
+
+ if input is not None:
+ # Before writing input data, disable echo so the input doesn't show
+ # up as part of the output.
+ import termios
+ attr = termios.tcgetattr(fd_in)
+ attr[3] = attr[3] & ~termios.ECHO
+ termios.tcsetattr(fd_in, termios.TCSADRAIN, attr)
+
+ os.write(pty_out, input)
+ os.write(pty_out, '\x04') # End-of-file marker (Ctrl+D)
else:
(fd_out, outname) = tempfile.mkstemp()
(fd_err, errname) = tempfile.mkstemp()