Skip to content

Commit 27fbd31

Browse files
authored
[test] Avoid reusing a.mjs for all js tests. (#7534)
Instead create `<filename>.mjs` named after each test. Test output now looks like this: ``` $ ./check.py --binaryen-bin=emcc-build/bin binaryenjs_wasm warning: Binaryen not found (or has not been successfully built to bin/ ? executing: /usr/bin/node -e process.stdout.write(typeof WebAssembly) [ checking binaryen.js testcases (/usr/local/google/home/sbc/dev/wasm/binaryen/emcc-build/bin/binaryen_wasm.js)... ] executing: /usr/bin/node atomics.mjs executing: /usr/bin/node closed-world.mjs executing: /usr/bin/node copy-expression.mjs executing: /usr/bin/node custom-section.mjs ... ``` Previously: ``` $ ./check.py --binaryen-bin=emcc-build/bin binaryenjs_wasm warning: Binaryen not found (or has not been successfully built to bin/ ? executing: /usr/bin/node -e process.stdout.write(typeof WebAssembly) [ checking binaryen.js testcases (/usr/local/google/home/sbc/dev/wasm/binaryen/emcc-build/bin/binaryen_wasm.js)... ] atomics.js executing: /usr/bin/node a.mjs closed-world.js executing: /usr/bin/node a.mjs copy-expression.js executing: /usr/bin/node a.mjs custom-section.js executing: /usr/bin/node a.mjs debug-info.js executing: /usr/bin/node a.mjs debug-names.js executing: /usr/bin/node a.mjs emit_asmjs.js ... ```
1 parent fb3c6e2 commit 27fbd31

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

scripts/test/binaryenjs.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,15 @@ def do_test_binaryen_js_with(which):
2929

3030
print('\n[ checking binaryen.js testcases (' + which + ')... ]\n')
3131

32-
for s in sorted(os.listdir(os.path.join(shared.options.binaryen_test, 'binaryen.js'))):
33-
if not s.endswith('.js'):
34-
continue
35-
print(s)
36-
f = open('a.mjs', 'w')
32+
for s in shared.get_tests(shared.get_test_dir('binaryen.js'), ['.js']):
33+
basename = os.path.basename(s)
34+
outname = os.path.splitext(basename)[0] + '.mjs'
35+
f = open(outname, 'w')
3736
# avoid stdout/stderr ordering issues in some js shells - use just stdout
38-
f.write('''
39-
console.warn = console.error = console.log;
40-
''')
37+
f.write('console.warn = console.error = console.log;')
4138
binaryen_js = open(which).read()
4239
f.write(binaryen_js)
43-
test_path = os.path.join(shared.options.binaryen_test, 'binaryen.js', s)
44-
test_src = open(test_path).read()
40+
test_src = open(s).read()
4541
f.write(support.js_test_wrap().replace('%TEST%', test_src))
4642
f.close()
4743

@@ -57,12 +53,12 @@ def test(cmd):
5753

5854
# run in all possible shells
5955
if shared.MOZJS:
60-
test([shared.MOZJS, '-m', 'a.mjs'])
56+
test([shared.MOZJS, '-m', outname])
6157
if shared.NODEJS:
6258
if node_has_wasm or 'WebAssembly.' not in test_src:
63-
test([shared.NODEJS, 'a.mjs'])
59+
test([shared.NODEJS, outname])
6460
else:
65-
print('Skipping ' + test_path + ' because WebAssembly might not be supported')
61+
print('Skipping ' + basename + ' because WebAssembly might not be supported')
6662

6763

6864
def update_binaryen_js_tests():
@@ -78,12 +74,10 @@ def update_binaryen_js_tests():
7874
node_has_wasm = shared.NODEJS and support.node_has_webassembly(shared.NODEJS)
7975
for s in shared.get_tests(shared.get_test_dir('binaryen.js'), ['.js']):
8076
basename = os.path.basename(s)
81-
print(basename)
82-
f = open('a.mjs', 'w')
77+
outname = os.path.splitext(basename)[0] + '.mjs'
78+
f = open(outname, 'w')
8379
# avoid stdout/stderr ordering issues in some js shells - use just stdout
84-
f.write('''
85-
console.warn = console.error = console.log;
86-
''')
80+
f.write('console.warn = console.error = console.log;')
8781
f.write(open(shared.BINARYEN_JS).read())
8882
test_src = open(s).read()
8983
f.write(support.js_test_wrap().replace('%TEST%', test_src))
@@ -100,9 +94,9 @@ def update(cmd):
10094

10195
# run in available shell
10296
if shared.MOZJS:
103-
update([shared.MOZJS, '-m', 'a.mjs'])
97+
update([shared.MOZJS, '-m', outname])
10498
elif node_has_wasm or 'WebAssembly.' not in test_src:
105-
update([shared.NODEJS, 'a.mjs'])
99+
update([shared.NODEJS, outname])
106100
else:
107101
print('Skipping ' + basename + ' because WebAssembly might not be supported')
108102

0 commit comments

Comments
 (0)