-
Notifications
You must be signed in to change notification settings - Fork 0
/
gradelab3.sh
executable file
·147 lines (133 loc) · 3.53 KB
/
gradelab3.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
#!/bin/bash
#============some output color
#RED_COLOR='\E[1;31m'
#GREEN_COLOR='\E[1;32m'
#YELOW_COLOR='\E[1;33m'
#BLUE_COLOR='\E[1;34m'
#PINK='\E[1;35m'
#RES='\E[0m'
RED_COLOR=''
GREEN_COLOR=''
YELOW_COLOR=''
BLUE_COLOR=''
PINK=''
RES=''
BIN=test_parse
#PROJDIR=lab3
REFOUTDIR=refs
TESTCASEDIR=testcases
#DIFFOPTION="-w -B"
ret_value=0
base_name=$(basename "$PWD")
if [[ ! $base_name =~ "tiger-compiler" ]]; then
echo "[-_-]: Not in Lab Root Dir"
echo "SCORE: 0"
exit 1
fi
mkdir -p build
cd build
rm -f testcases refs _tmp.txt .tmp.txt
ln -s ../testdata/lab3/testcases testcases
if [[ $? != 0 ]]; then
echo "[-_-]$ite: Link Error"
echo "TOTAL SCORE: 0"
exit 123
fi
ln -s ../testdata/lab3/refs refs
if [[ $? != 0 ]]; then
echo "[-_-]$ite: Link Error"
echo "TOTAL SCORE: 0"
exit 123
fi
cmake .. >&/dev/null
make ${BIN} -j >/dev/null
if [[ $? != 0 ]]; then
echo -e "${RED_COLOR}[-_-]$ite: Compile Error${RES}"
exit 123
fi
if [[ $1 == "syntax" ]]; then
for tcase in $(ls $TESTCASEDIR); do
if [ ${tcase##*.} = "tig" ]; then
tfileName=${tcase##*/}
./$BIN $TESTCASEDIR/$tfileName >&_tmp.txt
ret_value=$?
# fix bison version diff
if [ $tfileName = "test49.tig" ]; then
if [[ $ret_value == 0 ]]; then
echo -e "${BLUE_COLOR}[*_*]$ite: This case should be syntax error [$tfileName]${RES}"
rm -f _tmp.txt .tmp.txt
exit 234
fi
continue
fi
# normal case
if [[ $ret_value != 0 ]]; then
echo -e "${BLUE_COLOR}[*_*]$ite: Syntax Error [$tfileName]${RES}"
rm -f _tmp.txt .tmp.txt
exit 234
fi
fi
done
else
for tcase in $(ls $TESTCASEDIR); do
if [ ${tcase##*.} = "tig" ]; then
tfileName=${tcase##*/}
./$BIN $TESTCASEDIR/$tfileName >&_tmp.txt
ret_value=$?
# fix bison version diff
if [ $tfileName = "test49.tig" ]; then
if [[ $ret_value == 0 ]]; then
echo -e "${BLUE_COLOR}[*_*]$ite: This case should be syntax error [$tfileName]${RES}"
rm -f _tmp.txt .tmp.txt
exit 234
fi
continue
fi
# normal case
if [[ $ret_value != 0 ]]; then
echo -e "${BLUE_COLOR}[*_*]$ite: Syntax Error [$tfileName]${RES}"
rm -f _tmp.txt .tmp.txt
exit 234
fi
fi
done
echo -e "${GREEN_COLOR}[^_^]$ite: Pass Part A${RES}"
echo "TOTAL SCORE: 50"
for tcase in $(ls $TESTCASEDIR); do
if [ ${tcase##*.} = "tig" ]; then
tfileName=${tcase##*/}
./$BIN $TESTCASEDIR/$tfileName >&_tmp.txt
# fix bison version diff
if [ $tfileName = "test49.tig" ]; then
#echo $tfileName
#cat _tmp.txt
grep 'test49.tig:5.18: syntax error' _tmp.txt >&.tmp.txt
if [ -s .tmp.txt ]; then
grep 'test49.tig:5.18: parse error' _tmp.txt >&.tmp.txt
if [ -s .tmp.txt ]; then
cat _tmp.txt
echo -e "${BLUE_COLOR}[*_*]$ite: Output Mismatch [$tfileName]${RES}"
rm -f _tmp.txt .tmp.txt
exit 234
fi
fi
continue
fi
# normal case
diff $DIFFOPTION _tmp.txt $REFOUTDIR/${tfileName%.*}.out >&.tmp.txt
if [ -s .tmp.txt ]; then
cat .tmp.txt
echo -e "${BLUE_COLOR}[*_*]$ite: Output Mismatch [$tfileName]${RES}"
rm -f _tmp.txt .tmp.txt
exit 234
fi
fi
done
fi
rm -f testcases refs _tmp.txt .tmp.txt
if [[ $1 == "syntax" ]]; then
echo -e "${GREEN_COLOR}[^_^]$ite: Pass Part A${RES}"
else
echo -e "${GREEN_COLOR}[^_^]$ite: Pass Lab3${RES}"
echo "TOTAL SCORE: 100"
fi