Skip to content

Commit ee483fc

Browse files
authored
test_other: use self.do_runf where it makes sense. NFC. (#13275)
1 parent 540d3ba commit ee483fc

File tree

2 files changed

+27
-40
lines changed

2 files changed

+27
-40
lines changed

tests/runner.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -569,9 +569,11 @@ def build(self, filename, libraries=[], includes=[], force_c=False,
569569

570570
dirname, basename = os.path.split(filename)
571571
output = shared.unsuffixed(basename) + suffix
572-
cmd = compiler + [filename, '-o', output, '-I.'] + self.get_emcc_args(main_file=True) + \
573-
['-I' + include for include in includes] + \
574-
libraries
572+
cmd = compiler + [filename, '-o', output] + self.get_emcc_args(main_file=True) + libraries
573+
if shared.suffix(filename) not in ('.i', '.ii'):
574+
# Add the location of the test file to include path.
575+
cmd += ['-I.']
576+
cmd += ['-I' + include for include in includes]
575577

576578
self.run_process(cmd, stderr=self.stderr_redirect if not DEBUG else None)
577579
self.assertExists(output)

tests/test_other.py

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -702,8 +702,7 @@ def test_preprocessed_input(self):
702702
#endif
703703
int main() { puts("hello"); }
704704
''')
705-
self.run_process([EMCC, 'simple' + suffix])
706-
self.assertContained('hello', self.run_js('a.out.js'))
705+
self.do_runf('simple' + suffix, 'hello')
707706

708707
create_test_file('with_include' + suffix, '#include <stdio.h>\nint main() { puts("hello"); }')
709708
err = self.expect_fail([EMCC, 'with_include' + suffix])
@@ -3770,12 +3769,9 @@ def test_stat_silly(self):
37703769
}
37713770
}
37723771
''')
3773-
self.run_process([EMCC, 'src.cpp'])
3774-
3775-
# cannot stat ""
3776-
self.assertContained(r'''Failed to stat path: /a; errno=44
3772+
self.do_runf('src.cpp', r'''Failed to stat path: /a; errno=44
37773773
Failed to stat path: ; errno=44
3778-
''', self.run_js('a.out.js', args=['/a', '']))
3774+
''', args=['/a', ''])
37793775

37803776
def test_symlink_silly(self):
37813777
create_test_file('src.cpp', r'''
@@ -3936,10 +3932,8 @@ def test_readdir_r_silly(self):
39363932
return 0;
39373933
}
39383934
''')
3939-
self.run_process([EMCC, 'src.cpp'])
3940-
39413935
# cannot symlink nonexistents
3942-
self.assertContained(r'''Before:
3936+
self.do_runf('src.cpp', r'''Before:
39433937
dir
39443938
a
39453939
b
@@ -3954,7 +3948,7 @@ def test_readdir_r_silly(self):
39543948
Unlinking e
39553949
After:
39563950
dir
3957-
''', self.run_js('a.out.js', args=['', 'abc']))
3951+
''', args=['', 'abc'])
39583952

39593953
def test_emversion(self):
39603954
create_test_file('src.cpp', r'''
@@ -4287,8 +4281,7 @@ def test_strftime_zZ(self):
42874281
self.assertContained('ok!', self.run_js('a.out.js'))
42884282

42894283
def test_strptime_symmetry(self):
4290-
building.emcc(path_from_root('tests', 'strptime_symmetry.cpp'), output_filename='a.out.js')
4291-
self.assertContained('TEST PASSED', self.run_js('a.out.js'))
4284+
self.do_runf(path_from_root('tests', 'strptime_symmetry.cpp'), 'TEST PASSED')
42924285

42934286
def test_truncate_from_0(self):
42944287
create_test_file('src.cpp', r'''
@@ -4393,8 +4386,7 @@ def test_truncate_from_0(self):
43934386
return 0;
43944387
}
43954388
''')
4396-
self.run_process([EMCC, 'src.cpp'])
4397-
self.assertContained(r'''Creating file: /tmp/file with content=This is some content
4389+
self.do_runf('src.cpp', r'''Creating file: /tmp/file with content=This is some content
43984390
Size of file is: 20
43994391
Truncating file=/tmp/file to length=32
44004392
Size of file is: 32
@@ -4404,7 +4396,7 @@ def test_truncate_from_0(self):
44044396
Size of file is: 0
44054397
Truncating file=/tmp/file to length=32
44064398
Size of file is: 32
4407-
''', self.run_js('a.out.js'))
4399+
''')
44084400

44094401
def test_create_readonly(self):
44104402
create_test_file('src.cpp', r'''
@@ -4475,12 +4467,11 @@ def test_create_readonly(self):
44754467
"exists and is read-only.\n\n");
44764468
}
44774469
''')
4478-
self.run_process([EMCC, 'src.cpp'])
4479-
self.assertContained(r'''Creating file: /tmp/file with content of size=292
4470+
self.do_runf('src.cpp', r'''Creating file: /tmp/file with content of size=292
44804471
Data written to file=/tmp/file; successfully wrote 292 bytes
44814472
Creating file: /tmp/file with content of size=79
44824473
Failed to open file for writing: /tmp/file; errno=2; Permission denied
4483-
''', self.run_js('a.out.js'))
4474+
''')
44844475

44854476
def test_embed_file_large(self):
44864477
# If such long files are encoded on one line,
@@ -4569,9 +4560,8 @@ def test_browser_language_detection(self):
45694560
# Accept-Language: fr-FR,fr;q=0.8,en-US;q=0.5,en;q=0.3
45704561
create_test_file('preamble.js', r'''navigator = {};
45714562
navigator.languages = [ "fr-FR", "fr", "en-US", "en" ];''')
4572-
self.run_process([EMCC, '--pre-js', 'preamble.js',
4573-
path_from_root('tests', 'test_browser_language_detection.c')])
4574-
self.assertContained('fr_FR.UTF-8', self.run_js('a.out.js'))
4563+
self.emcc_args += ['--pre-js', 'preamble.js']
4564+
self.do_runf(path_from_root('tests', 'test_browser_language_detection.c'), 'fr_FR.UTF-8')
45754565

45764566
def test_js_main(self):
45774567
# try to add a main() from JS, at runtime. this is not supported (the
@@ -4583,9 +4573,8 @@ def test_js_main(self):
45834573
};
45844574
''')
45854575
create_test_file('src.cpp', '')
4586-
self.run_process([EMCC, 'src.cpp', '--pre-js', 'pre_main.js'])
4587-
self.assertContained('compiled without a main, but one is present. if you added it from JS, use Module["onRuntimeInitialized"]',
4588-
self.run_js('a.out.js', assert_returncode=NON_ZERO))
4576+
self.emcc_args += ['--pre-js', 'pre_main.js']
4577+
self.do_runf('src.cpp', 'compiled without a main, but one is present. if you added it from JS, use Module["onRuntimeInitialized"]', assert_returncode=NON_ZERO)
45894578

