-
Notifications
You must be signed in to change notification settings - Fork 3
/
testtypes.sh
executable file
·88 lines (78 loc) · 2.94 KB
/
testtypes.sh
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
tempfoo=`basename $0`
rm -rf $TMPDIR/$tempfoo.*
OUTDIR=`mktemp -d -t ${tempfoo}`
./buildparser.sh || exit 1
go build cmd/typecheck/typecheck.go || exit 1
GOOD_FILES='simplearith basicclassestree expressionblock objectdispatchabort initwithself compare comparisons cycleinmethods letnoinit forwardinherits letinit newselftype basic overridingmethod letshadows neg methodcallsitself overriderenamearg isvoid overridingmethod3 inheritsObject scopes letselftype if methodnameclash trickyatdispatch stringtest overridingmethod2 simplecase assignment subtypemethodreturn dispatch io staticdispatch classes hairyscary.cl cells.cl list.cl'
GOOD_EXTRAS='case-none.cl mainmethod-missing mainmethod-wrong if-self-type'
BAD_FILES='nomain badredefineint inheritsselftype returntypenoexist letself badmethodcallsitself badarith outofscope selftypeparameterposition missingclass selftypebadreturn attroverride selftyperedeclared badequalitytest2 badequalitytest dupformals self-assignment selfinformalparameter badwhilecond assignnoconform caseidenticalbranch inheritsbool inheritsstring badwhilebody anattributenamedself attrbadinit redefinedclass redefinedobject signaturechange trickyatdispatch2 letbadinit badargs1 overridingmethod4 badstaticdispatch baddispatch lubtest'
# Expected passing tests: if we get a fail on one of these, we diff and exit immediately.
PASSING='badredefineint inheritsbool inheritsselftype inheritsstring nomain redefinedclass redefinedobject selftyperedeclared missingclass anattributenamedself attroverride redefinedclass signaturechange dupformals selfinformalparameter selftypeparameterposition'
CORRECT=0
INCORRECT=0
BADNAME=''
BADWANT=''
BADGOT=''
succeed ()
{
CORRECT=$((CORRECT+1))
echo " ok"
return 0
}
fail ()
{
INCORRECT=$((INCORRECT+1))
echo " FAIL"
if [[ $BADNAME == '' ]]
then
BADNAME=$1
BADWANT=testdata/typecheck/$1.test.out
BADGOT=$OUTDIR/$1.test.out
fi
return 1
}
unexpectedfail ()
{
echo " FAIL (unexpected)"
diff -u testdata/typecheck/$1.test.out $OUTDIR/$1.test.out
exit 1
}
echo "---- BAD INPUT ----"
for i in $BAD_FILES
do
echo -n "$i..."
./typecheck testdata/typecheck/$i.test > $OUTDIR/$i.test.out 2>&1
if cmp -s testdata/typecheck/$i.test.out $OUTDIR/$i.test.out
then
succeed
else
[[ " $PASSING " == *" $i "* ]] && unexpectedfail $i
fail $i
fi
done
echo "---- GOOD INPUT ----"
for i in $GOOD_FILES $GOOD_EXTRAS
do
echo -n "$i..."
./typecheck testdata/typecheck/$i.test > $OUTDIR/$i.test.out 2>&1
if cmp -s testdata/typecheck/$i.test.out $OUTDIR/$i.test.out
then
succeed
else
[[ " $PASSING " == *" $i "* ]] && unexpectedfail $i
fail $i
fi
done
if [[ $INCORRECT == 0 ]]
then
echo "($CORRECT/$((CORRECT+INCORRECT)))"
echo "ok"
else
echo -e "\nFirst failure: $BADNAME"
diff -u $BADWANT $BADGOT
echo "($CORRECT/$((CORRECT+INCORRECT)))"
echo "FAIL"
exit 1
fi
rm -r $OUTDIR
rm -f ./typecheck