-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_tests.py
executable file
·38 lines (36 loc) · 1.73 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
#!/usr/bin/env python3
import json
import subprocess
import platform
import tempfile
import sys
if __name__ == "__main__":
if platform.system() == "Windows":
subprocess.run(["cmd.exe", "gradlew.bat", "jar"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
else:
subprocess.run(["./gradlew", "jar"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
config = json.loads(open("tests/config.json", "r").read())
successfulTests = 0
for test in config:
print(test["name"], ": ", end='', sep='')
with tempfile.TemporaryDirectory() as tempdir:
status = subprocess.run(["java", "-jar", "build/libs/compiler-lt2018.jar", "tests/" + test["source"], "-o", tempdir + "/output.bin"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if (test["compileShouldFail"] and status.returncode == 0) or (not test["compileShouldFail"] and status.returncode != 0):
print("FAIL (compile error)")
continue
if test["compileShouldFail"]:
print("OK")
successfulTests += 1
continue
status = subprocess.run([tempdir + "/output.bin"], input=test["input"].encode(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if status.returncode != 0:
print("FAIL (non-zero return code)")
if test["output"] == status.stdout.decode():
print("OK")
successfulTests += 1
else:
print("FAIL (different output)")
totalTests = len(config)
failedTests = totalTests - successfulTests
print("%d test(s) ran - %d passed, %d failed" % (totalTests, successfulTests, failedTests))
sys.exit(0 if successfulTests == totalTests else 1)