|
16 | 16 |
|
17 | 17 | import os |
18 | 18 |
|
19 | | -from support import run_command |
| 19 | +from support import run_command, split_wast |
20 | 20 | from shared import ( |
21 | 21 | WASM2JS, MOZJS, NODEJS, fail_if_not_identical, options, tests, |
22 | 22 | fail_if_not_identical_to_file |
@@ -51,36 +51,46 @@ def test_wasm2js_output(): |
51 | 51 |
|
52 | 52 | print '..', wasm |
53 | 53 |
|
54 | | - cmd = WASM2JS + [os.path.join(options.binaryen_test, wasm)] |
55 | | - if 'emscripten' in wasm: |
56 | | - cmd += ['--emscripten'] |
57 | | - out = run_command(cmd) |
58 | | - fail_if_not_identical_to_file(out, expected_file) |
| 54 | + t = os.path.join(options.binaryen_test, wasm) |
59 | 55 |
|
60 | | - if not NODEJS and not MOZJS: |
61 | | - print 'No JS interpreters. Skipping spec tests.' |
62 | | - continue |
| 56 | + all_out = [] |
63 | 57 |
|
64 | | - open('a.2asm.mjs', 'w').write(out) |
| 58 | + for module, asserts in split_wast(t): |
| 59 | + with open('split.wast', 'w') as o: |
| 60 | + o.write(module + '\n'.join(asserts)) |
65 | 61 |
|
66 | | - cmd += ['--allow-asserts'] |
67 | | - out = run_command(cmd) |
| 62 | + cmd = WASM2JS + ['split.wast'] |
| 63 | + if 'emscripten' in wasm: |
| 64 | + cmd += ['--emscripten'] |
| 65 | + out = run_command(cmd) |
| 66 | + all_out.append(out) |
68 | 67 |
|
69 | | - open('a.2asm.asserts.mjs', 'w').write(out) |
| 68 | + if not NODEJS and not MOZJS: |
| 69 | + print 'No JS interpreters. Skipping spec tests.' |
| 70 | + continue |
70 | 71 |
|
71 | | - # verify asm.js is valid js, note that we're using --experimental-modules |
72 | | - # to enable ESM syntax and we're also passing a custom loader to handle the |
73 | | - # `spectest` module in our tests. |
74 | | - if NODEJS: |
75 | | - node = [NODEJS, '--experimental-modules', '--loader', './scripts/test/node-esm-loader.mjs'] |
76 | | - cmd = node[:] |
77 | | - cmd.append('a.2asm.mjs') |
| 72 | + open('a.2asm.mjs', 'w').write(out) |
| 73 | + |
| 74 | + cmd += ['--allow-asserts'] |
78 | 75 | out = run_command(cmd) |
79 | | - fail_if_not_identical(out, '') |
80 | | - cmd = node[:] |
81 | | - cmd.append('a.2asm.asserts.mjs') |
82 | | - out = run_command(cmd, expected_err='', err_ignore='The ESM module loader is experimental') |
83 | | - fail_if_not_identical(out, '') |
| 76 | + |
| 77 | + open('a.2asm.asserts.mjs', 'w').write(out) |
| 78 | + |
| 79 | + # verify asm.js is valid js, note that we're using --experimental-modules |
| 80 | + # to enable ESM syntax and we're also passing a custom loader to handle the |
| 81 | + # `spectest` and `env` modules in our tests. |
| 82 | + if NODEJS: |
| 83 | + node = [NODEJS, '--experimental-modules', '--loader', './scripts/test/node-esm-loader.mjs'] |
| 84 | + cmd = node[:] |
| 85 | + cmd.append('a.2asm.mjs') |
| 86 | + out = run_command(cmd) |
| 87 | + fail_if_not_identical(out, '') |
| 88 | + cmd = node[:] |
| 89 | + cmd.append('a.2asm.asserts.mjs') |
| 90 | + out = run_command(cmd, expected_err='', err_ignore='The ESM module loader is experimental') |
| 91 | + fail_if_not_identical(out, '') |
| 92 | + |
| 93 | + fail_if_not_identical_to_file(''.join(all_out), expected_file) |
84 | 94 |
|
85 | 95 |
|
86 | 96 | def test_asserts_output(): |
@@ -130,12 +140,22 @@ def update_wasm2js_tests(): |
130 | 140 |
|
131 | 141 | print '..', wasm |
132 | 142 |
|
133 | | - cmd = WASM2JS + [os.path.join('test', wasm)] |
134 | | - if 'emscripten' in wasm: |
135 | | - cmd += ['--emscripten'] |
136 | | - out = run_command(cmd) |
| 143 | + t = os.path.join(options.binaryen_test, wasm) |
| 144 | + |
| 145 | + all_out = [] |
| 146 | + |
| 147 | + for module, asserts in split_wast(t): |
| 148 | + with open('split.wast', 'w') as o: |
| 149 | + o.write(module + '\n'.join(asserts)) |
| 150 | + |
| 151 | + cmd = WASM2JS + ['split.wast'] |
| 152 | + if 'emscripten' in wasm: |
| 153 | + cmd += ['--emscripten'] |
| 154 | + out = run_command(cmd) |
| 155 | + all_out.append(out) |
| 156 | + |
137 | 157 | with open(expected_file, 'w') as o: |
138 | | - o.write(out) |
| 158 | + o.write(''.join(all_out)) |
139 | 159 |
|
140 | 160 | for wasm in assert_tests: |
141 | 161 | print '..', wasm |
|
0 commit comments