Skip to content

Commit 87f34a7

Browse files
authored
Use assert_fail in test_jslib.py. NFC (emscripten-core#26003)
1 parent f5d7467 commit 87f34a7

File tree

1 file changed

+26
-33
lines changed

1 file changed

+26
-33
lines changed

test/test_jslib.py

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def test_jslib_no_override(self):
3939
''')
4040

4141
self.cflags += ['--js-library', 'duplicated_func_1.js', '--js-library', 'duplicated_func_2.js']
42-
err = self.expect_fail([EMCC, 'duplicated_func.c'] + self.get_cflags())
43-
self.assertContained('duplicated_func_2.js: Symbol re-definition in JavaScript library: duplicatedFunc. Do not use noOverride if this is intended', err)
42+
self.assert_fail([EMCC, 'duplicated_func.c'] + self.get_cflags(),
43+
'duplicated_func_2.js: Symbol re-definition in JavaScript library: duplicatedFunc. Do not use noOverride if this is intended')
4444

4545
def test_jslib_missing_sig(self):
4646
create_file('some_func.c', '''
@@ -61,8 +61,8 @@ def test_jslib_missing_sig(self):
6161
''')
6262

6363
self.cflags += ['--js-library', 'some_func.js']
64-
err = self.expect_fail([EMCC, 'some_func.c'] + self.get_cflags())
65-
self.assertContained('some_func.js: __sig is missing for function: someFunc. Do not use checkSig if this is intended', err)
64+
self.assert_fail([EMCC, 'some_func.c'] + self.get_cflags(),
65+
'some_func.js: __sig is missing for function: someFunc. Do not use checkSig if this is intended')
6666

6767
def test_jslib_extra_args(self):
6868
# Verify that extra arguments in addition to those listed in `__sig` are still present
@@ -193,16 +193,14 @@ def test_jslib_preprocessor_errors(self):
193193
// This is a library file
194194
#endif // line 2
195195
''')
196-
err = self.expect_fail([EMCC, test_file('hello_world.c'), '--js-library', 'lib.js'])
197-
self.assertContained('lib.js:2: #endif without matching #if', err)
196+
self.assert_fail([EMCC, test_file('hello_world.c'), '--js-library', 'lib.js'], 'lib.js:2: #endif without matching #if')
198197

199198
create_file('lib.js', '''\
200199
// This is a library file
201200
202201
#else // line 3
203202
''')
204-
err = self.expect_fail([EMCC, test_file('hello_world.c'), '--js-library', 'lib.js'])
205-
self.assertContained('lib.js:3: #else without matching #if', err)
203+
self.assert_fail([EMCC, test_file('hello_world.c'), '--js-library', 'lib.js'], 'lib.js:3: #else without matching #if')
206204

207205
def test_jslib_internal_deps(self):
208206
create_file('lib.js', r'''
@@ -252,8 +250,8 @@ def test_jslib_sig_redefinition(self):
252250
jslibfunc: (x) => {},
253251
});
254252
''')
255-
err = self.expect_fail([EMCC, 'src.c', '--js-library', 'lib.js', '--js-library', 'lib2.js'])
256-
self.assertContained('lib2.js: signature redefinition for: jslibfunc__sig. (old=ii vs new=pp)', err)
253+
self.assert_fail([EMCC, 'src.c', '--js-library', 'lib.js', '--js-library', 'lib2.js'],
254+
'lib2.js: signature redefinition for: jslibfunc__sig. (old=ii vs new=pp)')
257255

258256
def test_jslib_invalid_deps(self):
259257
create_file('lib.js', r'''
@@ -263,8 +261,8 @@ def test_jslib_invalid_deps(self):
263261
});
264262
''')
265263

266-
err = self.expect_fail([EMCC, test_file('hello_world.c'), '--js-library', 'lib.js'])
267-
self.assertContained('lib.js: JS library directive jslibfunc__deps=hello is of type \'string\', but it should be an array', err)
264+
self.assert_fail([EMCC, test_file('hello_world.c'), '--js-library', 'lib.js'],
265+
'lib.js: JS library directive jslibfunc__deps=hello is of type \'string\', but it should be an array')
268266

269267
create_file('lib2.js', r'''
270268
addToLibrary({
@@ -273,8 +271,8 @@ def test_jslib_invalid_deps(self):
273271
});
274272
''')
275273

276-
err = self.expect_fail([EMCC, test_file('hello_world.c'), '--js-library', 'lib2.js'])
277-
self.assertContained("lib2.js: __deps entries must be of type 'string' or 'function' not 'number': jslibfunc__deps", err)
274+
self.assert_fail([EMCC, test_file('hello_world.c'), '--js-library', 'lib2.js'],
275+
"lib2.js: __deps entries must be of type 'string' or 'function' not 'number': jslibfunc__deps")
278276

279277
def test_jslib_invalid_decorator(self):
280278
create_file('lib.js', r'''
@@ -283,8 +281,8 @@ def test_jslib_invalid_decorator(self):
283281
jslibfunc: (x) => {},
284282
});
285283
''')
286-
err = self.expect_fail([EMCC, test_file('hello_world.c'), '--js-library', 'lib.js'])
287-
self.assertContained("lib.js: Decorator (jslibfunc__async} has wrong type. Expected 'boolean' not 'string'", err)
284+
self.assert_fail([EMCC, test_file('hello_world.c'), '--js-library', 'lib.js'],
285+
"lib.js: Decorator (jslibfunc__async} has wrong type. Expected 'boolean' not 'string'")
288286

289287
@also_with_wasm64
290288
@also_without_bigint
@@ -312,8 +310,8 @@ def test_jslib_i53abi_errors(self):
312310
jslibfunc: (x) => { return 42 },
313311
});
314312
''')
315-
err = self.expect_fail([EMCC, test_file('hello_world.c'), '-sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE=jslibfunc', '--js-library', 'lib.js'])
316-
self.assertContained("error: JS library error: '__i53abi' decorator requires '__sig' decorator: 'jslibfunc'", err)
313+
self.assert_fail([EMCC, test_file('hello_world.c'), '-sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE=jslibfunc', '--js-library', 'lib.js'],
314+
"error: JS library error: '__i53abi' decorator requires '__sig' decorator: 'jslibfunc'")
317315

318316
create_file('lib.js', r'''
319317
addToLibrary({
@@ -322,8 +320,8 @@ def test_jslib_i53abi_errors(self):
322320
jslibfunc: (x) => { return 42 },
323321
});
324322
''')
325-
err = self.expect_fail([EMCC, test_file('hello_world.c'), '-sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE=jslibfunc', '--js-library', 'lib.js'])
326-
self.assertContained("error: JS library error: '__i53abi' only makes sense when '__sig' includes 'j' (int64): 'jslibfunc'", err)
323+
self.assert_fail([EMCC, test_file('hello_world.c'), '-sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE=jslibfunc', '--js-library', 'lib.js'],
324+
"error: JS library error: '__i53abi' only makes sense when '__sig' includes 'j' (int64): 'jslibfunc'")
327325

328326
def test_jslib_invalid_proxy_mode(self):
329327
create_file('lib.js', r'''
@@ -332,8 +330,8 @@ def test_jslib_invalid_proxy_mode(self):
332330
jslibfunc: (x) => 42,
333331
});
334332
''')
335-
err = self.expect_fail([EMCC, test_file('hello_world.c'), '-sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE=jslibfunc', '--js-library', 'lib.js'])
336-
self.assertContained("error: JS library error: invalid proxying mode 'jslibfunc__proxy: foo' specified", err)
333+
self.assert_fail([EMCC, test_file('hello_world.c'), '-sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE=jslibfunc', '--js-library', 'lib.js'],
334+
"error: JS library error: invalid proxying mode 'jslibfunc__proxy: foo' specified")
337335

338336
def test_jslib_legacy(self):
339337
# Test that the legacy `mergeInfo` function work instead of `addToLibrary`
@@ -358,7 +356,7 @@ def test_jslib_custom_settings(self):
358356
self.cflags += ['--js-library', test_file('jslib/test_jslib_custom_settings.js'), '-jsDCUSTOM_JS_OPTION=1']
359357
self.do_run_in_out_file_test('jslib/test_jslib_custom_settings.c')
360358

361-
self.assertContained('cannot change built-in settings values with a -jsD directive', self.expect_fail([EMCC, '-jsDWASM=0']))
359+
self.assert_fail([EMCC, '-jsDWASM=0'], 'cannot change built-in settings values with a -jsD directive')
362360

363361
def test_jslib_native_deps(self):
364362
# Verify that memset (which lives in compiled code), can be specified as a JS library
@@ -419,8 +417,7 @@ def test_jslib_bad_config(self):
419417
foo__sig: 'ii',
420418
});
421419
''')
422-
err = self.expect_fail([EMCC, test_file('hello_world.c'), '--js-library=lib.js'])
423-
self.assertContained("lib.js: Missing library element 'foo' for library config 'foo__sig'", err)
420+
self.assert_fail([EMCC, test_file('hello_world.c'), '--js-library=lib.js'], "lib.js: Missing library element 'foo' for library config 'foo__sig'")
424421

