-
Notifications
You must be signed in to change notification settings - Fork 25
/
test.py
81 lines (59 loc) · 1.71 KB
/
test.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
import difflib
import glob
import os.path
import subprocess
import sys
def output_of(args):
return subprocess.check_output(args).decode('ascii', 'ignore').split("\n")
testcases = []
test_path = "test"
if len(sys.argv) > 1:
test_path = sys.argv[1]
if os.path.isdir(test_path):
for root, dirs, files in os.walk(test_path):
for file in files:
if not file.endswith(".py"):
continue
testcase = os.path.join(root, file)
testcases.append(testcase)
else:
testcases.append(test_path)
testcases.sort()
errors = []
failures = []
for testcase in testcases:
try:
#print("Testing %s..." % testcase.replace("test/", ""))
python_cmdline = ["python3", testcase]
python_output = output_of(python_cmdline)
hython_cmdline = ["./hython", testcase]
hython_output = output_of(hython_cmdline)
if python_output == hython_output:
sys.stdout.write(".")
sys.stdout.flush()
else:
sys.stdout.write("F")
sys.stdout.flush()
diff = difflib.unified_diff(python_output, hython_output, lineterm='',
fromfile=" ".join(python_cmdline), tofile=" ".join(hython_cmdline))
failures.append(diff)
except subprocess.CalledProcessError as e:
#print(dir(e))
#print(e.stderr)
#sys.exit(1)
sys.stdout.write("E")
sys.stdout.flush()
errors.append(testcase)
print('')
if failures:
print()
print("Failures:")
for failure in failures:
print("\n".join(failure))
print()
if errors:
print("Errors:")
for error in errors:
print(error)
if errors or failures:
sys.exit(1)