-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
143 lines (125 loc) · 3.13 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
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
from subprocess import Popen, PIPE
from os import environ
from sys import argv
files_all_checks = [
"addition",
"append",
"cmpop",
"control",
"factorial",
"fibonacci",
"forin",
"map",
"mutate",
"sample2",
"sample3",
"sample4",
"sample",
"simple",
"sort",
"store",
"tuple",
"while",
"rule110",
"bitwise",
"cast",
"graph",
"seive",
"adt",
"tree",
"syncchan",
"string_indexing",
"match",
]
files_retcode_check = [
# "chan",
# "coroutine",
]
byte_mode = 0
aot_mode = 1
go_mode = 2
passing = {
byte_mode: 0,
aot_mode: 0,
go_mode: 0,
}
total = len(files_all_checks) + len(files_retcode_check)
mode_to_str = {
byte_mode: "byte",
aot_mode: "aot",
go_mode: "go",
}
str_to_mode = {
"byte": byte_mode,
"aot": aot_mode,
"go": go_mode,
}
def passed(file, mode):
global passing
passing[mode] += 1
print(f"{file} passed")
def failed(file, mode, msg=""):
print(f"{file} failed in {mode_to_str[mode]}")
if msg:
print(msg)
def run_file(mode, file, only_rc_check=False):
modestr = mode_to_str[mode]
print(f"running {file} in {modestr}")
p = Popen([f"./run_{modestr}.sh", f"samples/{file}.sahl"], stdout=PIPE, stderr=PIPE)
output, err = p.communicate(b"")
# # dont check rc for aot
rc = p.returncode
if rc != 0:
failed(file, mode, err)
return
if only_rc_check:
passed(file, mode)
return
output = output.decode("utf-8")
with open(f"tests/{file}", "r") as f:
expected = f.read()
if expected == output:
passed(file, mode)
else:
failed(file, mode)
def run_all(mode):
for file in files_all_checks:
run_file(mode, file)
for file in files_retcode_check:
run_file(mode, file, True)
def result(mode):
print(f"{passing[mode]}/{total} {mode_to_str[mode]} tests passed")
modes = [byte_mode, aot_mode, go_mode]
if __name__ == "__main__":
if len(argv) > 1:
if argv[1] in str_to_mode:
m = str_to_mode[argv[1]]
run_all(m)
result(m)
elif argv[1] in files_all_checks:
run_file(byte_mode, argv[1])
run_file(aot_mode, argv[1])
run_file(go_mode, argv[1])
elif argv[1] in files_retcode_check:
run_file(byte_mode, argv[1], True)
run_file(aot_mode, argv[1], True)
run_file(go_mode, argv[1], True)
exit(0)
modes = [
byte_mode,
aot_mode,
go_mode,
]
for mode in modes:
run_all(mode)
for mode in modes:
result(mode)
if not "GITHUB_ENV" in environ:
exit(0)
with open(environ["GITHUB_ENV"], "w") as f:
f.write(f"TEST_RESULT={passing[byte_mode]}/{total}\n")
f.write(f"COLOR={int((passing[byte_mode] / total) * 100)}\n")
f.write(f"AOT_TEST_RESULT={passing[aot_mode]}/{total}\n")
f.write(f"AOT_COLOR={int((passing[aot_mode] / total) * 100)}\n")
f.write(f"GO_TEST_RESULT={passing[go_mode]}/{total}\n")
f.write(f"GO_COLOR={int((passing[go_mode] / total) * 100)}\n")