Skip to content

Commit 249cf8c

Browse files
authored
Prefer C over C++ for simple compiler tests. NFC (#21002)
1 parent 7ae7165 commit 249cf8c

File tree

2 files changed

+46
-45
lines changed

2 files changed

+46
-45
lines changed

test/test_other.py

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2372,7 +2372,7 @@ def test_link_memcpy(self):
23722372
self.assertNotContained('warning: library.js memcpy should not be running, it is only for testing!', output)
23732373

23742374
def test_undefined_exported_function(self):
2375-
cmd = [EMXX, test_file('hello_world.cpp')]
2375+
cmd = [EMCC, test_file('hello_world.c')]
23762376
self.run_process(cmd)
23772377

23782378
# adding a missing symbol to EXPORTED_FUNCTIONS should cause failure
@@ -5357,19 +5357,19 @@ def test(args):
53575357

53585358
def test_dashE_respect_dashO(self):
53595359
# issue #3365
5360-
with_dash_o = self.run_process([EMXX, test_file('hello_world.cpp'), '-E', '-o', 'ignored.js'], stdout=PIPE, stderr=PIPE).stdout
5361-
without_dash_o = self.run_process([EMXX, test_file('hello_world.cpp'), '-E'], stdout=PIPE, stderr=PIPE).stdout
5360+
with_dash_o = self.run_process([EMCC, test_file('hello_world.c'), '-E', '-o', 'ignored.js'], stdout=PIPE, stderr=PIPE).stdout
5361+
without_dash_o = self.run_process([EMCC, test_file('hello_world.c'), '-E'], stdout=PIPE, stderr=PIPE).stdout
53625362
self.assertEqual(len(with_dash_o), 0)
53635363
self.assertNotEqual(len(without_dash_o), 0)
53645364

53655365
def test_dashM(self):
5366-
out = self.run_process([EMXX, test_file('hello_world.cpp'), '-M'], stdout=PIPE).stdout
5366+
out = self.run_process([EMCC, test_file('hello_world.c'), '-M'], stdout=PIPE).stdout
53675367
self.assertContained('hello_world.o:', out) # Verify output is just a dependency rule instead of bitcode or js
53685368

53695369
def test_dashM_respect_dashO(self):
53705370
# issue #3365
5371-
with_dash_o = self.run_process([EMXX, test_file('hello_world.cpp'), '-M', '-o', 'ignored.js'], stdout=PIPE).stdout
5372-
without_dash_o = self.run_process([EMXX, test_file('hello_world.cpp'), '-M'], stdout=PIPE).stdout
5371+
with_dash_o = self.run_process([EMCC, test_file('hello_world.c'), '-M', '-o', 'ignored.js'], stdout=PIPE).stdout
5372+
without_dash_o = self.run_process([EMCC, test_file('hello_world.c'), '-M'], stdout=PIPE).stdout
53735373
self.assertEqual(len(with_dash_o), 0)
53745374
self.assertNotEqual(len(without_dash_o), 0)
53755375

@@ -7607,42 +7607,42 @@ def test_dash_s_link_flag(self):
76077607
# its used to set a settings based on looking at the argument that follows.
76087608

76097609
# Test the case when -s is the last flag
7610-
self.run_process([EMXX, test_file('hello_world.cpp'), '-s'])
7610+
self.run_process([EMCC, test_file('hello_world.c'), '-s'])
76117611
self.assertContained('hello, world!', self.run_js('a.out.js'))
76127612

76137613
# Test the case when the following flag is all uppercase but starts with a `-`
7614-
self.run_process([EMXX, test_file('hello_world.cpp'), '-s', '-DFOO'])
7614+
self.run_process([EMCC, test_file('hello_world.c'), '-s', '-DFOO'])
76157615
self.assertContained('hello, world!', self.run_js('a.out.js'))
76167616

76177617
# Test that case when the following flag is not all uppercase
7618-
self.run_process([EMXX, '-s', test_file('hello_world.cpp')])
7618+
self.run_process([EMCC, '-s', test_file('hello_world.c')])
76197619
self.assertContained('hello, world!', self.run_js('a.out.js'))
76207620

76217621
def test_dash_s_response_file_string(self):
76227622
create_file('response_file.txt', 'MyModule\n')
76237623
create_file('response_file.json', '"MyModule"\n')
7624-
self.run_process([EMXX, test_file('hello_world.cpp'), '-sEXPORT_NAME=@response_file.txt'])
7625-
self.run_process([EMXX, test_file('hello_world.cpp'), '-sEXPORT_NAME=@response_file.json'])
7624+
self.run_process([EMCC, test_file('hello_world.c'), '-sEXPORT_NAME=@response_file.txt'])
7625+
self.run_process([EMCC, test_file('hello_world.c'), '-sEXPORT_NAME=@response_file.json'])
76267626

76277627
def test_dash_s_response_file_list(self):
76287628
create_file('response_file.txt', '_main\n_malloc\n')
76297629
create_file('response_file.json', '["_main", "_malloc"]\n')
7630-
self.run_process([EMXX, test_file('hello_world.cpp'), '-sEXPORTED_FUNCTIONS=@response_file.txt'])
7631-
self.run_process([EMXX, test_file('hello_world.cpp'), '-sEXPORTED_FUNCTIONS=@response_file.json'])
7630+
self.run_process([EMCC, test_file('hello_world.c'), '-sEXPORTED_FUNCTIONS=@response_file.txt'])
7631+
self.run_process([EMCC, test_file('hello_world.c'), '-sEXPORTED_FUNCTIONS=@response_file.json'])
76327632

76337633
def test_dash_s_response_file_misssing(self):
7634-
err = self.expect_fail([EMXX, test_file('hello_world.cpp'), '-sEXPORTED_FUNCTIONS=@foo'])
7634+
err = self.expect_fail([EMCC, test_file('hello_world.c'), '-sEXPORTED_FUNCTIONS=@foo'])
76357635
self.assertContained('error: foo: file not found parsing argument: EXPORTED_FUNCTIONS=@foo', err)
76367636

76377637
def test_dash_s_unclosed_quote(self):
76387638
# Unclosed quote
7639-
err = self.expect_fail([EMXX, test_file('hello_world.cpp'), '-s', "TEST_KEY='MISSING_QUOTE"])
7639+
err = self.expect_fail([EMCC, test_file('hello_world.c'), '-s', "TEST_KEY='MISSING_QUOTE"])
76407640
self.assertNotContained('AssertionError', err) # Do not mention that it is an assertion error
76417641
self.assertContained('unclosed opened quoted string. expected final character to be "\'"', err)
76427642

76437643
def test_dash_s_single_quote(self):
76447644
# Only one quote
7645-
err = self.expect_fail([EMXX, test_file('hello_world.cpp'), "-sTEST_KEY='"])
7645+
err = self.expect_fail([EMCC, test_file('hello_world.c'), "-sTEST_KEY='"])
76467646
self.assertNotContained('AssertionError', err) # Do not mention that it is an assertion error
76477647
self.assertContained('unclosed opened quoted string.', err)
76487648

@@ -7678,7 +7678,7 @@ def test_dash_s_typo(self):
76787678

76797679
def test_dash_s_with_space(self):
76807680
self.run_process([EMCC, test_file('hello_world.c'), '-s', 'EXPORT_ALL'])
7681-
err = self.expect_fail([EMXX, test_file('hello_world.cpp'), '-s', 'EXPORTED_FUNCTIONS=foo'])
7681+
err = self.expect_fail([EMCC, test_file('hello_world.c'), '-s', 'EXPORTED_FUNCTIONS=foo'])
76827682
self.assertContained('error: undefined exported symbol: "foo"', err)
76837683

76847684
def test_dash_s_hex(self):
@@ -8020,13 +8020,13 @@ def test_binaryen_warn_mem(self):
80208020
# if user changes INITIAL_MEMORY at runtime, the wasm module may not accept the memory import if
80218021
# it is too big/small
80228022
create_file('pre.js', 'Module.INITIAL_MEMORY = 50 * 1024 * 1024')
8023-
self.run_process([EMXX, test_file('hello_world.cpp'), '-sINITIAL_MEMORY=' + str(16 * 1024 * 1024), '--pre-js', 'pre.js', '-sWASM_ASYNC_COMPILATION=0', '-sIMPORTED_MEMORY'])
8023+
self.run_process([EMCC, test_file('hello_world.c'), '-sINITIAL_MEMORY=' + str(16 * 1024 * 1024), '--pre-js', 'pre.js', '-sWASM_ASYNC_COMPILATION=0', '-sIMPORTED_MEMORY'])
80248024
out = self.run_js('a.out.js', assert_returncode=NON_ZERO)
80258025
self.assertContained('LinkError', out)
80268026
self.assertContained("memory import 2 has a larger maximum size 800 than the module's declared maximum", out)
80278027
self.assertNotContained('hello, world!', out)
80288028
# and with memory growth, all should be good
8029-
self.run_process([EMXX, test_file('hello_world.cpp'), '-sINITIAL_MEMORY=' + str(16 * 1024 * 1024), '--pre-js', 'pre.js', '-sALLOW_MEMORY_GROWTH', '-sWASM_ASYNC_COMPILATION=0', '-sIMPORTED_MEMORY'])
8029+
self.run_process([EMCC, test_file('hello_world.c'), '-sINITIAL_MEMORY=' + str(16 * 1024 * 1024), '--pre-js', 'pre.js', '-sALLOW_MEMORY_GROWTH', '-sWASM_ASYNC_COMPILATION=0', '-sIMPORTED_MEMORY'])
80308030
self.assertContained('hello, world!', self.run_js('a.out.js'))
80318031

80328032
def test_memory_size(self):
@@ -8126,7 +8126,7 @@ def test_binaryen_debug(self):
81268126
]:
81278127
print(args, expect_emit_text)
81288128
delete_file('a.out.wat')
8129-
cmd = [EMXX, test_file('hello_world.cpp')] + args
8129+
cmd = [EMCC, test_file('hello_world.c')] + args
81308130
print(' '.join(cmd))
81318131
self.run_process(cmd)
81328132
js = read_file('a.out.js')
@@ -8154,7 +8154,7 @@ def test_binaryen_ignore_implicit_traps(self):
81548154

