-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_tests
executable file
·48 lines (37 loc) · 1.38 KB
/
run_tests
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
#!/usr/bin/python3
import glob
import os.path
import subprocess
import sys
if len(sys.argv)!=3:
print("Wrong number of arguments. Run through \"make test\" instead", file=sys.stderr)
sys.exit(1)
print("Running tests on directory", sys.argv[2])
numFailed=0
numPassed=0
testNames = glob.glob( os.path.join(sys.argv[2], "*.pr.res") )
testNames.sort()
for resultFileName in testNames:
sourceFileName = os.path.splitext(resultFileName)[0]
testResult = subprocess.run(
[sys.argv[1], sourceFileName], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, check=False)
if testResult.returncode<0:
print(os.path.basename(sourceFileName), "\033[41;97mCrashed\033[m")
numFailed=numFailed+1
continue
if testResult.returncode!=0:
print(os.path.basename(sourceFileName), "\033[91mCompilation failed\033[m")
numFailed=numFailed+1
continue
with open(resultFileName) as resultFile:
expectedResult = resultFile.read()
if testResult.stdout==expectedResult:
print(os.path.basename(sourceFileName), "\033[32mSuccess\033[m")
numPassed=numPassed+1
else:
print(os.path.basename(sourceFileName), "\033[93mWrong result\033[m")
numFailed=numFailed+1
print()
print(numFailed+numPassed, "tests run,", numPassed, "passed and", numFailed, "failed")
if numFailed!=0:
exit(2)