Skip to content

Commit

Permalink
Use @parameterize for test_stdin. NFC (#21923)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbc100 committed May 9, 2024
1 parent c412949 commit a488fca
Showing 1 changed file with 25 additions and 26 deletions.
51 changes: 25 additions & 26 deletions test/test_other.py
Expand Up @@ -113,13 +113,13 @@ def also_with_wasmfs(f):
assert callable(f)

@wraps(f)
def metafunc(self, wasmfs):
def metafunc(self, wasmfs, *args, **kwargs):
if wasmfs:
self.set_setting('WASMFS')
self.emcc_args.append('-DWASMFS')
f(self)
f(self, *args, **kwargs)
else:
f(self)
f(self, *args, **kwargs)

parameterize(metafunc, {'': (False,),
'wasmfs': (True,)})
Expand Down Expand Up @@ -1642,32 +1642,31 @@ def test_export_all_and_exported_functions(self):
self.emcc('lib.c', ['-sEXPORTED_FUNCTIONS=_libfunc2', '-sEXPORT_ALL', '--pre-js', 'pre.js'], output_filename='a.out.js')
self.assertContained('libfunc\n', self.run_js('a.out.js'))

@parameterized({
'': ([],),
'closure': (['-O2', '--closure=1'],),
})
@also_with_wasmfs
@crossplatform
def test_stdin(self):
def run_test():
for engine in config.JS_ENGINES:
if engine == config.V8_ENGINE:
continue # no stdin support in v8 shell
engine[0] = os.path.normpath(engine[0])
print(engine, file=sys.stderr)
# work around a bug in python's subprocess module
# (we'd use self.run_js() normally)
delete_file('out.txt')
cmd = jsrun.make_command(os.path.normpath('out.js'), engine)
cmd = shared.shlex_join(cmd)
if WINDOWS:
os.system(f'type "in.txt" | {cmd} >out.txt')
else: # posix
os.system(f'cat in.txt | {cmd} > out.txt')
self.assertContained('abcdef\nghijkl\neof', read_file('out.txt'))

self.emcc(test_file('module/test_stdin.c'), output_filename='out.js')
def test_stdin(self, args):
create_file('in.txt', 'abcdef\nghijkl')
run_test()
self.emcc(test_file('module/test_stdin.c'),
['-O2', '--closure=1'], output_filename='out.js')
run_test()
self.emcc(test_file('module/test_stdin.c'), args=args, output_filename='out.js')

for engine in config.JS_ENGINES:
if engine == config.V8_ENGINE:
continue # no stdin support in v8 shell
engine[0] = os.path.normpath(engine[0])
print(engine, file=sys.stderr)
# work around a bug in python's subprocess module
# (we'd use self.run_js() normally)
delete_file('out.txt')
cmd = jsrun.make_command(os.path.normpath('out.js'), engine)
cmd = shared.shlex_join(cmd)
if WINDOWS:
os.system(f'type "in.txt" | {cmd} >out.txt')
else: # posix
os.system(f'cat in.txt | {cmd} > out.txt')
self.assertContained('abcdef\nghijkl\neof', read_file('out.txt'))

def test_ungetc_fscanf(self):
create_file('main.c', r'''
Expand Down

0 comments on commit a488fca

Please sign in to comment.