GeezerVison is showing github.com — tools: allow input for TTY tests · nodejs/node@d7031df
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: test/pseudo-tty/testcfg.py +9-3Lines changed: 9 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 35 | 35 |
| 36 | 36 | class TTYTestCase(test.TestCase): | 37 | 37 |
| 38 | | - def __init__(self, path, file, expected, arch, mode, context, config): | | 38 | + def __init__(self, path, file, expected, input, arch, mode, context, config): | 39 | 39 | super(TTYTestCase, self).__init__(context, path, arch, mode) | 40 | 40 | self.file = file | 41 | 41 | self.expected = expected | | 42 | + self.input = input | 42 | 43 | self.config = config | 43 | 44 | self.arch = arch | 44 | 45 | self.mode = mode | @@ -104,12 +105,16 @@ def GetSource(self): | 104 | 105 | + open(self.expected).read()) | 105 | 106 |
| 106 | 107 | def RunCommand(self, command, env): | | 108 | + input = None | | 109 | + if self.input is not None and exists(self.input): | | 110 | + input = open(self.input).read() | 107 | 111 | full_command = self.context.processor(command) | 108 | 112 | output = test.Execute(full_command, | 109 | 113 | self.context, | 110 | 114 | self.context.GetTimeout(self.mode), | 111 | 115 | env, | 112 | | - True) | | 116 | + faketty=True, | | 117 | + input=input) | 113 | 118 | return test.TestOutput(self, | 114 | 119 | full_command, | 115 | 120 | output, | @@ -139,11 +144,12 @@ def ListTests(self, current_path, path, arch, mode): | 139 | 144 | if self.Contains(path, test): | 140 | 145 | file_prefix = join(self.root, reduce(join, test[1:], "")) | 141 | 146 | file_path = file_prefix + ".js" | | 147 | + input_path = file_prefix + ".in" | 142 | 148 | output_path = file_prefix + ".out" | 143 | 149 | if not exists(output_path): | 144 | 150 | raise Exception("Could not find %s" % output_path) | 145 | 151 | result.append(TTYTestCase(test, file_path, output_path, | 146 | | - arch, mode, self.context, self)) | | 152 | + input_path, arch, mode, self.context, self)) | 147 | 153 | return result | 148 | 154 |
| 149 | 155 | def GetBuildRequirements(self): | |
Collapse file Copy file name to clipboardExpand all lines: tools/test.py +12-1Lines changed: 12 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -705,12 +705,23 @@ def CheckedUnlink(name): | 705 | 705 | PrintError("os.unlink() " + str(e)) | 706 | 706 | break | 707 | 707 |
| 708 | | -def Execute(args, context, timeout=None, env={}, faketty=False, disable_core_files=False): | | 708 | +def Execute(args, context, timeout=None, env={}, faketty=False, disable_core_files=False, input=None): | 709 | 709 | if faketty: | 710 | 710 | import pty | 711 | 711 | (out_master, fd_out) = pty.openpty() | 712 | 712 | fd_in = fd_err = fd_out | 713 | 713 | pty_out = out_master | | 714 | + | | 715 | + if input is not None: | | 716 | + # Before writing input data, disable echo so the input doesn't show | | 717 | + # up as part of the output. | | 718 | + import termios | | 719 | + attr = termios.tcgetattr(fd_in) | | 720 | + attr[3] = attr[3] & ~termios.ECHO | | 721 | + termios.tcsetattr(fd_in, termios.TCSADRAIN, attr) | | 722 | + | | 723 | + os.write(pty_out, input) | | 724 | + os.write(pty_out, '\x04') # End-of-file marker (Ctrl+D) | 714 | 725 | else: | 715 | 726 | (fd_out, outname) = tempfile.mkstemp() | 716 | 727 | (fd_err, errname) = tempfile.mkstemp() | |
|