This repository has been archived by the owner on Nov 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathrun_tests.py
executable file
·77 lines (59 loc) · 1.98 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
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
#!/usr/bin/env python
from os import walk, unlink
from subprocess import Popen, PIPE
class colors:
HEADER = '\033[95m'
OK = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
END = '\033[0m'
def get_test_files():
filelist = []
for (dirpath, dirnames, filenames) in walk("tests/"):
filelist.extend(filenames)
return filelist
def run():
stdlib = open("stdlib.rh").read()
tests = get_test_files()
no_tests = len(tests)
no_successes = 0
print colors.HEADER
print "--------------------------"
print "RUNNING TESTS..."
print "--------------------------"
print colors.END
for filename in tests:
if filename.startswith("output.") or not filename.endswith(".rht"):
no_tests -= 1
continue
contents = open("tests/"+filename).read().split("---")
test_input = contents[0].strip()
expected_output = "---".join(contents[1:]).strip()
p = Popen(["./rhine", "-"], stdin=PIPE, stdout=PIPE, stderr=PIPE)
stdout, stderr = p.communicate(stdlib+"\n"+test_input)
stdout = stdout
stderr = stderr
if stderr.find(expected_output) >= 0 or stdout.find(expected_output) >= 0:
no_successes += 1
try:
unlink('tests/output.'+filename)
except OSError:
pass
print "%s %s: SUCCESS%s" % (colors.OK, filename, colors.END)
else:
f = open('tests/output.'+filename,'w')
f.write(stdout+stderr)
f.close()
print "%s %s: FAILED (output written to tests/)" % (colors.FAIL, filename)
if no_successes == no_tests:
print colors.OK
else:
print colors.FAIL
print "--------------------------"
print "TOTAL TESTS: %i" % no_tests
print "SUCCESSES: %i" % no_successes
print "FAILS: %i" % (no_tests - no_successes)
print "--------------------------"
print colors.END
if __name__ == "__main__":
run()