81558155
def test_binaryen_passes_extra(self):
81568156
def build(args):
8157-
return self.run_process([EMXX, test_file('hello_world.cpp'), '-O3'] + args, stdout=PIPE).stdout
8157+
return self.run_process([EMCC, test_file('hello_world.c'), '-O3'] + args, stdout=PIPE).stdout
81588158

81598159
build([])
81608160
base_size = os.path.getsize('a.out.wasm')
@@ -8409,7 +8409,7 @@ def test_exported_runtime_methods_metadce(self, use_legacy_name):
84098409
setting_name = 'EXPORTED_RUNTIME_METHODS'
84108410
if use_legacy_name:
84118411
setting_name = 'EXTRA_EXPORTED_RUNTIME_METHODS'
8412-
err = self.run_process([EMXX, test_file('hello_world.cpp'), '-Os', '-s%s=%s' % (setting_name, ','.join(exports))], stderr=PIPE).stderr
8412+
err = self.run_process([EMCC, test_file('hello_world.c'), '-Os', '-s%s=%s' % (setting_name, ','.join(exports))], stderr=PIPE).stderr
84138413
if use_legacy_name:
84148414
self.assertContained('warning: EXTRA_EXPORTED_RUNTIME_METHODS is deprecated, please use EXPORTED_RUNTIME_METHODS instead [-Wdeprecated]', err)
84158415
js = read_file('a.out.js')
@@ -8530,7 +8530,7 @@ def test_wasm_target_and_STANDALONE_WASM(self):
85308530
print(opts, potentially_expect_minified_exports_and_imports, target, ' => ', expect_minified_exports_and_imports, standalone)
85318531