45904579
def test_locale_wrong(self):
45914580
create_test_file('src.cpp', r'''
@@ -4676,8 +4665,8 @@ def test_no_filesystem(self):
46764665
self.assertLess(no_size, 360000)
46774666

46784667
def test_no_filesystem_libcxx(self):
4679-
self.run_process([EMCC, path_from_root('tests', 'hello_libcxx.cpp'), '-s', 'FILESYSTEM=0'])
4680-
self.assertContained('hello, world!', self.run_js('a.out.js'))
4668+
self.set_setting('FILESYSTEM', 0)
4669+
self.do_runf(path_from_root('tests', 'hello_libcxx.cpp'), 'hello, world!')
46814670

46824671
@is_slow_test
46834672
def test_no_nuthin(self):
@@ -4721,7 +4710,8 @@ def test_no_browser(self):
47214710
self.run_process([EMCC, path_from_root('tests', 'hello_world.c')])
47224711
self.assertNotContained(BROWSER_INIT, open('a.out.js').read())
47234712

4724-
self.run_process([EMCC, path_from_root('tests', 'browser_main_loop.c')]) # uses emscripten_set_main_loop, which needs Browser
4713+
# uses emscripten_set_main_loop, which needs Browser
4714+
self.run_process([EMCC, path_from_root('tests', 'browser_main_loop.c')])
47254715
self.assertContained(BROWSER_INIT, open('a.out.js').read())
47264716

47274717
def test_EXPORTED_RUNTIME_METHODS(self):
@@ -4797,8 +4787,7 @@ def test_stat_fail_alongtheway(self):
47974787
return fail;
47984788
}
47994789
''')
4800-
self.run_process([EMCC, 'src.cpp'])
4801-
self.assertContained(r'''pass: mkdir("path", 0777) == 0
4790+
self.do_runf('src.cpp', r'''pass: mkdir("path", 0777) == 0
48024791
pass: close(open("path/file", O_CREAT | O_WRONLY, 0644)) == 0
48034792
pass: stat("path", &st) == 0
48044793
pass: st.st_mode = 0777
@@ -4813,7 +4802,7 @@ def test_stat_fail_alongtheway(self):
48134802
pass: lstat("path/file/impossible", &st) == -1
48144803
info: errno=54 Not a directory
48154804
pass: error == ENOTDIR
4816-
''', self.run_js('a.out.js'))
4805+
''')
48174806

