-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·221 lines (191 loc) · 3.88 KB
/
test.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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/bin/bash
LOG=0
VERBOSE=0
VERIFY=1
while getopts ":lvc" opt; do
case $opt in
l)
LOG=1
;;
v)
VERBOSE=1
;;
c)
VERIFY=1
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit
;;
esac
done
echo -n -e "\033[93m"
echo " Building compiler"
echo "============================="
echo -e -n "\033[0m"
if [ ! -f build.sh ]
then
echo -e "\033[0;31m[Error]\033[0m: Missing build.sh script"
exit 1
fi
./build.sh
if [[ $? != 0 ]]
then
echo -e "\033[0;31m[Error]\033[0m: Build failed"
exit 1
fi
if [ ! -f run.sh ]
then
echo -e "\033[0;31m[Error]\033[0m: Missing run.sh script"
exit 1
fi
RESULTS=()
for DIR_PHASE in programs/*/
do
PHASE=$(basename $DIR_PHASE)
PHASE_NUM=${PHASE%-*}
PHASE_NAME=${PHASE#*-}
PREV_PHASE_NUM=`expr $PHASE_NUM - 1`
PREV_PHASE=`ls programs | grep $PREV_PHASE_NUM-`
PREV_PHASE_NAME=${PREV_PHASE#*-}
PREV_MODE=${PREV_PHASE_NAME#*+}
MODE=${PHASE_NAME#*+}
PHASE_NAME="${PHASE_NAME^}"
for DIR_TYPE in $DIR_PHASE*/
do
TYPE=$(basename $DIR_TYPE)
TYPE="${TYPE^}"
if [[ $TYPE == "Valid" ]]
then
CONF_STATUS=0
CONF_OUTPUT="OK"
else
CONF_STATUS=1
CONF_OUTPUT="Error:"
fi
if [[ $MODE == "codegen" ]]
then
CONF_STATUS=0
CONF_OUTPUT=""
fi
if [ "$(ls -A -I ".gitignore" $DIR_TYPE)" ]
then
echo -e "\033[93m"
echo " $PHASE_NAME $TYPE"
echo "============================="
echo -e -n "\033[0m"
COUNT=0
COUNT_PASSED=0
TESTS=`find $DIR_TYPE -type f \( -name "*.go" \)`
for TEST in $TESTS
do
((COUNT++))
PREV_SUCCESS=1
if [[ $VERBOSE == 1 ]]
then
echo
echo -n "$TEST: "
fi
if [[ $TYPE == 'Invalid' && ! -z $PREV_MODE ]]
then
OUTPUT=$(./run.sh $PREV_MODE $TEST 2>&1)
STATUS=${PIPESTATUS[0]}
OUTPUT=${OUTPUT#$TEST}
if [[ $OUTPUT == *"java.lang.NullPointerException"* ]]
then
STATUS=-1
fi
if [[ $OUTPUT != "OK" || $STATUS != 0 ]]
then
PREV_SUCCESS=0
fi
fi
VERIFY_OUTPUT=
VERIFY_STATUS=
if [[ $PREV_SUCCESS == 1 ]]
then
OUTPUT=$(./run.sh $MODE $TEST 2>&1)
STATUS=${PIPESTATUS[0]}
OUTPUT=${OUTPUT#$TEST}
if [[ $OUTPUT == $CONF_OUTPUT* && $STATUS == $CONF_STATUS ]]
then
if [[ $VERBOSE == 1 ]]
then
STATUS_TEXT="pass"
STATUS_COLOUR="32"
else
STATUS_TEXT=""
fi
if [[ -f $DIR_TYPE/verify.sh ]]
then
VERIFY_OUTPUT=$(./$DIR_TYPE/verify.sh $TEST 2>&1)
VERIFY_STATUS=${PIPESTATUS[0]}
if [[ $VERIFY_STATUS == 0 ]]
then
((COUNT_PASSED++))
else
STATUS_TEXT="pass"
STATUS_COLOUR="32"
fi
else
((COUNT_PASSED++))
fi
else
STATUS_TEXT="fail"
STATUS_COLOUR="31"
fi
else
STATUS_TEXT="failed previous"
STATUS_COLOUR="31"
fi
if [ ! -z "$STATUS_TEXT" ]
then
if [[ $VERBOSE == 0 ]]
then
echo
echo -n "$TEST: "
fi
echo "$OUTPUT" | tr -d '\n'
if [ -z "$VERIFY_OUTPUT" ]
then
echo -n -e " \033[0;${STATUS_COLOUR}m[$STATUS_TEXT]\033[0m"
else
echo -e -n "\n$VERIFY_OUTPUT" | sed 's/^/ /'
fi
if [ $LOG -eq 1 ]
then
echo "$TEST: $OUTPUT [$STATUS_TEXT]" >> ${PHASE_NAME}_${TYPE}.log
fi
fi
done
if [ $VERBOSE -eq 1 ]
then
if [ $COUNT -gt 0 ]
then
echo
fi
else
if [ $COUNT -ne $COUNT_PASSED ]
then
echo
fi
fi
echo
if [ $COUNT -eq $COUNT_PASSED ]
then
STATUS_COLOUR="42"
else
STATUS_COLOUR="41"
fi
echo -e "\e[${STATUS_COLOUR}m# ${PHASE_NAME} ${TYPE}: ${COUNT_PASSED}/${COUNT}\e[49m"
RESULTS+=("\e[${STATUS_COLOUR}m# ${PHASE_NAME} ${TYPE}: ${COUNT_PASSED}/${COUNT}\e[49m")
fi
done
done
echo -e "\033[93m"
echo " Overall"
echo "============================="
echo -e "\033[0m"
for i in ${!RESULTS[*]}; do
echo -e ${RESULTS[$i]}
done