-
Notifications
You must be signed in to change notification settings - Fork 146
/
run_tests.py
executable file
·72 lines (58 loc) · 1.53 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
#!/usr/bin/env python3
import re
import sys
import json
import subprocess
executable = "${TESTPROG}"
def parse_test(raw):
raw = re.compile('#.*$', re.M).sub('', raw).strip()
if raw.startswith('"""'):
raw = raw[3:]
for fixture in raw.split('r"""'):
name = ''
doc, _, body = fixture.partition('"""')
cases = []
for case in body.split('$')[1:]:
argv, _, expect = case.strip().partition('\n')
expect = json.loads(expect)
prog, _, argv = argv.strip().partition(' ')
cases.append((prog, argv, expect))
yield name, doc, cases
failures = 0
passes = 0
tests = open('${TESTCASES}','r').read()
for _, doc, cases in parse_test(tests):
if not cases: continue
for prog, argv, expect in cases:
args = [ x for x in argv.split() if x ]
expect_error = not isinstance(expect, dict)
error = None
out = None
try:
out = subprocess.check_output([executable, doc]+args, stderr=subprocess.STDOUT)
if expect_error:
error = " ** an error was expected but it appeared to succeed!"
else:
json_out = json.loads(out)
if expect != json_out:
error = " ** JSON does not match expected: %r" % expect
except subprocess.CalledProcessError as e:
if not expect_error:
error = "\n ** this should have succeeded! exit code = %s" % e.returncode
if not error:
passes += 1
continue
failures += 1
print("="*40)
print(doc)
print(':'*20)
print(prog, argv)
print('-'*20)
if out:
print(out)
print(error)
if failures:
print("%d failures" % failures)
sys.exit(1)
else:
print("PASS (%d)" % passes)