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>
This commit is contained in:
parent
c7405fe9cb
commit
d0fc382c4b
@ -35,10 +35,11 @@ FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)")
|
|||||||
|
|
||||||
class TTYTestCase(test.TestCase):
|
class TTYTestCase(test.TestCase):
|
||||||
|
|
||||||
def __init__(self, path, file, expected, arch, mode, context, config):
|
def __init__(self, path, file, expected, input, arch, mode, context, config):
|
||||||
super(TTYTestCase, self).__init__(context, path, arch, mode)
|
super(TTYTestCase, self).__init__(context, path, arch, mode)
|
||||||
self.file = file
|
self.file = file
|
||||||
self.expected = expected
|
self.expected = expected
|
||||||
|
self.input = input
|
||||||
self.config = config
|
self.config = config
|
||||||
self.arch = arch
|
self.arch = arch
|
||||||
self.mode = mode
|
self.mode = mode
|
||||||
@ -104,12 +105,16 @@ class TTYTestCase(test.TestCase):
|
|||||||
+ open(self.expected).read())
|
+ open(self.expected).read())
|
||||||
|
|
||||||
def RunCommand(self, command, env):
|
def RunCommand(self, command, env):
|
||||||
|
input = None
|
||||||
|
if self.input is not None and exists(self.input):
|
||||||
|
input = open(self.input).read()
|
||||||
full_command = self.context.processor(command)
|
full_command = self.context.processor(command)
|
||||||
output = test.Execute(full_command,
|
output = test.Execute(full_command,
|
||||||
self.context,
|
self.context,
|
||||||
self.context.GetTimeout(self.mode),
|
self.context.GetTimeout(self.mode),
|
||||||
env,
|
env,
|
||||||
True)
|
faketty=True,
|
||||||
|
input=input)
|
||||||
return test.TestOutput(self,
|
return test.TestOutput(self,
|
||||||
full_command,
|
full_command,
|
||||||
output,
|
output,
|
||||||
@ -139,11 +144,12 @@ class TTYTestConfiguration(test.TestConfiguration):
|
|||||||
if self.Contains(path, test):
|
if self.Contains(path, test):
|
||||||
file_prefix = join(self.root, reduce(join, test[1:], ""))
|
file_prefix = join(self.root, reduce(join, test[1:], ""))
|
||||||
file_path = file_prefix + ".js"
|
file_path = file_prefix + ".js"
|
||||||
|
input_path = file_prefix + ".in"
|
||||||
output_path = file_prefix + ".out"
|
output_path = file_prefix + ".out"
|
||||||
if not exists(output_path):
|
if not exists(output_path):
|
||||||
raise Exception("Could not find %s" % output_path)
|
raise Exception("Could not find %s" % output_path)
|
||||||
result.append(TTYTestCase(test, file_path, output_path,
|
result.append(TTYTestCase(test, file_path, output_path,
|
||||||
arch, mode, self.context, self))
|
input_path, arch, mode, self.context, self))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def GetBuildRequirements(self):
|
def GetBuildRequirements(self):
|
||||||
|
@ -705,12 +705,23 @@ def CheckedUnlink(name):
|
|||||||
PrintError("os.unlink() " + str(e))
|
PrintError("os.unlink() " + str(e))
|
||||||
break
|
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:
|
if faketty:
|
||||||
import pty
|
import pty
|
||||||
(out_master, fd_out) = pty.openpty()
|
(out_master, fd_out) = pty.openpty()
|
||||||
fd_in = fd_err = fd_out
|
fd_in = fd_err = fd_out
|
||||||
pty_out = out_master
|
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:
|
else:
|
||||||
(fd_out, outname) = tempfile.mkstemp()
|
(fd_out, outname) = tempfile.mkstemp()
|
||||||
(fd_err, errname) = tempfile.mkstemp()
|
(fd_err, errname) = tempfile.mkstemp()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user