Commit dc25542a authored by Christoph Reichenbach's avatar Christoph Reichenbach
Browse files

Incorporated automatic test script for Ex3

parent 4ccee870
import sys
try:
import termcolor
def colored(col, s):
return termcolor.colored(s, col)
except:
def colored(col, s):
return s
if len(sys.argv) < 3:
print("Usage: %s tealprg.expected tealprg.out" % sys.argv[0])
sys.exit(1)
LINE_MERGER={}
class Line(object):
def __init__(self, line):
self.line = line.strip()
self.s = line.split()
self.pos = (self.s[1], self.s[2])
if self.pos[0] in LINE_MERGER:
self.pos = (self.pos[0], LINE_MERGER[self.pos[0]][0]) # normalise column to first column in equiv. set
self.s[2] = self.pos[1]
self.line = ' '.join(self.s)
self.satisfied = False
def points_to_null(self):
return self.s[4] == 'null'
def accept(self, l):
if l == self.line:
# Accept duplicates
self.satisfied = True
return True
return False
def __str__(self):
return self.line
class OptLine(Line):
def __init__(self, line):
Line.__init__(self, line)
# Don't need to see this one
self.satisfied = True
def __str__(self):
return self.line + ' (optional)'
# class ChoiceLine(Line):
# def __init__(self, choices):
# Line.__init__(self, '')
# self.choices = [c.strip() for c in choices]
# def accept(self, l):
# if l in self.choices:
# # Accept duplicates
# self.satisfied = True
# return True
# return False
# def __str__(self):
# return 'One of:\n- ' + '\n- '.join(self.choices)
def parse_line(string, allow_special=False):
l = string.split()
if len(l) == 0:
return None
if not allow_special and string[0] != 'N':
return None
if l[0] == 'merge:':
LINE_MERGER[l[1]] = l[2:]
return None
if l[0] == 'maybe:':
return OptLine(' '.join(l[1:]))
# elif l[0] == 'choice:':
# s = [p.strip() for p in (' '.join(l[1:])).split('|')]
# return ChoiceLine(s)
if string[0] != 'N':
print(colored('red', 'Ill-formed: %s' % string))
return None
return Line(string)
expected = []
with open(sys.argv[1]) as expected_file:
for l in expected_file.readlines():
l = l.strip()
line = parse_line(l, True)
if line is not None:
expected.append(line)
def must_include(line):
return len(line.split()) > 4 and line[0] == 'N'
failure = False
actual = []
with open(sys.argv[2]) as actual_file:
for line in actual_file.readlines():
line = line.strip()
if not must_include(line):
continue
actual.append(line)
# filter out locations that do not point to `null`
null_locs = set()
for line in actual:
if line.strip() == '':
continue
if len(line.split()) != 7:
continue
l = Line(line)
if l.points_to_null():
null_locs.add((l.pos))
for line in actual:
lp = parse_line(line, False)
line = lp.line
loc = lp.pos
# skip non-null info
if not loc in null_locs:
print ('skipping', loc)
continue
if lp is not None:
found = False
for e in expected:
# first check unsatisfied
if not e.satisfied and e.accept(line):
found = True
break
# now check satisfied, allowing for duplicates
if e.accept(line):
found = True
break
if not found:
print(colored('red', line) + ': unexpected!')
failure = True
unsat = False
for e in expected:
if not e.satisfied:
if not unsat:
unsat = True
print("Missing expected output:")
print(colored('yellow', str(e)))
failure = failure or unsat
if failure:
print(colored('red', 'Specification not yet satisfied'))
sys.exit(1)
else:
print(colored('green', 'Clear!'))
sys.exit(0)
merge: 1 7 19
N 4 6 -> null 13 27
N 4 6 -> obj 22 4
N 4 6 -> obj 23 4
N 4 6 -> obj 24 4
N 4 6 -> obj 25 4
NI 9 9 -> obj 6 11
NI 9 9 -> obj 13 21
NI 9 9 -> obj 13 33
NI 9 9 -> obj 14 21
NI 9 9 -> obj 14 25
NI 9 9 -> obj 16 21
NI 9 9 -> null 16 25
NI 9 9 -> obj 22 5
NI 9 9 -> obj 22 8
NI 9 9 -> obj 23 5
NI 9 9 -> obj 23 8
NI 9 9 -> obj 24 5
NI 9 9 -> obj 24 8
NI 9 9 -> obj 25 5
NI 9 9 -> obj 25 8
NI 9 9 -> obj 34 9
N 15 2 -> obj 13 15
N 15 2 -> obj 14 15
N 15 2 -> null 18 7
NO 23 12 -> obj 13 15
NO 23 12 -> obj 14 15
NO 23 12 -> null 18 7
NO 25 12 -> obj 13 15
NO 25 12 -> obj 14 15
NO 25 12 -> obj 16 15
NO 25 12 -> null 18 7
NO 31 2 -> obj 27 12
NO 31 2 -> null 29 10
NA 32 12 -> obj 27 12
NA 32 12 -> null 29 10
NO 35 9 -> obj 13 15
NO 35 9 -> obj 14 15
NO 35 9 -> null 18 7
type T(x : string, y : int);
fun f(a : nonnull array[int], y : int) : int = {
if y < 0 {
return -1;
}
return a[y];
}
fun main() = {
var a : T := new T("", f(null, -1));
var b : T := new T("", 0);
var c : nonnull T := b;
var d : T := new T("", null);
b := null;
d := c;
b := a;
f([1, 2], a.y);
f([1, 2], b.y);
f([1, 2], c.y);
f([1, 2], d.y);
var aa := [];
if 1 {
aa := null;
}
aa[0] := 1;
var bb := aa[0];
a.y := 1;
return b.x;
}
N 4 6 -> obj 14 4 merge: 1 7 19
NI 5 9 -> obj 9 21 NI 5 9 -> obj 9 21
NI 5 9 -> null 9 25 NI 5 9 -> null 9 25
N 10 2 -> obj 9 15 N 10 2 -> obj 9 15
......
merge: 1 10 29
N 1 10 -> null 5 14 N 1 10 -> null 5 14
N 1 10 -> obj 11 29 N 1 10 -> obj 11 29
N 1 10 -> obj 11 32 N 1 10 -> obj 11 32
......
merge: 1 9 18 27
N 8 2 -> obj 4 17 N 8 2 -> obj 4 17
N 8 2 -> obj 4 25 N 8 2 -> obj 4 25
N 8 2 -> obj 4 28 N 8 2 -> obj 4 28
......
#! /bin/bash
N=${1%.teal}
if [ x$N == x ] || [ ${N}.teal != $1 ] ; then
echo "Usage: $0 file.teal"
echo "'$N' vs $1"
exit 1
fi
if [ x${PYTHON} == x ]; then
PYTHON=python
fi
./hw3.sh ${N}.teal | sort -n -k 2,2 -k 3,3 -k 6,6 -k 7,7 > ${N}.out
${PYTHON} compare-hw3.py ${N}.expected ${N}.out
#! /bin/bash #! /bin/bash
java -jar ./compiler/teal-0.jar $1 -Z java -jar ./compiler/teal-2.jar $1 -Z
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment