Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 26 additions & 33 deletions test/test_jslib.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def test_jslib_no_override(self):
''')

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

def test_jslib_missing_sig(self):
create_file('some_func.c', '''
Expand All @@ -61,8 +61,8 @@ def test_jslib_missing_sig(self):
''')

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

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

create_file('lib.js', '''\
// This is a library file

#else // line 3
''')
err = self.expect_fail([EMCC, test_file('hello_world.c'), '--js-library', 'lib.js'])
self.assertContained('lib.js:3: #else without matching #if', err)
self.assert_fail([EMCC, test_file('hello_world.c'), '--js-library', 'lib.js'], 'lib.js:3: #else without matching #if')

def test_jslib_internal_deps(self):
create_file('lib.js', r'''
Expand Down Expand Up @@ -252,8 +250,8 @@ def test_jslib_sig_redefinition(self):
jslibfunc: (x) => {},
});
''')
err = self.expect_fail([EMCC, 'src.c', '--js-library', 'lib.js', '--js-library', 'lib2.js'])
self.assertContained('lib2.js: signature redefinition for: jslibfunc__sig. (old=ii vs new=pp)', err)
self.assert_fail([EMCC, 'src.c', '--js-library', 'lib.js', '--js-library', 'lib2.js'],
'lib2.js: signature redefinition for: jslibfunc__sig. (old=ii vs new=pp)')

def test_jslib_invalid_deps(self):
create_file('lib.js', r'''
Expand All @@ -263,8 +261,8 @@ def test_jslib_invalid_deps(self):
});
''')

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

create_file('lib2.js', r'''
addToLibrary({
Expand All @@ -273,8 +271,8 @@ def test_jslib_invalid_deps(self):
});
''')

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

def test_jslib_invalid_decorator(self):
create_file('lib.js', r'''
Expand All @@ -283,8 +281,8 @@ def test_jslib_invalid_decorator(self):
jslibfunc: (x) => {},
});
''')
err = self.expect_fail([EMCC, test_file('hello_world.c'), '--js-library', 'lib.js'])
self.assertContained("lib.js: Decorator (jslibfunc__async} has wrong type. Expected 'boolean' not 'string'", err)
self.assert_fail([EMCC, test_file('hello_world.c'), '--js-library', 'lib.js'],
"lib.js: Decorator (jslibfunc__async} has wrong type. Expected 'boolean' not 'string'")

@also_with_wasm64
@also_without_bigint
Expand Down Expand Up @@ -312,8 +310,8 @@ def test_jslib_i53abi_errors(self):
jslibfunc: (x) => { return 42 },
});
''')
err = self.expect_fail([EMCC, test_file('hello_world.c'), '-sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE=jslibfunc', '--js-library', 'lib.js'])
self.assertContained("error: JS library error: '__i53abi' decorator requires '__sig' decorator: 'jslibfunc'", err)
self.assert_fail([EMCC, test_file('hello_world.c'), '-sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE=jslibfunc', '--js-library', 'lib.js'],
"error: JS library error: '__i53abi' decorator requires '__sig' decorator: 'jslibfunc'")

create_file('lib.js', r'''
mergeInto(LibraryManager.library, {
Expand All @@ -322,8 +320,8 @@ def test_jslib_i53abi_errors(self):
jslibfunc: (x) => { return 42 },
});
''')
err = self.expect_fail([EMCC, test_file('hello_world.c'), '-sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE=jslibfunc', '--js-library', 'lib.js'])
self.assertContained("error: JS library error: '__i53abi' only makes sense when '__sig' includes 'j' (int64): 'jslibfunc'", err)
self.assert_fail([EMCC, test_file('hello_world.c'), '-sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE=jslibfunc', '--js-library', 'lib.js'],
"error: JS library error: '__i53abi' only makes sense when '__sig' includes 'j' (int64): 'jslibfunc'")

def test_jslib_invalid_proxy_mode(self):
create_file('lib.js', r'''
Expand All @@ -332,8 +330,8 @@ def test_jslib_invalid_proxy_mode(self):
jslibfunc: (x) => 42,
});
''')
err = self.expect_fail([EMCC, test_file('hello_world.c'), '-sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE=jslibfunc', '--js-library', 'lib.js'])
self.assertContained("error: JS library error: invalid proxying mode 'jslibfunc__proxy: foo' specified", err)
self.assert_fail([EMCC, test_file('hello_world.c'), '-sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE=jslibfunc', '--js-library', 'lib.js'],
"error: JS library error: invalid proxying mode 'jslibfunc__proxy: foo' specified")

def test_jslib_legacy(self):
create_file('lib.js', r'''
Expand All @@ -357,7 +355,7 @@ def test_jslib_custom_settings(self):
self.cflags += ['--js-library', test_file('jslib/test_jslib_custom_settings.js'), '-jsDCUSTOM_JS_OPTION=1']
self.do_run_in_out_file_test('jslib/test_jslib_custom_settings.c')

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

def test_jslib_native_deps(self):
# Verify that memset (which lives in compiled code), can be specified as a JS library
Expand Down Expand Up @@ -418,8 +416,7 @@ def test_jslib_bad_config(self):
foo__sig: 'ii',
});
''')
err = self.expect_fail([EMCC, test_file('hello_world.c'), '--js-library=lib.js'])
self.assertContained("lib.js: Missing library element 'foo' for library config 'foo__sig'", err)
self.assert_fail([EMCC, test_file('hello_world.c'), '--js-library=lib.js'], "lib.js: Missing library element 'foo' for library config 'foo__sig'")

def test_jslib_ifdef(self):
create_file('lib.js', '''
Expand Down Expand Up @@ -463,8 +460,7 @@ def test_jslib_search_path(self):
self.do_runf('main.c', '42\n', cflags=['-L.', '-lfoo.js'])

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

# Tests using the #warning directive in JS library files
def test_jslib_warnings(self):
Expand Down Expand Up @@ -502,8 +498,7 @@ def test_jslib_include(self):
self.run_process([EMCC, test_file('hello_world.c'), '--js-library', 'foo.js'])

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

@also_with_wasm64
@also_without_bigint
Expand Down Expand Up @@ -609,8 +604,7 @@ def test_jslib_export_alias(self, args):

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

def test_jslib_has_library(self):
create_file('libfoo.js', '''
Expand Down Expand Up @@ -655,8 +649,7 @@ def test_jslib_new_objects_non_empty(self):
}
});
''')
err = self.expect_fail([EMCC, test_file('hello_world.c'), '--js-library=lib.js', '-sEXPORTED_FUNCTIONS=obj,_main'])
self.assertContained('cannot stringify Map with data', err)
self.assert_fail([EMCC, test_file('hello_world.c'), '--js-library=lib.js', '-sEXPORTED_FUNCTIONS=obj,_main'], 'cannot stringify Map with data')

def test_jslib_system_lib_name(self):
create_file('libcore.js', r'''
Expand Down