-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_parser.py
executable file
·46 lines (37 loc) · 1.45 KB
/
test_parser.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
#!/bin/python3
from termcolor import colored
from os import listdir, environ
import subprocess
GrosMathExecPath = "./GroMath"
testsPath = "tests/parser/"
tests = listdir(testsPath)
tn_lens = []
descs = []
descs_lens = []
for test in tests:
tn_lens.append(len(test))
with open(testsPath + test, "r") as f:
descs.append(f.readline()[2:].strip())
descs_lens.append(len(descs[-1]))
m_lens = max(tn_lens)
m_decs = max(descs_lens)
def pad(s, l):
assert len(s) <= l, "cant pad, string is too long"
pl = l - len(s)
return s + " " * (pl)
test_env = dict(environ) | {"TEST_PARSER": "1"}
success = 0
for test_id, test in enumerate(tests):
print(colored(f"[+] Test {test_id + 1} | {pad(test, m_lens)} | {pad(descs[test_id], m_decs)} | ", "blue"), end="")
comm = [GrosMathExecPath, testsPath + test]
tr = subprocess.run(comm, capture_output=True, env=test_env)
out = tr.stderr.decode().strip()
if tr.returncode != 0 or "error" in out.lower():
print(colored(f"FAILED !! with retcode : {tr.returncode}", "red", attrs=["bold"]))
for l in out.split("\n")[:2] + ["..."] + out.split("\n")[-5:]:
print(colored(" ↳ " + l, "red"))
print(colored(" [!] Command to use to reproduce error : " + " ".join(comm), "red", attrs=["bold"]))
else:
success += 1
print(colored("SUCCESS !!", "green"))
print(colored(f"[+] Result : {success} / {len(tests)} successful !", "light_magenta"))