forked from bengioe/rogue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
92 lines (87 loc) · 3.2 KB
/
test.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# -*- encoding: utf-8 -*-
# je me doute bien que c'est innaproprié de faire du Python dans un
# projet en Scheme, mais j'ai pas assez de temps pour faire ce petit
# script en Scheme, et encore moins en bash/makefile
import os
import subprocess
import sys
from subprocess import Popen, PIPE, STDOUT
untested = []
def scan_file(path):
lines = file(path,'r').read().splitlines()
exp = inp = cmd = ""
for i in lines:
if ";;@" in i:
exp += i[i.rindex(";;@")+4:].strip()+"\n"
if ";;#" in i:
inp += i[i.rindex(";;#")+4:].strip()+"\n"
if ";;&" in i:
if cmd != "":
print
print "Warning, redefining command line arguments for test",path
print "at line",i
cmd = i[i.rindex(";;&")+4:].strip()
return exp,inp,cmd
for i in os.listdir("test"):
sys.stdout.write("."+i)
sys.stdout.flush()
if i.startswith("ok_test") or ("-" in i and i[:i.index('-')].isdigit()):
s = ""
try:
s = subprocess.check_output("./roc test/"+i,
shell=True)
po = ""
expected,pinput,command_line_args = scan_file("test/"+i)
try:
p = Popen(['./out']+command_line_args.split(" "),
stdout=PIPE, stdin=PIPE, stderr=STDOUT)
po = p.communicate(input=pinput)[0]
except subprocess.CalledProcessError,e:
if e.returncode != 0:
print i
print "Unexpected return code:",e.returncode
print "roc output:",s
print e.output
continue
if expected != po:
print i
print "Unexpected output:"
print po
print repr(po)
print "Expected:"
print expected
print repr(expected)
print "roc and asmbler output:",s
except subprocess.CalledProcessError,e:
print "Test should not have failed:",i,e
print s
print e.output
elif i.startswith("fail_test"):
try:
s = subprocess.check_output("./roc test/"+i,
shell=True,
stderr=subprocess.STDOUT)
s += subprocess.check_output("gcc out.s -o out",
shell=True,
stderr=subprocess.STDOUT)
try:
po = subprocess.check_output("./out",
shell=True)
except subprocess.CalledProcessError,e:
if e.returncode == 0:
print i
print "Unexpected return code",e.returncode,"should have been 0"
print s
print e.output
continue
print "Test should have failed:",i
print s
print po
except subprocess.CalledProcessError,e:
pass
else:
untested.append(i)
print
print "End of testing."
if untested:
print "Did not test files:",",".join(untested)