-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
98 lines (89 loc) · 2.82 KB
/
tests.py
File metadata and controls
98 lines (89 loc) · 2.82 KB
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
from genericpath import exists
import os
import sys
import asyncio
def genTest(file):
print(f"Generating Tests for: {file}")
test_file = file
ret = os.system("sclc " + test_file)
if ret != 0:
print(f"Error generating tests for: {file}")
sys.exit(1)
output = os.popen("./out.scl").read()
if exists("output.txt"):
os.remove("output.txt")
with open("output.txt", "w") as f:
f.write(output)
def runTest(file, directory="examples", current=1, total=1):
global failedTests
global theseTestsFailed
global passedTests
global skippedTests
test_file = directory + "/" + file
curDir = os.path.abspath(os.path.curdir)
os.chdir(test_file)
print(f"[COMP] {file}")
compOut = os.popen("sclc main.scale").read()
print(f"[RUN] {file} ({current}/{total})")
output = os.popen("./out.scl").read()
if not exists("output.txt"):
print(f"[SKIP] {file}")
genTest(f"main.scale")
skippedTests += 1
os.chdir(curDir)
return
with open("output.txt", "r") as f:
expected = f.read()
if output == expected:
print(f"[PASS] {file}")
passedTests += 1
else:
print(f"\b[FAIL] {file}")
failedTests += 1
theseTestsFailed.append(file)
print("Compiler Output:")
print(compOut)
print(f"Program Output (characters: {len(output)}):")
print(output)
print(f"Expected Output (characters: {len(expected)}):")
print(expected)
os.remove("./out.scl")
os.chdir(curDir)
# loop over every file in the directory examples
# and run the tests on each file
def run_tests(directory):
tests = [ i for i in os.listdir(directory) if i[0] != '.' ]
tests.sort()
current = 1
try:
for file in tests:
runTest(file, current=current, total=len(tests))
current += 1
except KeyboardInterrupt:
pass
total = passedTests + failedTests + skippedTests
print("Passed: " + str(passedTests) + "/" + str(total))
print("Failed: " + str(failedTests) + "/" + str(total) + " " + str(theseTestsFailed))
print("Skipped: " + str(skippedTests) + "/" + str(total))
# Reset the tests
def reset_tests(directory):
tests = [ i for i in os.listdir(directory) if i.endswith(".scale") ]
tests.sort()
for file in tests:
genTest(f"{directory}/{file}")
if __name__ == '__main__':
failedTests = 0
theseTestsFailed = []
passedTests = 0
skippedTests = 0
if len(sys.argv) != 2:
print("Usage: python3 tests.py [run|reset]")
sys.exit(1)
else:
if sys.argv[1] == "reset":
reset_tests("examples")
elif sys.argv[1] == "run":
run_tests("examples")
else:
print("Usage: python3 tests.py [run|reset]")
sys.exit(1)