diff --git a/scripts/test/shared.py b/scripts/test/shared.py index 526b125c182..2eb61999091 100644 --- a/scripts/test/shared.py +++ b/scripts/test/shared.py @@ -301,15 +301,11 @@ def remove_readonly_and_try_again(func, path, exc_info): pass -def run_process(cmd, check=True, input=None, decode_output=True, *args, **kwargs): - if input and type(input) is str: - input = bytes(input, 'utf-8') - ret = subprocess.run(cmd, *args, check=check, input=input, **kwargs) - if decode_output and ret.stdout is not None: - ret.stdout = ret.stdout.decode('utf-8') - if ret.stderr is not None: - ret.stderr = ret.stderr.decode('utf-8') - return ret +def run_process(cmd, check=True, text=True, *args, **kw): + """Trivial wrapper around subprocess.run that defaults to check=True and + text=True + """ + return subprocess.run(cmd, check=check, text=text, *args, **kw) def fail_with_error(msg): diff --git a/test/unit/test_features.py b/test/unit/test_features.py index f33328cb488..3bb9ff4e159 100644 --- a/test/unit/test_features.py +++ b/test/unit/test_features.py @@ -421,16 +421,19 @@ def test_explicit_detect_features(self): opts=['-mvp', '--detect-features', '--enable-simd']) def test_emit_all_features(self): + # We use text=False in this test because we pass binary modules via + # stdin and stdout. p = shared.run_process(shared.WASM_OPT + ['--emit-target-features', '-all', '-o', '-'], - input="(module)", check=False, - capture_output=True, decode_output=False) + input=b"(module)", check=False, text=False, + capture_output=True) self.assertEqual(p.returncode, 0) p2 = shared.run_process(shared.WASM_OPT + ['--print-features', '-o', os.devnull], - input=p.stdout, check=False, + input=p.stdout, text=False, check=False, capture_output=True) self.assertEqual(p2.returncode, 0) + output = p2.stdout.debug('utf-8') self.assertEqual([ '--enable-threads', '--enable-mutable-globals', @@ -454,4 +457,4 @@ def test_emit_all_features(self): '--enable-bulk-memory-opt', '--enable-call-indirect-overlong', '--enable-custom-descriptors', - ], p2.stdout.splitlines()) + ], output.splitlines())