-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruntests.py
65 lines (57 loc) · 1.7 KB
/
runtests.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
from subprocess import Popen, PIPE
from os import listdir, path
from functools import total_ordering
from sys import argv
@total_ordering
class NameOrder(object):
def __init__(self, value):
self.value = value
def __eq__(self, other):
return self.value == other.value
def __lt__(self, other):
firstNumber, sep, firstEnding = self.value.partition(".")
firstNumber = firstNumber.partition("/")[2]
secondNumber, sep, secondEnding = other.value.partition(".")
secondNumber = secondNumber.partition("/")[2]
if (firstEnding != secondEnding):
return firstEnding > secondEnding
else:
return int(firstNumber) < int(secondNumber)
def runTests(verbose):
if (not path.isdir("tests/")):
print("No tests directory.")
return
files = sorted(["tests/" + f for f in listdir('tests') if path.isfile("tests/" + f) and f.endswith(".lang")], key=NameOrder)
for f in files:
infile = open(f, 'r')
print("./lang < " + f + ":")
p = Popen(["./lang"], stdin=infile, stdout=PIPE, stderr=PIPE)
(out, err) = p.communicate()
try:
if (verbose):
if (out):
print(out.decode("utf-8"))
if (err):
print(err.decode("utf-8"))
elif (not out):
print("No output.\n")
else:
if (out):
print(out.decode("utf-8"))
if (err):
if (len(err.decode("utf-8").strip().split("\n")) > 1):
print("Multiple errors produced.\n")
else:
line = err.decode("utf-8").strip().split()[-1]
print("Error produced on line " + line + ".\n")
elif (not out):
print("No output.\n")
except UnicodeDecodeError:
print("Invalid characters in output.\n")
def main():
if (len(argv) > 1 and argv[1] == "-v"):
runTests(True)
else:
runTests(False)
if __name__ == "__main__":
main()