Skip to content

Commit b0d7fa6

Browse files
committed
Improve binaryenjs testing
- Add optional message to assert helper - When a subprocess fails we should show both its stdout and stderr. In the case when stderr was being captured we were not showing it at all. I think it makes sense to simply forward this rather than embed it in the thrown exception.
1 parent b9a2c29 commit b0d7fa6

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

scripts/test/binaryenjs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ def make_js_test_header(binaryen_js):
2828
// avoid stdout/stderr ordering issues in some js shells - use just stdout
2929
console.warn = console.error = console.log;
3030
31-
function assert(x) {{
32-
if (!x) throw Error('Test assertion failed');
31+
function assert(cond, msg='') {{
32+
if (!cond) throw Error('Test assertion failed: ' + msg);
3333
}}
3434
'''
3535

scripts/test/support.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import io
1717
import os
1818
import re
19+
import shlex
1920
import shutil
2021
import subprocess
2122
import sys
@@ -224,13 +225,17 @@ def run_command(cmd, expected_status=0, stdout=None, stderr=None,
224225
out, err, code = _subprocess_run(cmd, stdout=subprocess.PIPE, stderr=stderr, encoding='UTF-8')
225226

226227
if expected_status is not None and code != expected_status:
227-
raise Exception(f"run_command `{' '.join(cmd)}` failed ({code}) {err or ''}")
228+
if out:
229+
print(out)
230+
if err:
231+
print(out, file=sys.stderr)
232+
raise subprocess.CalledProcessError(f"run_command `{shlex.join(cmd)}` failed ({code})")
228233
if expected_err is not None:
229234
if err_ignore is not None:
230235
err = "\n".join([line for line in err.split('\n') if err_ignore not in line])
231236
err_correct = expected_err in err if err_contains else expected_err == err
232237
if not err_correct:
233-
raise Exception(f"run_command unexpected stderr. Expected '{expected_err}', actual '{err}'")
238+
raise subprocess.CalledProcessError(f"run_command unexpected stderr. Expected '{expected_err}', actual '{err}'")
234239
return out
235240

236241

test/binaryen.js/errors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ try {
1111
assert(e.message === '3:16: error: unrecognized instruction');
1212
caughtAsExpected = true;
1313
}
14-
assert(caughtAsExpected);
14+
assert(caughtAsExpected, 'no exception caught');
1515

1616
console.log('success.');
1717

0 commit comments

Comments
 (0)