Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions tests/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,12 @@ def assertNotContained(self, value, string):
limit_size(''.join([a.rstrip() + '\n' for a in difflib.unified_diff(value.split('\n'), string.split('\n'), fromfile='expected', tofile='actual')]))
))

def assertContainedIf(self, value, string, condition):
if condition:
self.assertContained(value, string)
else:
self.assertNotContained(value, string)

library_cache = {}

def get_build_dir(self):
Expand Down
41 changes: 12 additions & 29 deletions tests/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -1366,9 +1366,8 @@ def test_abspaths(self):
([], False)]:
print(args, expected)
proc = run_process([PYTHON, EMCC, 'main.c'] + args, stderr=PIPE)
assert ('encountered. If this is to a local system header/library, it may cause problems (local system files make sense for compiling natively on your system, but not necessarily to JavaScript)' in proc.stderr) == expected, proc.stderr
if not expected:
assert proc.stderr == '', proc.stderr
WARNING = 'encountered. If this is to a local system header/library, it may cause problems (local system files make sense for compiling natively on your system, but not necessarily to JavaScript)'
self.assertContainedIf(WARNING, proc.stderr, expected)

def test_local_link(self):
# Linking a local library directly, like /usr/lib/libsomething.so, cannot work of course since it
Expand Down Expand Up @@ -1952,10 +1951,7 @@ def test_prepost(self):

run_process([PYTHON, EMCC, 'main.cpp'] + args)
output = run_js('a.out.js')
if no_initial_run:
self.assertNotContained('hello from main', output)
else:
self.assertContained('hello from main', output)
self.assertContainedIf('hello from main', output, not no_initial_run)

if no_initial_run:
# Calling main later should still work, filesystem etc. must be set up.
Expand Down Expand Up @@ -3455,10 +3451,7 @@ def test_no_exit_runtime(self):
exit = 1 - no_exit
print(' exit:', exit, 'opts:', opts)
self.assertContained('coming around', output)
if exit:
self.assertContained('going away', output)
else:
self.assertNotContained('going away', output)
self.assertContainedIf('going away', output, exit)
if not self.is_wasm_backend():
# The wasm backend uses atexit to register destructors when
# constructors are called There is currently no way to exclude
Expand Down Expand Up @@ -3618,10 +3611,7 @@ def test_global_inits(self):
run_js('a.out.js', stderr=PIPE, full_output=True, engine=NODE_JS)
src = open('a.out.js').read()
self.assertContained('argc: 1\n16\n17\n10\n', run_js('a.out.js'))
if has_global:
self.assertContained('globalCtors', src)
else:
self.assertNotContained('globalCtors', src)
self.assertContainedIf('globalCtors', src, has_global)

# Tests that when there are only 0 or 1 global initializers, that a grouped global initializer function will not be generated
# (that would just consume excess code size)
Expand Down Expand Up @@ -3761,10 +3751,7 @@ def test_warn_dylibs(self):
print(suffix)
err = run_process([PYTHON, EMCC, path_from_root('tests', 'hello_world.c'), '-o', 'out' + suffix], stderr=PIPE).stderr
warning = 'When Emscripten compiles to a typical native suffix for shared libraries (.so, .dylib, .dll) then it emits an object file. You should then compile that to an emscripten SIDE_MODULE (using that flag) with suffix .wasm (for wasm) or .js (for asm.js).'
if suffix in shared_suffixes:
self.assertContained(warning, err)
else:
self.assertNotContained(warning, err)
self.assertContainedIf(warning, err, suffix in shared_suffixes)

def test_side_module_without_proper_target(self):
# SIDE_MODULE is only meaningful when compiling to wasm (or js+wasm)
Expand Down Expand Up @@ -7918,10 +7905,7 @@ def test_binaryen_ignore_implicit_traps(self):
cmd = [PYTHON, EMCC, path_from_root('tests', 'hello_libcxx.cpp'), '-s', 'WASM=1', '-O3'] + args
print(' '.join(cmd))
err = run_process(cmd, stdout=PIPE, stderr=PIPE).stderr
if expect:
self.assertContained('--ignore-implicit-traps ', err)
else:
self.assertNotContained('--ignore-implicit-traps ', err)
self.assertContainedIf('--ignore-implicit-traps ', err, expect)
sizes.append(os.path.getsize('a.out.wasm'))
print('sizes:', sizes)
# sizes must be different, as the flag has an impact
Expand Down Expand Up @@ -8390,10 +8374,7 @@ def test_clear_error_on_massive_static_data(self):
def test_o_level_clamp(self):
for level in [3, 4, 20]:
err = run_process([PYTHON, EMCC, '-O' + str(level), path_from_root('tests', 'hello_world.c')], stderr=PIPE).stderr
if level > 3:
self.assertContained("optimization level '-O" + str(level) + "' is not supported; using '-O3' instead", err)
else:
self.assertEqual(err, '')
self.assertContainedIf("optimization level '-O" + str(level) + "' is not supported; using '-O3' instead", err, level > 3)

# Tests that if user specifies multiple -o output directives, then the last one will take precedence
def test_multiple_o_files(self):
Expand Down Expand Up @@ -8528,10 +8509,12 @@ def test(check, extra=[]):
self.assertNotEqual(proc.returncode, 0)
return proc

WARNING = 'Variable dupe declared more than once'

proc = test(check=False)
self.assertContained('ERROR - Variable dupe declared more than once', proc.stderr)
self.assertContained(WARNING, proc.stderr)
proc = test(check=True, extra=['-s', 'IGNORE_CLOSURE_COMPILER_ERRORS=1'])
self.assertEqual(proc.stderr, '')
self.assertNotContained(WARNING, proc.stderr)

def test_closure_full_js_library(self):
# test for closure errors in the entire JS library
Expand Down