-
Notifications
You must be signed in to change notification settings - Fork 0
/
test
159 lines (129 loc) · 3.3 KB
/
test
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/env sh
# configuration
TEST_SUFFIX="lang"
TEST_REFERENCE_COMPILATION_OUTPUT_SUFFIX="compile.out"
TEST_COMPILED_SUFFIX="compiled"
TEST_RUN_STDIN_SUFFIX="run.in"
TEST_RUN_REFERENCE_STDOUT_SUFFIX="run.out"
TEST_RUN_FAIL_SUFFIX="run.fail"
testcases="none"
single="no"
if [ $# -eq 0 ]
then
echo "Doing all testcases."
echo
testcases=$(find tests -type f -name "*.$TEST_SUFFIX")
# reset fails
echo -n > fails
elif [ $1 = "fails" ]
then
if [ -e fails ]
then
echo "Doing only failed testcases."
echo
testcases=$(cat fails)
else
echo "Couldn't find fails file! Doing all testcases."
testcases=$(find tests -type f -name "*.$TEST_SUFFIX")
fi
# reset fails
echo -n > fails
else
single="yes"
testcases=$1
echo "Doing testcase $testcases."
echo
fi
testcases=$(echo "$testcases" | sed "s/\.$TEST_SUFFIX$//" | sed "s/^\.\///")
pass=0
fail=0
total=0
# go over all testcases:
for testcase in $testcases
do
language=$(echo $testcase | awk -F'/' '{ print $2 }')
echo -n "Testcase $testcase ... "
ret=0
if [ -e $testcase.$TEST_REFERENCE_COMPILATION_OUTPUT_SUFFIX ]
then
if [ "FAIL" = "$(cat $testcase.$TEST_REFERENCE_COMPILATION_OUTPUT_SUFFIX)" ]
then
ret=255
fi
fi
output=$(java -enableassertions -cp compilers/$language/bin lfocc.compilers.$language.Main $testcase.$TEST_SUFFIX $testcase.$TEST_COMPILED_SUFFIX 2>&1)
exit=$?
if [ $exit -ne $ret ]
then
echo "FAILURE (during compilation)!"
echo
echo "$output"
echo
fail=$((fail+1))
if [ $single = "no" ]
then
echo $testcase >> fails
fi
elif [ $exit -eq 0 -a -e $testcase.$TEST_RUN_STDIN_SUFFIX ]
then
input=""
if [ -e $testcase.$TEST_RUN_STDIN_SUFFIX ]
then
input=$(cat $testcase.$TEST_RUN_STDIN_SUFFIX)
fi
output=$(echo "$input" | ./$testcase.$TEST_COMPILED_SUFFIX 2>&1)
exit=$?
if [ -e $testcase.$TEST_RUN_FAIL_SUFFIX ]
then
if [ $exit -eq 0 ];
then
echo "FAILURE (program ran, but should have crashed)!"
fail=$((fail+1))
if [ $single = "no" ]
then
echo $testcase >> fails
fi
else
echo "OK!"
pass=$((pass+1))
fi
elif [ $exit -ne 0 ]
then
echo "FAILURE (program crashed)!"
if [ "$output" != "" ]
then
echo
echo "$output"
echo
fi
fail=$((fail+1))
if [ $single = "no" ]
then
echo $testcase >> fails
fi
elif [ -e $testcase.$TEST_RUN_REFERENCE_STDOUT_SUFFIX ]
then
if [ "$output" != "$(cat $testcase.$TEST_RUN_REFERENCE_STDOUT_SUFFIX)" ]
then
echo "FAILURE (program gave wrong output)!"
fail=$((fail+1))
if [ $single = "no" ]
then
echo $testcase >> fails
fi
else
echo "OK!"
pass=$((pass+1))
fi
else
echo "OK!"
pass=$((pass+1))
fi
else
echo "OK!"
pass=$((pass+1))
fi
total=$((total+1))
done
echo
echo "Finished ($fail failed, $pass passed, $total in total)"