Skip to content

Commit fdb190d

Browse files
authored
Simplify test_stdin. NFC (#24114)
1 parent 08775a3 commit fdb190d

File tree

3 files changed

+8
-16
lines changed

3 files changed

+8
-16
lines changed

test/common.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1499,7 +1499,8 @@ def cleanup(line):
14991499

15001500
def run_js(self, filename, engine=None, args=None,
15011501
assert_returncode=0,
1502-
interleaved_output=True):
1502+
interleaved_output=True,
1503+
input=None):
15031504
# use files, as PIPE can get too full and hang us
15041505
stdout_file = self.in_dir('stdout')
15051506
stderr_file = None
@@ -1523,7 +1524,8 @@ def run_js(self, filename, engine=None, args=None,
15231524
jsrun.run_js(filename, engine, args,
15241525
stdout=stdout,
15251526
stderr=stderr,
1526-
assert_returncode=assert_returncode)
1527+
assert_returncode=assert_returncode,
1528+
input=input)
15271529
except subprocess.TimeoutExpired as e:
15281530
timeout_error = e
15291531
except subprocess.CalledProcessError as e:

test/jsrun.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def require_engine(engine):
8484

8585

8686
def run_js(filename, engine, args=None,
87-
stdin=None, stdout=PIPE, stderr=None, cwd=None,
87+
stdin=None, stdout=PIPE, stderr=None, cwd=None, input=None,
8888
full_output=False, assert_returncode=0, skip_check=False,
8989
timeout=DEFAULT_TIMEOUT):
9090
"""Execute javascript code generated by tests, with possible timeout."""
@@ -104,6 +104,7 @@ def run_js(filename, engine, args=None,
104104
stdin=stdin,
105105
stdout=stdout,
106106
stderr=stderr,
107+
input=input,
107108
cwd=cwd,
108109
timeout=timeout,
109110
universal_newlines=True)

test/test_other.py

+2-13
Original file line numberDiff line numberDiff line change
@@ -1669,23 +1669,12 @@ def test_export_all_and_exported_functions(self):
16691669
'closure': (['-O2', '--closure=1'],),
16701670
})
16711671
def test_stdin(self, args):
1672-
create_file('in.txt', 'abcdef\nghijkl\n')
16731672
self.set_setting('ENVIRONMENT', 'node,shell')
16741673
self.emcc(test_file('module/test_stdin.c'), args=args, output_filename='out.js')
16751674

16761675
for engine in config.JS_ENGINES:
1677-
engine[0] = os.path.normpath(engine[0])
1678-
# work around a bug in python's subprocess module
1679-
# (we'd use self.run_js() normally)
1680-
delete_file('out.txt')
1681-
cmd = jsrun.make_command(os.path.normpath('out.js'), engine)
1682-
cmd = shared.shlex_join(cmd)
1683-
print(cmd, file=sys.stderr)
1684-
if WINDOWS:
1685-
os.system(f'type "in.txt" | {cmd} >out.txt')
1686-
else: # posix
1687-
os.system(f'cat in.txt | {cmd} > out.txt')
1688-
self.assertContained('abcdef\nghijkl\neof', read_file('out.txt'))
1676+
output = self.run_js('out.js', engine, input='abcdef\nghijkl\n')
1677+
self.assertContained('abcdef\nghijkl\neof', output)
16891678

16901679
@crossplatform
16911680
def test_module_stdin(self):

0 commit comments

Comments
 (0)