@@ -2340,13 +2340,6 @@ def test_dylink_LEGACY_GL_EMULATION(self):
23402340 self.do_runf('test.c', 'done\n', emcc_args=['-sLEGACY_GL_EMULATION', '-sMAIN_MODULE=2'])
23412341
23422342 def test_js_link(self):
2343- create_file('main.c', '''
2344- #include <stdio.h>
2345- int main() {
2346- printf("hello from main\\n");
2347- return 0;
2348- }
2349- ''')
23502343 create_file('before.js', '''
23512344 var MESSAGE = 'hello from js';
23522345 // Module is initialized with empty object by default, so if there are no keys - nothing was run yet
@@ -2356,7 +2349,7 @@ def test_js_link(self):
23562349 out(MESSAGE);
23572350 ''')
23582351
2359- self.do_runf('main .c', 'hello from main \nhello from js\n',
2352+ self.do_runf(test_file('hello_world .c') , 'hello, world! \nhello from js\n',
23602353 emcc_args=['--pre-js', 'before.js', '--post-js', 'after.js', '-sWASM_ASYNC_COMPILATION=0'])
23612354
23622355 def test_sdl_none(self):
@@ -2719,97 +2712,79 @@ def test_get_proc_address_error_message(self):
27192712 err = self.expect_fail([EMCC, '-sGL_ENABLE_GET_PROC_ADDRESS=0', test_file('other/test_GetProcAddress_LEGACY_GL_EMULATION.c')])
27202713 self.assertContained('error: linker: Undefined symbol: SDL_GL_GetProcAddress(). Please pass -sGL_ENABLE_GET_PROC_ADDRESS at link time to link in SDL_GL_GetProcAddress().', err)
27212714
2722- def test_prepost(self):
2723- create_file('main.c', '''
2724- #include <stdio.h>
2725- int main() {
2726- printf("hello from main\\n");
2727- return 0;
2728- }
2729- ''')
2715+ @parameterized({
2716+ '': (False, False),
2717+ 'no_initial_run': (True, False),
2718+ 'run_dep': (False, True),
2719+ })
2720+ def test_prepost(self, no_initial_run, run_dep):
27302721 create_file('pre.js', '''
27312722 var Module = {
27322723 preRun: () => out('pre-run'),
27332724 postRun: () => out('post-run')
27342725 };
27352726 ''')
27362727
2737- self.run_process([EMCC, 'main .c', '--pre-js', 'pre.js', '-sWASM_ASYNC_COMPILATION=0'])
2738- self.assertContained('pre-run\nhello from main \npost-run\n', self.run_js('a.out.js'))
2728+ self.run_process([EMCC, test_file('hello_world .c') , '--pre-js', 'pre.js', '-sWASM_ASYNC_COMPILATION=0'])
2729+ self.assertContained('pre-run\nhello, world! \npost-run\n', self.run_js('a.out.js'))
27392730
27402731 # addRunDependency during preRun should prevent main, and post-run from
27412732 # running.
27422733 with open('pre.js', 'a') as f:
27432734 f.write('Module.preRun = () => { out("add-dep"); addRunDependency(); }\n')
2744- self.run_process([EMCC, 'main .c', '--pre-js', 'pre.js', '-sWASM_ASYNC_COMPILATION=0'])
2735+ self.run_process([EMCC, test_file('hello_world .c') , '--pre-js', 'pre.js', '-sWASM_ASYNC_COMPILATION=0'])
27452736 output = self.run_js('a.out.js')
27462737 self.assertContained('add-dep\n', output)
2747- self.assertNotContained('hello from main \n', output)
2738+ self.assertNotContained('hello, world! \n', output)
27482739 self.assertNotContained('post-run\n', output)
27492740
27502741 # noInitialRun prevents run
2751- for no_initial_run, run_dep in ((0, 0), (1, 0), (0, 1)):
2752- print(no_initial_run, run_dep)
2753- args = ['-sWASM_ASYNC_COMPILATION=0', '-sEXPORTED_RUNTIME_METHODS=callMain']
2754- if no_initial_run:
2755- args += ['-sINVOKE_RUN=0']
2756- if run_dep:
2757- create_file('pre.js', 'Module.preRun = () => addRunDependency("test");')
2758- create_file('post.js', 'removeRunDependency("test");')
2759- args += ['--pre-js', 'pre.js', '--post-js', 'post.js']
2760-
2761- self.run_process([EMCC, 'main.c'] + args)
2762- output = self.run_js('a.out.js')
2763- self.assertContainedIf('hello from main', output, not no_initial_run)
2742+ args = ['-sWASM_ASYNC_COMPILATION=0', '-sEXPORTED_RUNTIME_METHODS=callMain']
2743+ if no_initial_run:
2744+ args += ['-sINVOKE_RUN=0']
2745+ if run_dep:
2746+ create_file('pre.js', 'Module.preRun = () => addRunDependency("test");')
2747+ create_file('post.js', 'removeRunDependency("test");')
2748+ args += ['--pre-js', 'pre.js', '--post-js', 'post.js']
27642749
2765- if no_initial_run:
2766- # Calling main later should still work, filesystem etc. must be set up.
2767- print('call main later')
2768- src = read_file('a.out.js')
2769- src += '\nout("callMain -> " + Module.callMain());\n'
2770- create_file('a.out.js', src)
2771- self.assertContained('hello from main\ncallMain -> 0\n', self.run_js('a.out.js'))
2750+ self.run_process([EMCC, test_file('hello_world.c')] + args)
2751+ output = self.run_js('a.out.js')
2752+ self.assertContainedIf('hello, world!', output, not no_initial_run)
2753+
2754+ if no_initial_run:
2755+ # Calling main later should still work, filesystem etc. must be set up.
2756+ print('call main later')
2757+ src = read_file('a.out.js')
2758+ src += '\nout("callMain -> " + Module.callMain());\n'
2759+ create_file('a.out.js', src)
2760+ self.assertContained('hello, world!\ncallMain -> 0\n', self.run_js('a.out.js'))
27722761
2773- # Use postInit
2762+ def test_preinit(self):
27742763 create_file('pre.js', '''
27752764 var Module = {
27762765 preRun: () => out('pre-run'),
27772766 postRun: () => out('post-run'),
27782767 preInit: () => out('pre-init')
27792768 };
27802769 ''')
2781- self.do_runf('main .c',
2782- 'pre-init\npre-run\nhello from main \npost-run\n',
2770+ self.do_runf(test_file('hello_world .c') ,
2771+ 'pre-init\npre-run\nhello, world! \npost-run\n',
27832772 emcc_args=['--pre-js', 'pre.js'])
27842773
27852774 def test_prepost2(self):
2786- create_file('main.c', '''
2787- #include <stdio.h>
2788- int main() {
2789- printf("hello from main\\n");
2790- return 0;
2791- }
2792- ''')
27932775 create_file('pre.js', 'Module.preRun = () => out("pre-run");')
27942776 create_file('pre2.js', 'Module.postRun = () => out("post-run");')
2795- self.do_runf('main .c', 'pre-run\nhello from main \npost-run\n',
2777+ self.do_runf(test_file('hello_world .c') , 'pre-run\nhello, world! \npost-run\n',
27962778 emcc_args=['--pre-js', 'pre.js', '--pre-js', 'pre2.js'])
27972779
27982780 def test_prepre(self):
2799- create_file('main.c', '''
2800- #include <stdio.h>
2801- int main() {
2802- printf("hello from main\\n");
2803- return 0;
2804- }
2805- ''')
28062781 create_file('pre.js', '''
28072782 Module.preRun = [() => out('pre-run')];
28082783 ''')
28092784 create_file('pre2.js', '''
28102785 Module.preRun.push(() => out('prepre'));
28112786 ''')
2812- self.do_runf('main .c', 'prepre\npre-run\nhello from main \n',
2787+ self.do_runf(test_file('hello_world .c') , 'prepre\npre-run\nhello, world! \n',
28132788 emcc_args=['--pre-js', 'pre.js', '--pre-js', 'pre2.js'])
28142789
28152790 def test_extern_prepost(self):
0 commit comments