85328532
self.clear()
8533-
self.run_process([EMXX, test_file('hello_world.cpp'), '-o', target] + opts)
8533+
self.run_process([EMCC, test_file('hello_world.c'), '-o', target] + opts)
85348534
self.assertExists('out.wasm')
85358535
if target.endswith('.wasm'):
85368536
# only wasm requested
@@ -8654,7 +8654,7 @@ def test_lto_flags(self):
86548654
(['-sWASM_OBJECT_FILES=0'], True),
86558655
(['-sWASM_OBJECT_FILES'], False),
86568656
]:
8657-
self.run_process([EMXX, test_file('hello_world.cpp')] + flags + ['-c', '-o', 'a.o'])
8657+
self.run_process([EMCC, test_file('hello_world.c')] + flags + ['-c', '-o', 'a.o'])
86588658
seen_bitcode = building.is_bitcode('a.o')
86598659
self.assertEqual(expect_bitcode, seen_bitcode, 'must emit LTO-capable bitcode when flags indicate so (%s)' % str(flags))
86608660

@@ -8671,7 +8671,7 @@ def test_wasm_nope(self):
86718671
print(opts)
86728672
# check we show a good error message if there is no wasm support
86738673
create_file('pre.js', 'WebAssembly = undefined;\n')
8674-
self.run_process([EMXX, test_file('hello_world.cpp'), '--pre-js', 'pre.js'] + opts)
8674+
self.run_process([EMCC, test_file('hello_world.c'), '--pre-js', 'pre.js'] + opts)
86758675
out = self.run_js('a.out.js', assert_returncode=NON_ZERO)
86768676
self.assertContained('no native wasm support detected', out)
86778677