425422
def test_jslib_ifdef(self):
426423
create_file('lib.js', '''
@@ -464,8 +461,7 @@ def test_jslib_search_path(self):
464461
self.do_runf('main.c', '42\n', cflags=['-L.', '-lfoo.js'])
465462

466463
# If the library path is not included with `-L` we expect the command to fail
467-
err = self.expect_fail([EMCC, 'main.c', '-lfoo.js'])
468-
self.assertContained('emcc: error: unable to find library -lfoo.js', err)
464+
self.assert_fail([EMCC, 'main.c', '-lfoo.js'], 'emcc: error: unable to find library -lfoo.js')
469465

470466
# Tests using the #warning directive in JS library files
471467
def test_jslib_warnings(self):
@@ -503,8 +499,7 @@ def test_jslib_include(self):
503499
self.run_process([EMCC, test_file('hello_world.c'), '--js-library', 'foo.js'])
504500

505501
delete_file('inc.js')
506-
err = self.expect_fail([EMCC, test_file('hello_world.c'), '--js-library', 'foo.js'])
507-
self.assertContained('foo.js:5: file not found: inc.js', err)
502+
self.assert_fail([EMCC, test_file('hello_world.c'), '--js-library', 'foo.js'], 'foo.js:5: file not found: inc.js')
508503

509504
@also_with_wasm64
510505
@also_without_bigint
@@ -610,8 +605,7 @@ def test_jslib_export_alias(self, args):
610605

611606
def test_postjs_errors(self):
612607
create_file('post.js', '#preprocess\n#error This is an error')
613-
err = self.expect_fail([EMCC, test_file('hello_world.c'), '--post-js', 'post.js'])
614-
self.assertContained('post.js:2: #error This is an error', err)
608+
self.assert_fail([EMCC, test_file('hello_world.c'), '--post-js', 'post.js'], 'post.js:2: #error This is an error')
615609

616610
def test_jslib_has_library(self):
617611
create_file('libfoo.js', '''
@@ -656,8 +650,7 @@ def test_jslib_new_objects_non_empty(self):
656650
}
657651
});
658652
''')
659-
err = self.expect_fail([EMCC, test_file('hello_world.c'), '--js-library=lib.js', '-sEXPORTED_FUNCTIONS=obj,_main'])
660-
self.assertContained('cannot stringify Map with data', err)
653+
self.assert_fail([EMCC, test_file('hello_world.c'), '--js-library=lib.js', '-sEXPORTED_FUNCTIONS=obj,_main'], 'cannot stringify Map with data')
661654

662655
def test_jslib_system_lib_name(self):
663656
create_file('libcore.js', r'''

0 commit comments

Comments
 (0)