@@ -80,7 +80,18 @@ def decorated(self):
80
80
return decorated
81
81
82
82
83
+ def with_both_compilers(f):
84
+ assert callable(f)
85
+
86
+ f._parameterize = {'': (EMCC,),
87
+ 'emxx': (EMXX,)}
88
+ return f
89
+
90
+
83
91
def also_with_wasmfs(f):
92
+ assert callable(f)
93
+
94
+ @wraps(f)
84
95
def metafunc(self, wasmfs):
85
96
if wasmfs:
86
97
self.set_setting('WASMFS')
@@ -107,6 +118,9 @@ def metafunc(self, backend):
107
118
108
119
109
120
def also_with_wasmfs_all_backends(f):
121
+ assert callable(f)
122
+
123
+ @wraps(f)
110
124
def metafunc(self, backend):
111
125
if backend:
112
126
self.set_setting('WASMFS')
@@ -243,20 +257,20 @@ def parse_wasm(self, filename):
243
257
# This needs to work because many tools run `emcc -v` internally and it should
244
258
# always work even if the user has `EMCC_CFLAGS` set.
245
259
@with_env_modify({'EMCC_CFLAGS': '-should -be -ignored'})
260
+ @with_both_compilers
246
261
@crossplatform
247
- def test_emcc_v(self):
248
- for compiler in [EMCC, EMXX]:
249
- # -v, without input files
250
- proc = self.run_process([compiler, '-v'], stdout=PIPE, stderr=PIPE)
251
- self.assertEqual(proc.stdout, '')
252
- # assert that the emcc message comes first. We had a bug where the sub-process output
253
- # from clang would be flushed to stderr first.
254
- self.assertContained('emcc (Emscripten gcc/clang-like replacement', proc.stderr)
255
- self.assertTrue(proc.stderr.startswith('emcc (Emscripten gcc/clang-like replacement'))
256
- self.assertContained('clang version ', proc.stderr)
257
- self.assertContained('GNU', proc.stderr)
258
- self.assertContained('Target: wasm32-unknown-emscripten', proc.stderr)
259
- self.assertNotContained('this is dangerous', proc.stderr)
262
+ def test_emcc_v(self, compiler):
263
+ # -v, without input files
264
+ proc = self.run_process([compiler, '-v'], stdout=PIPE, stderr=PIPE)
265
+ self.assertEqual(proc.stdout, '')
266
+ # assert that the emcc message comes first. We had a bug where the sub-process output
267
+ # from clang would be flushed to stderr first.
268
+ self.assertContained('emcc (Emscripten gcc/clang-like replacement', proc.stderr)
269
+ self.assertTrue(proc.stderr.startswith('emcc (Emscripten gcc/clang-like replacement'))
270
+ self.assertContained('clang version ', proc.stderr)
271
+ self.assertContained('GNU', proc.stderr)
272
+ self.assertContained('Target: wasm32-unknown-emscripten', proc.stderr)
273
+ self.assertNotContained('this is dangerous', proc.stderr)
260
274
261
275
def test_log_subcommands(self):
262
276
# `-v` when combined with other arguments will trace the subcommands
@@ -281,16 +295,16 @@ def test_emcc_check(self):
281
295
proc = self.run_process([EMCC, '--check'], stdout=PIPE, stderr=PIPE)
282
296
self.assertContained('Running sanity checks', proc.stderr)
283
297
284
- def test_emcc_generate_config(self):
298
+ @with_both_compilers
299
+ def test_emcc_generate_config(self, compiler):
285
300
config_path = './emscripten_config'
286
301
with env_modify({'EM_CONFIG': config_path}):
287
- for compiler in [EMCC, EMXX]:
288
- self.assertNotExists(config_path)
289
- self.run_process([compiler, '--generate-config'])
290
- self.assertExists(config_path)
291
- config_contents = read_file(config_path)
292
- self.assertContained('LLVM_ROOT', config_contents)
293
- os.remove(config_path)
302
+ self.assertNotExists(config_path)
303
+ self.run_process([compiler, '--generate-config'])
304
+ self.assertExists(config_path)
305
+ config_contents = read_file(config_path)
306
+ self.assertContained('LLVM_ROOT', config_contents)
307
+ os.remove(config_path)
294
308
295
309
@parameterized({
296
310
'': ([],),
@@ -385,7 +399,8 @@ def test_emcc_out_file(self):
385
399
386
400
@parameterized({
387
401
'c': [EMCC, '.c'],
388
- 'cxx': [EMXX, '.cpp']})
402
+ 'cxx': [EMXX, '.cpp'],
403
+ })
389
404
def test_emcc_basics(self, compiler, suffix):
390
405
# emcc src.cpp ==> writes a.out.js and a.out.wasm
391
406
self.run_process([compiler, test_file('hello_world' + suffix)])
@@ -1050,23 +1065,23 @@ def verify_includes(stderr):
1050
1065
err = self.run_process([EMXX, test_file('hello_world.cpp'), '-v'], stderr=PIPE).stderr
1051
1066
verify_includes(err)
1052
1067
1053
- def test_failure_error_code(self):
1054
- for compiler in [EMCC, EMXX] :
1055
- # Test that if one file is missing from the build, then emcc shouldn't succeed, and shouldn't produce an output file.
1056
- self.expect_fail([compiler, test_file('hello_world.c'), 'this_file_is_missing.c', '-o', 'out.js'])
1057
- self.assertFalse(os.path.exists('out.js'))
1068
+ @with_both_compilers
1069
+ def test_failure_error_code(self, compiler) :
1070
+ # Test that if one file is missing from the build, then emcc shouldn't succeed, and shouldn't produce an output file.
1071
+ self.expect_fail([compiler, test_file('hello_world.c'), 'this_file_is_missing.c', '-o', 'out.js'])
1072
+ self.assertFalse(os.path.exists('out.js'))
1058
1073
1059
- def test_failure_modularize_and_catch_rejection(self):
1060
- for compiler in [EMCC, EMXX] :
1061
- # Test that if sMODULARIZE and sNODEJS_CATCH_REJECTION are both enabled, then emcc shouldn't succeed, and shouldn't produce an output file.
1062
- self.expect_fail([compiler, test_file('hello_world.c'), '-sMODULARIZE', '-sNODEJS_CATCH_REJECTION', '-o', 'out.js'])
1063
- self.assertFalse(os.path.exists('out.js'))
1074
+ @with_both_compilers
1075
+ def test_failure_modularize_and_catch_rejection(self, compiler) :
1076
+ # Test that if sMODULARIZE and sNODEJS_CATCH_REJECTION are both enabled, then emcc shouldn't succeed, and shouldn't produce an output file.
1077
+ self.expect_fail([compiler, test_file('hello_world.c'), '-sMODULARIZE', '-sNODEJS_CATCH_REJECTION', '-o', 'out.js'])
1078
+ self.assertFalse(os.path.exists('out.js'))
1064
1079
1065
- def test_failure_modularize_and_catch_exit(self):
1066
- for compiler in [EMCC, EMXX] :
1067
- # Test that if sMODULARIZE and sNODEJS_CATCH_EXIT are both enabled, then emcc shouldn't succeed, and shouldn't produce an output file.
1068
- self.expect_fail([compiler, test_file('hello_world.c'), '-sMODULARIZE', '-sNODEJS_CATCH_EXIT', '-o', 'out.js'])
1069
- self.assertFalse(os.path.exists('out.js'))
1080
+ @with_both_compilers
1081
+ def test_failure_modularize_and_catch_exit(self, compiler) :
1082
+ # Test that if sMODULARIZE and sNODEJS_CATCH_EXIT are both enabled, then emcc shouldn't succeed, and shouldn't produce an output file.
1083
+ self.expect_fail([compiler, test_file('hello_world.c'), '-sMODULARIZE', '-sNODEJS_CATCH_EXIT', '-o', 'out.js'])
1084
+ self.assertFalse(os.path.exists('out.js'))
1070
1085
1071
1086
def test_use_cxx(self):
1072
1087
create_file('empty_file', ' ')
@@ -1075,18 +1090,18 @@ def test_use_cxx(self):
1075
1090
dash_xcpp = self.run_process([EMCC, '-v', '-xc++', 'empty_file'], stderr=PIPE).stderr
1076
1091
self.assertContained('-x c++', dash_xcpp)
1077
1092
1078
- def test_cxx11(self):
1093
+ @with_both_compilers
1094
+ def test_cxx11(self, compiler):
1079
1095
for std in ['-std=c++11', '--std=c++11']:
1080
- for compiler in [EMCC, EMXX]:
1081
- self.run_process([compiler, std, test_file('hello_cxx11.cpp')])
1096
+ self.run_process([compiler, std, test_file('hello_cxx11.cpp')])
1082
1097
1083
1098
# Regression test for issue #4522: Incorrect CC vs CXX detection
1084
- def test_incorrect_c_detection(self):
1099
+ @with_both_compilers
1100
+ def test_incorrect_c_detection(self, compiler):
1085
1101
# This auto-detection only works for the compile phase.
1086
1102
# For linking you need to use `em++` or pass `-x c++`
1087
1103
create_file('test.c', 'foo\n')
1088
- for compiler in [EMCC, EMXX]:
1089
- self.run_process([compiler, '-c', '-lembind', '--embed-file', 'test.c', test_file('hello_world.cpp')])
1104
+ self.run_process([compiler, '-c', '-lembind', '--embed-file', 'test.c', test_file('hello_world.cpp')])
1090
1105
1091
1106
def test_odd_suffixes(self):
1092
1107
for suffix in ['CPP', 'c++', 'C++', 'cxx', 'CXX', 'cc', 'CC']:
0 commit comments