48184807
def test_link_with_a_static(self):
48194808
create_test_file('x.c', r'''
@@ -4953,7 +4942,6 @@ class Descriptor {
49534942
49544943
Descriptor desc;
49554944
''')
4956-
try_delete('a.out.js')
49574945
self.run_process([EMCC, 'src.cpp', '-O2', '-s', 'EXPORT_ALL'])
49584946
self.assertExists('a.out.js')
49594947

@@ -5002,10 +4990,10 @@ def test_sdl2_config(self):
50024990
]:
50034991
print(args, expected)
50044992
out = self.run_process([PYTHON, path_from_root('system', 'bin', 'sdl2-config')] + args, stdout=PIPE, stderr=PIPE).stdout
5005-
assert expected in out, out
4993+
self.assertContained(expected, out)
50064994
print('via emmake')
50074995
out = self.run_process([emmake, 'sdl2-config'] + args, stdout=PIPE, stderr=PIPE).stdout
5008-
assert expected in out, out
4996+
self.assertContained(expected, out)
50094997

50104998
def test_module_onexit(self):
50114999
create_test_file('src.cpp', r'''
@@ -5017,7 +5005,6 @@ def test_module_onexit(self):
50175005
return 14;
50185006
}
50195007
''')
5020-
try_delete('a.out.js')
50215008
self.run_process([EMCC, 'src.cpp', '-s', 'EXIT_RUNTIME'])
50225009
self.assertContained('exiting now, status 14', self.run_js('a.out.js', assert_returncode=14))
50235010

@@ -7553,11 +7540,9 @@ def test_check_source_map_args(self):
75537540
'profiling': ['--profiling'] # -g4 --profiling should still emit a source map; see #8584
75547541
})
75557542
def test_check_sourcemapurl_default(self, *args):
7556-
print(args)
75577543
if not self.is_wasm():
75587544
self.skipTest('only supported with wasm')
75597545

7560-
try_delete('a.wasm.map')
75617546
self.run_process([EMCC, path_from_root('tests', 'hello_123.c'), '-g4', '-o', 'a.js'] + list(args))
75627547
output = open('a.wasm', 'rb').read()
75637548
# has sourceMappingURL section content and points to 'a.wasm.map' file

0 commit comments

Comments
 (0)