Skip to content

Commit 51ff47f

Browse files
authored
Cleanup other.test_single_file. NFC (#21738)
- Use `also_with_wasm2js` decorator - Peel one of the loop variables and implement it as @parameterize instead.
1 parent 9b67335 commit 51ff47f

File tree

3 files changed

+36
-34
lines changed

3 files changed

+36
-34
lines changed

test/common.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,23 @@ def metafunc(self, with_wasm64, *args, **kwargs):
440440
return metafunc
441441

442442

443+
def also_with_wasm2js(f):
444+
assert callable(f)
445+
446+
def metafunc(self, with_wasm2js, *args, **kwargs):
447+
assert self.get_setting('WASM') is None
448+
if with_wasm2js:
449+
self.require_wasm2js()
450+
self.set_setting('WASM', 0)
451+
f(self, *args, **kwargs)
452+
else:
453+
f(self, *args, **kwargs)
454+
455+
metafunc._parameterize = {'': (False,),
456+
'wasm2js': (True,)}
457+
return metafunc
458+
459+
443460
def can_do_standalone(self, impure=False):
444461
# Pure standalone engines don't support MEMORY64 yet. Even with MEMORY64=2 (lowered)
445462
# the WASI APIs that take pointer values don't have 64-bit variants yet.

test/test_browser.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from common import BrowserCore, RunnerCore, path_from_root, has_browser, EMTEST_BROWSER, Reporting
2424
from common import create_file, parameterized, ensure_dir, disabled, test_file, WEBIDL_BINDER
2525
from common import read_file, also_with_minimal_runtime, EMRUN, no_wasm64, no_2gb, no_4gb
26-
from common import requires_wasm2js
26+
from common import requires_wasm2js, also_with_wasm2js
2727
from tools import shared
2828
from tools import ports
2929
from tools import utils
@@ -113,23 +113,6 @@ def decorated(self, *args, **kwargs):
113113
return decorator
114114

115115

116-
def also_with_wasm2js(f):
117-
assert callable(f)
118-
119-
def metafunc(self, with_wasm2js, *args, **kwargs):
120-
assert self.get_setting('WASM') is None
121-
if with_wasm2js:
122-
self.require_wasm2js()
123-
self.set_setting('WASM', 0)
124-
f(self, *args, **kwargs)
125-
else:
126-
f(self, *args, **kwargs)
127-
128-
metafunc._parameterize = {'': (False,),
129-
'wasm2js': (True,)}
130-
return metafunc
131-
132-
133116
def shell_with_script(shell_file, output_file, replacement):
134117
shell = read_file(path_from_root('src', shell_file))
135118
create_file(output_file, shell.replace('{{{ SCRIPT }}}', replacement))

test/test_other.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from common import create_file, parameterized, NON_ZERO, node_pthreads, TEST_ROOT, test_file
3636
from common import compiler_for, EMBUILDER, requires_v8, requires_node, requires_wasm64, requires_node_canary
3737
from common import requires_wasm_eh, crossplatform, with_both_eh_sjlj, with_both_sjlj
38-
from common import also_with_standalone_wasm, also_with_env_modify
38+
from common import also_with_standalone_wasm, also_with_env_modify, also_with_wasm2js
3939
from common import also_with_minimal_runtime, also_with_wasm_bigint, also_with_wasm64, flaky
4040
from common import EMTEST_BUILD_VERBOSE, PYTHON, WEBIDL_BINDER
4141
from common import requires_network
@@ -9091,39 +9091,41 @@ def test_standalone_system_headers(self):
90919091

90929092
@is_slow_test
90939093
@parameterized({
9094-
'': (False,),
9095-
'wasm2js': (True,),
9094+
'': (True,),
9095+
'disabled': (False,),
90969096
})
9097-
def test_single_file(self, wasm2js):
9098-
for (single_file_enabled,
9099-
debug_enabled,
9100-
closure_enabled) in itertools.product([True, False], repeat=3):
9097+
@also_with_wasm2js
9098+
def test_single_file(self, single_file_enabled):
9099+
for (debug_enabled,
9100+
closure_enabled) in itertools.product([True, False], repeat=2):
91019101
# skip unhelpful option combinations
91029102
if closure_enabled and debug_enabled:
91039103
continue
91049104

9105-
expect_wasm = not wasm2js
9106-
9107-
cmd = [EMCC, test_file('hello_world.c')]
9105+
cmd = [EMCC, test_file('hello_world.c')] + self.get_emcc_args()
91089106

91099107
if single_file_enabled:
91109108
expect_wasm = False
91119109
cmd += ['-sSINGLE_FILE']
9110+
else:
9111+
expect_wasm = self.is_wasm()
9112+
91129113
if debug_enabled:
91139114
cmd += ['-g']
91149115
if closure_enabled:
9115-
cmd += ['--closure=1']
9116-
if wasm2js:
9117-
cmd += ['-sWASM=0']
9116+
cmd += ['--closure=1', '-Wno-closure']
91189117

91199118
self.clear()
91209119

91219120
def do_test(cmd):
91229121
print(' '.join(cmd))
91239122
self.run_process(cmd)
91249123
print(os.listdir('.'))
9125-
assert expect_wasm == os.path.exists('a.out.wasm')
9126-
assert not os.path.exists('a.out.wat')
9124+
if expect_wasm:
9125+
self.assertExists('a.out.wasm')
9126+
else:
9127+
self.assertNotExists('a.out.wasm')
9128+
self.assertNotExists('a.out.wat')
91279129
self.assertContained('hello, world!', self.run_js('a.out.js'))
91289130

91299131
do_test(cmd)
@@ -9132,7 +9134,7 @@ def do_test(cmd):
91329134

91339135
if debug_enabled:
91349136
separate_dwarf_cmd = cmd + ['-gseparate-dwarf']
9135-
if wasm2js:
9137+
if self.is_wasm2js():
91369138
self.expect_fail(separate_dwarf_cmd)
91379139
else:
91389140
do_test(separate_dwarf_cmd)

0 commit comments

Comments
 (0)