-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_tests.py
166 lines (139 loc) · 4.84 KB
/
run_tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import sys
from os.path import basename, splitext
import subprocess
class Color:
OK = '\033[92m'
WARN = '\033[93m'
ERR = '\033[91m'
INFO = '\033[96m'
END = '\33[0m'
def main(test_suites):
tests_crashed = []
tests_passed = []
tests_failed = []
tests_ignored = []
# Empty line to clean up makefile output a bit.
print()
# Print message and exit if there where no tests passed:
if len(test_suites) == 0:
print("No test suites specified.")
sys.exit(0)
# Run every test
for test_suite in test_suites:
test_suite_name = splitext(basename(test_suite))[0]
print("Running test suite %s..." % test_suite_name)
test_output = subprocess.run(test_suite, capture_output=True)
suite_output = test_output.stdout.decode()
suite_fail_count = 0
if '-----------------------' not in suite_output:
# Test suite crashed
print(Color.ERR, end='')
print("Test suite %s crashed, test results not reported!" %
test_suite_name)
print(Color.END, end='')
tests_crashed.append(test_suite_name)
else:
# Test suite completed
# Save output to .test file:
with open(splitext(test_suite)[0] + '.test', 'w') as report:
report.write(suite_output)
# Separate and sort tests:
for line in suite_output.split('\n'):
if line == '' or line == '-----------------------':
# Report finished
break
elif ':PASS' in line:
tests_passed.append(line)
elif ':FAIL' in line:
tests_failed.append(line)
suite_fail_count += 1
elif ':IGNORE' in line:
tests_ignored.append(line)
elif ':INFO' in line:
print(Color.INFO, end='')
print(line)
print(Color.END, end='')
else:
print(Color.WARN, end='')
print("Error parsing test output '%s', ignoring line. Did the test crash?"
% line)
print(Color.END, end='')
# Unity test suites return the number of failed tests.
# Make sure that matches what we parsed above:
failed_tests_unity_report = test_output.returncode
if suite_fail_count != failed_tests_unity_report:
print(Color.WARN, end='')
print("Unity report %i failed tests, but %i where tracked by the test output." % (
failed_tests_unity_report, suite_fail_count))
print("Verify test suite output manually!")
print(Color.END, end='')
# Print summary:
crashes = len(tests_crashed)
passes = len(tests_passed)
fails = len(tests_failed)
ignores = len(tests_ignored)
tests = passes + fails + ignores
print()
print()
print("============= Summary =============")
if crashes != 0:
print(Color.ERR, end='')
print("Warning! %i test suite(s) crashed. Not all tests were performed!" % crashes)
print(Color.END, end='')
print("Ran %i tests." % tests)
print(Color.ERR, end='')
print("Failed: %i" % fails)
print(Color.END + Color.OK, end='')
print("Passed: %i" % passes)
print(Color.END + Color.WARN, end='')
print("Ignore: %i" % ignores)
print(Color.END, end='')
if (tests - ignores) != 0:
print("Success rate (without ignored tests): %2.2f%%" %
(float(passes) / (tests - ignores) * 100))
print()
print("============ Breakdown ============")
if crashes != 0:
print("Crashed test suites (%i):" % crashes)
print(Color.ERR, end='')
for suite in tests_crashed:
print(suite)
print(Color.END, end='')
print()
print("Failed (%i): " % fails)
for test in tests_failed:
print(Color.ERR, end='')
print(test)
print(Color.END, end='')
print()
print("Ignored (%i): " % ignores)
for test in tests_ignored:
print(Color.WARN, end='')
print(test)
print(Color.END, end='')
print()
print("Passed (%i): " % passes)
if passes <= 50:
for test in tests_passed:
print(test)
else:
print('...')
print("===================================")
if crashes == 0 and fails == 0:
print(Color.OK, end='')
print("All good! :)")
print(Color.END)
print()
print()
sys.exit(0)
else:
print(Color.WARN, end='')
print("There is some work left to do...")
print(Color.END, end='')
print()
print()
sys.exit(1)
if __name__ == '__main__':
args = sys.argv.copy()
path = args.pop(0)
main(args)