-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli_test.sh
executable file
·234 lines (213 loc) · 7 KB
/
cli_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
222
223
224
225
226
227
228
229
230
231
232
233
234
#!/usr/bin/env sh
usage() {
echo "usage: ${0} build"
echo ""
echo " Exit 0 if all tests passed, otherwise 1."
echo " If you get any code other them these two,"
echo " an unexpected error may have occured."
echo ""
echo "build:"
echo " Specify one of the builds to test on."
echo ""
echo " -d, --debug"
echo " -r, --release"
}
if [ "$#" -ne 1 ]; then
usage
exit 1
fi
case "$1" in
-d|--debug)
BUILD_MODE='debug'
;;
-r|--release)
BUILD_MODE='release'
;;
*)
usage
exit 1
esac
NO_COLOR='\033[0m'
echo_in_green() {
GREEN='\033[0;32m'
echo "${GREEN}$*${NO_COLOR}"
}
echo_in_red() {
RED='\033[0;31m'
echo "${RED}$*${NO_COLOR}"
}
echo_in_yellow() {
YELLOW='\033[0;33m'
echo "${YELLOW}$*${NO_COLOR}"
}
TITILE_BANNER="[==========]"
RUN_BANNER="[ RUN ]"
BODY_BANNER="[ ]"
OK_BANNER="[ OK ]"
FAILED_BANNER="[ FAILED ]"
SECTION_BANNER="[----------]"
#
# To add a new test, extend the following test case list
#
EXEC=bin/regexp
echo_in_yellow "${TITILE_BANNER} Running CLI tests on ${BUILD_MODE} build..."
pass_count=0
fail_count=0
if make clean >/dev/null 2>&1 && make ${BUILD_MODE} >/dev/null 2>&1; then
# begin test cases
echo_in_yellow "${RUN_BANNER} Normal matched"
args="(a|b)*abb ababb"
echo "${BODY_BANNER} ${EXEC} ${args}"
if ! echo "${args}" | xargs ${EXEC} >/dev/null 2>&1; then
echo_in_red "${FAILED_BANNER} should exit 0"
fail_count=$((fail_count + 1))
else
echo_in_green "${OK_BANNER}"
pass_count=$((pass_count + 1))
fi
echo_in_yellow "${RUN_BANNER} Normal matched (cache)"
args="-c (a|b)*abb ababb"
echo "${BODY_BANNER} ${EXEC} ${args}"
if ! echo "${args}" | xargs ${EXEC} >/dev/null 2>&1; then
echo_in_red "${FAILED_BANNER} should exit 0"
fail_count=$((fail_count + 1))
else
echo_in_green "${OK_BANNER}"
pass_count=$((pass_count + 1))
fi
echo_in_yellow "${RUN_BANNER} Normal unmatched"
args="(a|b)*abb abab"
echo "${BODY_BANNER} ${EXEC} ${args}"
if echo "${args}" | xargs ${EXEC} >/dev/null 2>&1; then
echo_in_red "${FAILED_BANNER} should exit 1"
fail_count=$((fail_count + 1))
else
echo_in_green "${OK_BANNER}"
pass_count=$((pass_count + 1))
fi
echo_in_yellow "${RUN_BANNER} Normal unmatched (cache)"
args="-c (a|b)*abb abab"
echo "${BODY_BANNER} ${EXEC} ${args}"
if echo "${args}" | xargs ${EXEC} >/dev/null 2>&1; then
echo_in_red "${FAILED_BANNER} should exit 1"
fail_count=$((fail_count + 1))
else
echo_in_green "${OK_BANNER}"
pass_count=$((pass_count + 1))
fi
echo_in_yellow "${RUN_BANNER} Ill-formed regex"
args="(a|b*abb ababb"
echo "${BODY_BANNER} ${EXEC} ${args}"
if echo "${args}" | xargs ${EXEC} >/dev/null 2>&1; then
echo_in_red "${FAILED_BANNER} should exit 1"
fail_count=$((fail_count + 1))
else
echo_in_green "${OK_BANNER}"
pass_count=$((pass_count + 1))
fi
echo_in_yellow "${RUN_BANNER} Missing string"
args="(a|b)*abb"
echo "${BODY_BANNER} ${EXEC} ${args}"
if echo "${args}" | xargs ${EXEC} >/dev/null 2>&1; then
echo_in_red "${FAILED_BANNER} should exit 1"
fail_count=$((fail_count + 1))
else
echo_in_green "${OK_BANNER}"
pass_count=$((pass_count + 1))
fi
echo_in_yellow "${RUN_BANNER} Unknown argument"
args="(a|b)*abb ababb unknown"
echo "${BODY_BANNER} ${EXEC} ${args}"
if echo "${args}" | xargs ${EXEC} >/dev/null 2>&1; then
echo_in_red "${FAILED_BANNER} should exit 1"
fail_count=$((fail_count + 1))
else
echo_in_green "${OK_BANNER}"
pass_count=$((pass_count + 1))
fi
DOT_EXT="dot"
echo_in_yellow "${RUN_BANNER} Graph NFA to default file"
DEFAULT="nfa"
echo "${BODY_BANNER} set-up: Removing ${DEFAULT}.${DOT_EXT}..."
rm -f "${DEFAULT}.${DOT_EXT}"
args="-g (a|b)*abb"
echo "${BODY_BANNER} ${EXEC} ${args}"
if ! echo "${args}" | xargs ${EXEC} >/dev/null 2>&1; then
echo_in_red "${FAILED_BANNER} should exit 0"
fail_count=$((fail_count + 1))
elif [ ! -f "${DEFAULT}.${DOT_EXT}" ]; then
echo_in_red "${FAILED_BANNER} output file ${DEFAULT}.${DOT_EXT} not found"
fail_count=$((fail_count + 1))
else
echo_in_green "${OK_BANNER}"
pass_count=$((pass_count + 1))
fi
echo "${BODY_BANNER} tear-down: Removing ${DEFAULT}.${DOT_EXT}..."
rm -f "${DEFAULT}.${DOT_EXT}"
echo_in_yellow "${RUN_BANNER} Graph NFA to designated file"
DESIGNSTED="cli_test_nfa"
echo "${BODY_BANNER} set-up: Removing ${DESIGNSTED}.${DOT_EXT}..."
rm -f "${DESIGNSTED}.${DOT_EXT}"
args="-g (a|b)*abb -o ${DESIGNSTED}"
echo "${BODY_BANNER} ${EXEC} ${args}"
if ! echo "${args}" | xargs ${EXEC} >/dev/null 2>&1; then
echo_in_red "${FAILED_BANNER} should exit 0"
fail_count=$((fail_count + 1))
elif [ ! -f "${DESIGNSTED}.${DOT_EXT}" ]; then
echo_in_red "${FAILED_BANNER} output file ${DESIGNSTED}.${DOT_EXT} not found"
fail_count=$((fail_count + 1))
else
echo_in_green "${OK_BANNER}"
pass_count=$((pass_count + 1))
fi
echo "${BODY_BANNER} tear-down: Removing ${DESIGNSTED}.${DOT_EXT}..."
rm -f "${DESIGNSTED}.${DOT_EXT}"
echo_in_yellow "${RUN_BANNER} Output specified without using graph mode"
args="(a|b)*abb ababb -o file"
echo "${BODY_BANNER} ${EXEC} ${args}"
if echo "${args}" | xargs ${EXEC} >/dev/null 2>&1; then
echo_in_red "${FAILED_BANNER} should exit 1"
fail_count=$((fail_count + 1))
else
echo_in_green "${OK_BANNER}"
pass_count=$((pass_count + 1))
fi
echo_in_yellow "${RUN_BANNER} Output option set without file specified"
args="(a|b)*abb ababb -o"
echo "${BODY_BANNER} ${EXEC} ${args}"
if echo "${args}" | xargs ${EXEC} >/dev/null 2>&1; then
echo_in_red "${FAILED_BANNER} should exit 1"
fail_count=$((fail_count + 1))
else
echo_in_green "${OK_BANNER}"
pass_count=$((pass_count + 1))
fi
echo_in_yellow "${RUN_BANNER} Cache option set under graph mode"
args="(a|b)*abb ababb -g -c"
echo "${BODY_BANNER} ${EXEC} ${args}"
if echo "${args}" | xargs ${EXEC} >/dev/null 2>&1; then
echo_in_red "${FAILED_BANNER} should exit 1"
fail_count=$((fail_count + 1))
else
echo_in_green "${OK_BANNER}"
pass_count=$((pass_count + 1))
fi
# tail of test cases
echo_in_yellow "${SECTION_BANNER} $((pass_count + fail_count)) tests ran."
else
echo_in_red "${FAILED_BANNER} Compilation error"
exit 1
fi
TITILE_BANNER="[==========]"
FAILED_BANNER="[ FAILED ]"
PASSED_BANNER="[ PASSED ]"
echo ""
echo_in_yellow "${TITILE_BANNER} Summary"
if [ $pass_count -ne 0 ]; then
echo_in_green "${PASSED_BANNER} ${pass_count} tests."
fi
if [ $fail_count -ne 0 ]; then
echo_in_red "${FAILED_BANNER} ${fail_count} tests."
exit 1
fi
exit 0