Skip to content

Commit 8c49036

Browse files
authored
Move test_modularize_instance into test_core.py. NFC (#24074)
Move this test alongside its peer (test_esm_integration). These are the only tests we have for these modes and its useful to be able to test other modes such as wasm64.
1 parent 9d408b0 commit 8c49036

File tree

2 files changed

+32
-31
lines changed

2 files changed

+32
-31
lines changed

test/test_core.py

+32
Original file line numberDiff line numberDiff line change
@@ -9577,6 +9577,38 @@ def test_esm_integration(self):
95779577
self.assertContained('hello, world! (3)', self.run_js('runner.mjs'))
95789578
self.assertFileContents(test_file('core/test_esm_integration.expected.mjs'), read_file('hello_world.mjs'))
95799579

9580+
@parameterized({
9581+
'': ([],),
9582+
'pthreads': (['-pthread'],),
9583+
})
9584+
def test_modularize_instance(self, args):
9585+
create_file('library.js', '''\
9586+
addToLibrary({
9587+
$baz: () => console.log('baz'),
9588+
$qux: () => console.log('qux'),
9589+
});''')
9590+
self.run_process([EMCC, test_file('modularize_instance.c'),
9591+
'-sMODULARIZE=instance',
9592+
'-Wno-experimental',
9593+
'-sEXPORTED_RUNTIME_METHODS=baz,addOnExit',
9594+
'-sEXPORTED_FUNCTIONS=_bar,_main,qux',
9595+
'--js-library', 'library.js',
9596+
'-o', 'modularize_instance.mjs'] + args)
9597+
9598+
create_file('runner.mjs', '''
9599+
import { strict as assert } from 'assert';
9600+
import init, { _foo as foo, _bar as bar, baz, qux, addOnExit, HEAP32 } from "./modularize_instance.mjs";
9601+
await init();
9602+
foo(); // exported with EMSCRIPTEN_KEEPALIVE
9603+
bar(); // exported with EXPORTED_FUNCTIONS
9604+
baz(); // exported library function with EXPORTED_RUNTIME_METHODS
9605+
qux(); // exported library function with EXPORTED_FUNCTIONS
9606+
assert(typeof addOnExit === 'function'); // exported runtime function with EXPORTED_RUNTIME_METHODS
9607+
assert(typeof HEAP32 === 'object'); // exported runtime value by default
9608+
''')
9609+
9610+
self.assertContained('main1\nmain2\nfoo\nbar\nbaz\n', self.run_js('runner.mjs'))
9611+
95809612

95819613
# Generate tests for everything
95829614
def make_run(name, emcc_args, settings=None, env=None,

test/test_other.py

-31
Original file line numberDiff line numberDiff line change
@@ -411,37 +411,6 @@ def test_esm_requires_modularize(self):
411411
err = self.expect_fail([EMCC, test_file('hello_world.c'), '-sEXPORT_ES6', '-sMODULARIZE=0'])
412412
self.assertContained('EXPORT_ES6 requires MODULARIZE to be set', err)
413413

414-
@parameterized({
415-
'': ([],),
416-
'pthreads': (['-pthread'],),
417-
})
418-
def test_modularize_instance(self, args):
419-
create_file('library.js', '''\
420-
addToLibrary({
421-
$baz: () => console.log('baz'),
422-
$qux: () => console.log('qux'),
423-
});''')
424-
self.run_process([EMCC, test_file('modularize_instance.c'),
425-
'-sMODULARIZE=instance',
426-
'-sEXPORTED_RUNTIME_METHODS=baz,addOnExit',
427-
'-sEXPORTED_FUNCTIONS=_bar,_main,qux',
428-
'--js-library', 'library.js',
429-
'-o', 'modularize_instance.mjs'] + args)
430-
431-
create_file('runner.mjs', '''
432-
import { strict as assert } from 'assert';
433-
import init, { _foo as foo, _bar as bar, baz, qux, addOnExit, HEAP32 } from "./modularize_instance.mjs";
434-
await init();
435-
foo(); // exported with EMSCRIPTEN_KEEPALIVE
436-
bar(); // exported with EXPORTED_FUNCTIONS
437-
baz(); // exported library function with EXPORTED_RUNTIME_METHODS
438-
qux(); // exported library function with EXPORTED_FUNCTIONS
439-
assert(typeof addOnExit === 'function'); // exported runtime function with EXPORTED_RUNTIME_METHODS
440-
assert(typeof HEAP32 === 'object'); // exported runtime value by default
441-
''')
442-
443-
self.assertContained('main1\nmain2\nfoo\nbar\nbaz\n', self.run_js('runner.mjs'))
444-
445414
def test_emcc_out_file(self):
446415
# Verify that "-ofile" works in addition to "-o" "file"
447416
self.run_process([EMCC, '-c', '-ofoo.o', test_file('hello_world.c')])

0 commit comments

Comments
 (0)