diff options
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/check_output_test.py | 16 | ||||
-rw-r--r-- | tools/util.py | 11 | ||||
-rw-r--r-- | tools/util_test.py | 14 |
3 files changed, 33 insertions, 8 deletions
diff --git a/tools/check_output_test.py b/tools/check_output_test.py index cba3b0c56..54aff4e0c 100755 --- a/tools/check_output_test.py +++ b/tools/check_output_test.py @@ -7,7 +7,7 @@ import os import sys import subprocess -from util import pattern_match +from util import pattern_match, parse_exit_code root_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) tests_path = os.path.join(root_path, "tests") @@ -27,21 +27,23 @@ def check_output_test(deno_exe_filename): with open(out_abs, 'r') as f: expected_out = f.read() cmd = [deno_exe_filename, script_abs] - should_succeed = "error" not in script + expected_code = parse_exit_code(script) print " ".join(cmd) - err = False + actual_code = 0 try: actual_out = subprocess.check_output(cmd, universal_newlines=True) except subprocess.CalledProcessError as e: - err = True + actual_code = e.returncode actual_out = e.output - if should_succeed == True: + if expected_code == 0: print "Expected success but got error. Output:" print actual_out sys.exit(1) - if should_succeed == False and err == False: - print "Expected an error but succeeded. Output:" + if expected_code != actual_code: + print "Expected exit code %d but got %d" % (expected_code, + actual_code) + print "Output:" print actual_out sys.exit(1) diff --git a/tools/util.py b/tools/util.py index 9e29cf742..b50b754c2 100644 --- a/tools/util.py +++ b/tools/util.py @@ -1,5 +1,6 @@ # Copyright 2018 the Deno authors. All rights reserved. MIT license. import os +import re import shutil import stat import sys @@ -162,3 +163,13 @@ def pattern_match(pattern, string, wildcard="[WILDCARD]"): string = string[(found + len(parts[i])):] return len(string) == 0 + + +def parse_exit_code(s): + codes = [int(d or 1) for d in re.findall(r'error(\d*)', s)] + if len(codes) > 1: + assert False, "doesn't support multiple error codes." + elif len(codes) == 1: + return codes[0] + else: + return 0 diff --git a/tools/util_test.py b/tools/util_test.py index 3315a4eaf..308951bc2 100644 --- a/tools/util_test.py +++ b/tools/util_test.py @@ -1,5 +1,5 @@ # Copyright 2018 the Deno authors. All rights reserved. MIT license. -from util import pattern_match +from util import pattern_match, parse_exit_code def pattern_match_test(): @@ -27,5 +27,17 @@ def pattern_match_test(): "[BAR]") == False, "expected wildcard to be set" +def parse_exit_code_test(): + print "Testing util.parse_exit_code()..." + assert 54 == parse_exit_code('hello_error54_world') + assert 1 == parse_exit_code('hello_error_world') + assert 0 == parse_exit_code('hello_world') + + def util_test(): pattern_match_test() + parse_exit_code_test() + + +if __name__ == '__main__': + util_test() |