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
8 changes: 3 additions & 5 deletions tests/check_emcc_help_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import os
import subprocess
import sys
from pathlib import Path

root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

Expand All @@ -21,11 +22,8 @@ def main():
print('doc build output not found: %s' % build_output)
return 1

with open(build_output, 'r') as f:
emcc_docs_output = f.read()

with open(docs_file, 'r') as f:
emcc_docs = f.read()
emcc_docs_output = Path(build_output).read_text()
emcc_docs = Path(docs_file).read_text()

if emcc_docs_output != emcc_docs:
print('contents of checked in docs/emcc.txt does not match build output:')
Expand Down
52 changes: 29 additions & 23 deletions tests/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def path_from_root(*pathelems):

TEST_ROOT = path_from_root('tests')

WEBIDL_BINDER = shared.bat_suffix(path_from_root('tools', 'webidl_binder'))
WEBIDL_BINDER = shared.bat_suffix(path_from_root('tools/webidl_binder'))


if EMTEST_VERBOSE:
Expand All @@ -115,6 +115,14 @@ def test_file(*path_components):
return str(Path(TEST_ROOT, *path_components))


def read_file(*path_components):
return Path(*path_components).read_text()


def read_binary(*path_components):
return Path(*path_components).read_bytes()


# checks if browser testing is enabled
def has_browser():
return EMTEST_BROWSER != '0'
Expand Down Expand Up @@ -609,7 +617,7 @@ def build(self, filename, libraries=[], includes=[], force_c=False,
post_build(output)

if js_outfile and self.uses_memory_init_file():
src = open(output).read()
src = read_file(output)
# side memory init file, or an empty one in the js
assert ('/* memory initializer */' not in src) or ('/* memory initializer */ allocate([]' in src)

Expand All @@ -636,8 +644,8 @@ def count_funcs(self, javascript_file):
start_off = 0
end_off = 0

with open(javascript_file, 'rt') as f:
blob = "".join(f.readlines())
js = read_file(javascript_file)
blob = "".join(js.splitlines())

start_off = blob.find(start_tok) + len(start_tok)
end_off = blob.find(end_tok)
Expand Down Expand Up @@ -687,8 +695,8 @@ def run_js(self, filename, engine=None, args=[], output_nicerizer=None, assert_r
if not filename.endswith('.wasm'):
self.assertEqual(line_endings.check_line_endings(filename), 0)

out = open(stdout, 'r').read()
err = open(stderr, 'r').read()
out = read_file(stdout)
err = read_file(stderr)
if output_nicerizer:
ret = output_nicerizer(out, err)
else:
Expand Down Expand Up @@ -790,8 +798,8 @@ def assertContainedIf(self, value, string, condition):
def assertBinaryEqual(self, file1, file2):
self.assertEqual(os.path.getsize(file1),
os.path.getsize(file2))
self.assertEqual(open(file1, 'rb').read(),
open(file2, 'rb').read())
self.assertEqual(read_binary(file1),
read_binary(file2))

library_cache = {}

Expand Down Expand Up @@ -1028,12 +1036,12 @@ def do_runf(self, filename, expected_output=None, **kwargs):

## Just like `do_run` but with filename of expected output
def do_run_from_file(self, filename, expected_output_filename, **kwargs):
self._build_and_run(filename, open(expected_output_filename).read(), **kwargs)
self._build_and_run(filename, read_file(expected_output_filename), **kwargs)

def do_run_in_out_file_test(self, *path, **kwargs):
srcfile = test_file(*path)
outfile = shared.unsuffixed(srcfile) + '.out'
expected = open(outfile).read()
expected = read_file(outfile)
self._build_and_run(srcfile, expected, **kwargs)

## Does a complete test - builds, runs, checks output, etc.
Expand Down Expand Up @@ -1180,7 +1188,7 @@ def do_GET(self):
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
self.wfile.write(open(test_file('browser_harness.html'), 'rb').read())
self.wfile.write(read_binary(test_file('browser_harness.html')))
elif 'report_' in self.path:
# the test is reporting its result. first change dir away from the
# test dir, as it will be deleted now that the test is finishing, and
Expand Down Expand Up @@ -1412,9 +1420,9 @@ def reftest(self, expected, manually_trigger=False):
# pngcrush -rem gAMA -rem cHRM -rem iCCP -rem sRGB infile outfile
basename = os.path.basename(expected)
shutil.copyfile(expected, os.path.join(self.get_dir(), basename))
reporting = read_file(test_file('browser_reporting.js'))
with open('reftest.js', 'w') as out:
with open(test_file('browser_reporting.js')) as reporting:
out.write('''
out.write('''
function doReftest() {
if (doReftest.done) return;
doReftest.done = true;
Expand Down Expand Up @@ -1510,7 +1518,7 @@ def reftest(self, expected, manually_trigger=False):
setTimeout(realDoReftest, 1);
};
}
''' % (reporting.read(), basename, int(manually_trigger)))
''' % (reporting, basename, int(manually_trigger)))

def compile_btest(self, args, reporting=Reporting.FULL):
# Inject support code for reporting results. This adds an include a header so testcases can
Expand Down Expand Up @@ -1642,14 +1650,12 @@ def build_library(name,
shared.run_process(configure, env=env, stdout=stdout, stderr=stderr,
cwd=project_dir)
except subprocess.CalledProcessError:
with open(os.path.join(project_dir, 'configure_out')) as f:
print('-- configure stdout --')
print(f.read())
print('-- end configure stdout --')
with open(os.path.join(project_dir, 'configure_err')) as f:
print('-- configure stderr --')
print(f.read())
print('-- end configure stderr --')
print('-- configure stdout --')
print(read_file(Path(project_dir, 'configure_out')))
print('-- end configure stdout --')
print('-- configure stderr --')
print(read_file(Path(project_dir, 'configure_err')))
print('-- end configure stderr --')
raise

def open_make_out(mode='r'):
Expand Down Expand Up @@ -1683,7 +1689,7 @@ def open_make_err(mode='r'):
cache[cache_name] = []
for f in generated_libs:
basename = os.path.basename(f)
cache[cache_name].append((basename, open(f, 'rb').read()))
cache[cache_name].append((basename, read_binary(f)))

return generated_libs

Expand Down
Loading