summaryrefslogtreecommitdiff
path: root/tools/util.py
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2018-10-11 16:56:50 -0400
committerGitHub <noreply@github.com>2018-10-11 16:56:50 -0400
commitd4f72e18bedda726a74ec0960e59e304055f9039 (patch)
treec73d3d03ea186c5a5bd944cf2204e8ac519ce716 /tools/util.py
parentc814d5a9140d88bf1633b74742e64436e1c75667 (diff)
Improve tools/unit_tests.py (#958)
Checks the output more carefully. The first line of output from js/unit_tests.ts should be something like "running 96 tests" And the last line should be something like "test result: ok. 96 passed; 0 failed; 0 ignored; 0 measured; 36 filtered out" This parses those strings and make sure they align. This will catch silent death bugs.
Diffstat (limited to 'tools/util.py')
-rw-r--r--tools/util.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/tools/util.py b/tools/util.py
index afe4690ce..2620e706f 100644
--- a/tools/util.py
+++ b/tools/util.py
@@ -294,3 +294,33 @@ def enable_ansi_colors_win10():
CloseHandle(conout)
return True
+
+
+def parse_unit_test_output(output, print_to_stdout):
+ first = True
+ expected = None
+ actual = None
+ result = None
+ for line in iter(output.readline, ''):
+ if expected is None:
+ # expect "running 30 tests"
+ expected = extract_number(r'running (\d+) tests', line)
+ elif "test result:" in line:
+ result = line
+ if print_to_stdout:
+ sys.stdout.write(line)
+ sys.stdout.flush()
+ # Check that the number of expected tests equals what was reported at the
+ # bottom.
+ if result:
+ # result should be a string like this:
+ # "test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; ..."
+ actual = extract_number(r'(\d+) passed', result)
+ return (actual, expected)
+
+
+def extract_number(pattern, string):
+ matches = re.findall(pattern, string)
+ if len(matches) != 1:
+ return None
+ return int(matches[0])