@@ -8862,7 +8862,7 @@ def test_jsrun(self):
88628862

88638863
def test_error_on_missing_libraries(self):
88648864
# -llsomenonexistingfile is an error by default
8865-
err = self.expect_fail([EMXX, test_file('hello_world.cpp'), '-lsomenonexistingfile'])
8865+
err = self.expect_fail([EMCC, test_file('hello_world.c'), '-lsomenonexistingfile'])
88668866
self.assertContained('wasm-ld: error: unable to find library -lsomenonexistingfile', err)
88678867

88688868
# Tests that if user accidentally attempts to link native object code, we show an error
@@ -11490,32 +11490,32 @@ def test_missing_stdlibs(self):
1149011490
# Certain standard libraries are expected to be useable via -l flags but
1149111491
# don't actually exist in our standard library path. Make sure we don't
1149211492
# error out when linking with these flags.
11493-
self.run_process([EMXX, test_file('hello_world.cpp'), '-lm', '-ldl', '-lrt', '-lpthread'])
11493+
self.run_process([EMCC, test_file('hello_world.c'), '-lm', '-ldl', '-lrt', '-lpthread'])
1149411494

1149511495
def test_supported_linker_flags(self):
11496-
out = self.run_process([EMXX, test_file('hello_world.cpp'), '-Wl,-rpath=foo'], stderr=PIPE).stderr
11496+
out = self.run_process([EMCC, test_file('hello_world.c'), '-Wl,-rpath=foo'], stderr=PIPE).stderr
1149711497
self.assertContained('warning: ignoring unsupported linker flag: `-rpath=foo`', out)
1149811498

11499-
out = self.run_process([EMXX, test_file('hello_world.cpp'), '-Wl,-rpath-link,foo'], stderr=PIPE).stderr
11499+
out = self.run_process([EMCC, test_file('hello_world.c'), '-Wl,-rpath-link,foo'], stderr=PIPE).stderr
1150011500
self.assertContained('warning: ignoring unsupported linker flag: `-rpath-link`', out)
1150111501

11502-
out = self.run_process([EMXX, test_file('hello_world.cpp'),
11502+
out = self.run_process([EMCC, test_file('hello_world.c'),
1150311503
'-Wl,--no-check-features,-mllvm,--data-sections'], stderr=PIPE).stderr
1150411504
self.assertNotContained('warning: ignoring unsupported linker flag', out)
1150511505

11506-
out = self.run_process([EMXX, test_file('hello_world.cpp'), '-Wl,-allow-shlib-undefined'], stderr=PIPE).stderr
11506+
out = self.run_process([EMCC, test_file('hello_world.c'), '-Wl,-allow-shlib-undefined'], stderr=PIPE).stderr
1150711507
self.assertContained('warning: ignoring unsupported linker flag: `-allow-shlib-undefined`', out)
1150811508

11509-
out = self.run_process([EMXX, test_file('hello_world.cpp'), '-Wl,--allow-shlib-undefined'], stderr=PIPE).stderr
11509+
out = self.run_process([EMCC, test_file('hello_world.c'), '-Wl,--allow-shlib-undefined'], stderr=PIPE).stderr
1151011510
self.assertContained('warning: ignoring unsupported linker flag: `--allow-shlib-undefined`', out)
1151111511

11512-
out = self.run_process([EMXX, test_file('hello_world.cpp'), '-Wl,-version-script,foo'], stderr=PIPE).stderr
11512+
out = self.run_process([EMCC, test_file('hello_world.c'), '-Wl,-version-script,foo'], stderr=PIPE).stderr
1151311513
self.assertContained('warning: ignoring unsupported linker flag: `-version-script`', out)
1151411514

1151511515
def test_supported_linker_flag_skip_next(self):
1151611516
# Regression test for a bug where skipping an unsupported linker flag
1151711517
# could skip the next unrelated linker flag.
11518-
err = self.expect_fail([EMXX, test_file('hello_world.cpp'), '-Wl,-rpath=foo', '-lbar'])
11518+
err = self.expect_fail([EMCC, test_file('hello_world.c'), '-Wl,-rpath=foo', '-lbar'])
1151911519
self.assertContained('error: unable to find library -lbar', err)
1152011520

1152111521
def test_linker_flags_pass_through(self):
@@ -11532,27 +11532,27 @@ def test_linker_flags_pass_through(self):
1153211532
self.assertContained('wasm-ld: warning: unknown -z value: foo', err)
1153311533

1153411534
def test_linker_flags_unused(self):
11535-
err = self.run_process([EMXX, test_file('hello_world.cpp'), '-c', '-lbar'], stderr=PIPE).stderr
11535+
err = self.run_process([EMCC, test_file('hello_world.c'), '-c', '-lbar'], stderr=PIPE).stderr
1153611536
self.assertContained("warning: -lbar: 'linker' input unused [-Wunused-command-line-argument]", err)
1153711537

1153811538
def test_linker_input_unused(self):
11539-
self.run_process([EMXX, '-c', test_file('hello_world.cpp')])
11539+
self.run_process([EMCC, '-c', test_file('hello_world.c')])
1154011540
err = self.run_process([EMCC, 'hello_world.o', '-c', '-o', 'out.o'], stderr=PIPE).stderr
1154111541
self.assertContained("clang: warning: hello_world.o: 'linker' input unused [-Wunused-command-line-argument]", err)
1154211542
# In this case the compiler does not produce any output file.
1154311543
self.assertNotExists('out.o')
1154411544

1154511545
def test_non_wasm_without_wasm_in_vm(self):
1154611546
# Test that our non-wasm output does not depend on wasm support in the vm.
11547-
self.run_process([EMXX, test_file('hello_world.cpp'), '-sWASM=0', '-sENVIRONMENT=node,shell'])
11547+
self.run_process([EMCC, test_file('hello_world.c'), '-sWASM=0', '-sENVIRONMENT=node,shell'])
1154811548
js = read_file('a.out.js')
1154911549
create_file('a.out.js', 'var WebAssembly = null;\n' + js)
1155011550
for engine in config.JS_ENGINES:
1155111551
self.assertContained('hello, world!', self.run_js('a.out.js', engine=engine))
1155211552

1155311553
def test_empty_output_extension(self):
1155411554
# Default to JS output when no extension is present
11555-
self.run_process([EMXX, test_file('hello_world.cpp'), '-Werror', '-o', 'hello'])
11555+
self.run_process([EMCC, test_file('hello_world.c'), '-Werror', '-o', 'hello'])
1155611556
self.assertContained('hello, world!', self.run_js('hello'))
1155711557

1155811558
def test_backwards_deps_in_archive(self):
@@ -11665,11 +11665,11 @@ def test_stdin_compile_and_link(self):
1166511665
def test_stdout_link(self):
1166611666
# linking to stdout `-` doesn't work, we have no way to pass such an output filename
1166711667
# through post-link tools such as binaryen.
11668-
err = self.expect_fail([EMXX, '-o', '-', test_file('hello_world.cpp')])
11668+
err = self.expect_fail([EMCC, '-o', '-', test_file('hello_world.c')])
1166911669
self.assertContained('invalid output filename: `-`', err)
1167011670
self.assertNotExists('-')
1167111671

11672-
err = self.expect_fail([EMXX, '-o', '-foo', test_file('hello_world.cpp')])
11672+
err = self.expect_fail([EMCC, '-o', '-foo', test_file('hello_world.c')])
1167311673
self.assertContained('invalid output filename: `-foo`', err)
1167411674
self.assertNotExists('-foo')
1167511675

@@ -11698,7 +11698,7 @@ def ok(args, filename='hello_world.cpp', expected='hello, world!'):
1169811698
def fail(args, details):
1169911699
print('fail', args, details)
1170011700
args += ['-sERROR_ON_WASM_CHANGES_AFTER_LINK']
11701-
err = self.expect_fail([EMXX, test_file('hello_world.cpp')] + args)
11701+
err = self.expect_fail([EMCC, test_file('hello_world.c')] + args)
1170211702
self.assertContained('changes to the wasm are required after link, but disallowed by ERROR_ON_WASM_CHANGES_AFTER_LINK', err)
1170311703
self.assertContained(details, err)
1170411704

@@ -11712,7 +11712,7 @@ def fail(args, details):
1171211712

1171311713
@crossplatform
1171411714
def test_output_to_nowhere(self):
11715-
self.run_process([EMXX, test_file('hello_world.cpp'), '-o', os.devnull, '-c'])
11715+
self.run_process([EMCC, test_file('hello_world.c'), '-o', os.devnull, '-c'])
1171611716

1171711717
# Test that passing -sMIN_X_VERSION=-1 on the command line will result in browser X being not supported at all.
1171811718
# I.e. -sMIN_X_VERSION=-1 is equal to -sMIN_X_VERSION=Infinity
@@ -11752,7 +11752,7 @@ def test(args, expect_fail):
1175211752
# legacy browsers may lack Promise, which wasm2js depends on. see what
1175311753
# happens when we kill the global Promise function.
1175411754
create_file('extern-post.js', extern_post_js)
11755-
self.run_process([EMXX, test_file('hello_world.cpp')] + constant_args + args + ['--extern-post-js', 'extern-post.js'])
11755+
self.run_process([EMCC, test_file('hello_world.c')] + constant_args + args + ['--extern-post-js', 'extern-post.js'])
1175611756
js = read_file('a.out.js')
1175711757
create_file('a.out.js', 'Promise = undefined;\n' + js)
1175811758
return self.run_js('a.out.js', assert_returncode=NON_ZERO if expect_fail else 0)

tools/maint/check_for_unused_test_files.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
script_dir = os.path.dirname(os.path.abspath(__file__))
1313
root_dir = os.path.dirname(os.path.dirname(script_dir))
14-
test_dir = os.path.join(root_dir, 'tests')
14+
test_dir = os.path.join(root_dir, 'test')
1515
ignore_dirs = {
1616
'third_party',
1717
'metadce',
@@ -26,6 +26,7 @@
2626
}
2727
ignore_root_patterns = ['runner.*', 'test_*.py']
2828
ignore_root_files = {
29+
'check_clean.py',
2930
'jsrun.py',
3031
'clang_native.py',
3132
'common.py',
@@ -97,7 +98,7 @@ def main(args):
9798
check_file(test_dir, arg)
9899
return 0
99100

100-
for (dirpath, dirnames, filenames) in os.walk(test_dir):
101+
for dirpath, dirnames, filenames in os.walk(test_dir):
101102
if os.path.basename(dirpath) in ignore_dirs:
102103
dirnames.clear()
103104
filenames.clear()

0 commit comments

Comments
 (0)