-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-all.sh
executable file
·317 lines (271 loc) · 10.5 KB
/
test-all.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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#!/bin/bash
# Sean Szumlanski
# COP 3503, Summer 2019
# =======================
# Pathfinder: test-all.sh
# =======================
# You can run this script at the command line like so:
#
# bash test-all.sh
#
# For more details, see the assignment PDF.
################################################################################
# Shell check.
################################################################################
# Running this script with sh instead of bash can lead to false positives on the
# test cases. Yikes! These checks ensure the script is not being run through the
# Bourne shell (or any shell other than bash).
if [ "$BASH" != "/bin/bash" ]; then
echo ""
echo " Bloop! Please use bash to run this script, like so: bash test-all.sh"
echo ""
exit
fi
if [ -z "$BASH_VERSION" ]; then
echo ""
echo " Bloop! Please use bash to run this script, like so: bash test-all.sh"
echo ""
exit
fi
################################################################################
# Initialization.
################################################################################
PASS_CNT=0
NUM_TEST_CASES=8
# +1 for the indentation check below.
TOTAL_TEST_CNT=`expr $NUM_TEST_CASES + 1`
################################################################################
# Check for commands that are required by this test script.
################################################################################
# This command is necessary in order to run all the test cases in sequence.
if ! [ -x "$(command -v seq)" ]; then
echo ""
echo " Error: seq command not found. You might see this message if you're"
echo " running this script on an old Mac system. Please be sure to"
echo " test your final code on Eustis. Aborting test script."
echo ""
exit
fi
# This command is necessary for various warning checks.
if ! [ -x "$(command -v grep)" ]; then
echo ""
echo " Error: grep command not found. You might see this message if you're"
echo " running this script on an old Mac system. Please be sure to"
echo " test your final code on Eustis. Aborting test script."
echo ""
exit
fi
################################################################################
# Check that all required files are present.
################################################################################
if [ ! -f Pathfinder.java ]; then
echo ""
echo " Error: You must place ConstrainedTopoSort.java in this directory"
echo " before we can proceed. Aborting test script."
echo ""
exit
fi
if [ ! -d sample_output ]; then
echo ""
echo " Error: You must place the sample_output folder in this directory"
echo " before we can proceed. Aborting test script."
echo ""
exit
fi
if [ ! -d input_files ]; then
echo ""
echo " Error: You must place the input_files folder in this directory"
echo " before we can proceed. Aborting test script."
echo ""
exit
fi
for i in `seq -f "%02g" 1 $NUM_TEST_CASES`;
do
if [ ! -f TestCase$i.java ]; then
echo ""
echo " Error: You must place TestCase$i.java in this directory before we"
echo " can proceed. Aborting test script."
echo ""
exit
fi
done
for i in `seq -f "%02g" 1 $NUM_TEST_CASES`;
do
if [ ! -f sample_output/TestCase$i-output.txt ]; then
echo ""
echo " Error: You must place TestCase$i-output.txt in the sample_output"
echo " directory before we can proceed. Aborting test script."
echo ""
exit
fi
done
for i in `seq 1 6`;
do
if [ ! -f input_files/maze$i.txt ]; then
echo ""
echo " Error: You must place maze$i.txt in the input_files directory"
echo " before we can proceed. Aborting test script."
echo ""
exit
fi
if [ ! -f input_files/maze$i-paths.txt ]; then
echo ""
echo " Error: You must place maze$i-paths.txt in the input_files directory"
echo " before we can proceed. Aborting test script."
echo ""
exit
fi
done
################################################################################
# Compile and run test cases.
################################################################################
echo ""
echo "================================================================"
echo "Running test cases..."
echo "================================================================"
echo ""
for i in `seq -f "%02g" 1 $NUM_TEST_CASES`;
do
echo -n " [Test Case] Checking TestCase$i... "
# Make sure any pre-compiled classes get re-compiled.
rm -rf *.class
# Attempt to compile, and check for compilation failure.
javac Pathfinder.java TestCase$i.java 2> /dev/null
compile_val=$?
if [[ $compile_val != 0 ]]; then
echo "** fail ** (failed to compile)"
continue
fi
# Run program. Capture return value to check whether it crashes.
java TestCase$i > myoutput.txt 2> /dev/null
execution_val=$?
if [[ $execution_val != 0 ]]; then
echo "** fail ** (program crashed)"
continue
fi
# Run diff and capture its return value.
diff myoutput.txt sample_output/TestCase$i-output.txt > /dev/null
diff_val=$?
# Output results based on diff's return value.
if [[ $diff_val != 0 ]]; then
echo "** fail ** (output does not match)"
else
echo "PASS!"
PASS_CNT=`expr $PASS_CNT + 1`
fi
done
############################################################################
# Check for tabs vs. spaces.
############################################################################
echo ""
echo "================================================================"
echo "Checking for tabs vs. spaces..."
echo "================================================================"
echo ""
if ! [ -x "$(command -v grep)" ]; then
echo " Skipping tabs vs. spaces check; grep not installed. You"
echo " might see this message if you're running this script on a"
echo " Mac. Please be sure to test your final code on Eustis."
elif ! [ -x "$(command -v awk)" ]; then
echo " Skipping tabs vs. spaces check; awk not installed. You"
echo " might see this message if you're running this script on a"
echo " Mac. Please be sure to test your final code on Eustis."
else
num_spc_lines=`grep "^ " Pathfinder.java | wc -l | awk '{$1=$1};1'`
num_tab_lines=`grep "$(printf '^\t')" Pathfinder.java | wc -l | awk '{$1=$1};1'`
num_und_lines=`grep "$(printf '^[^\t ]')" Pathfinder.java | wc -l | awk '{$1=$1};1'`
echo " Number of lines beginning with spaces: $num_spc_lines"
echo " Number of lines beginning with tabs: $num_tab_lines"
echo " Number of lines with no indentation: $num_und_lines"
if [ "$num_spc_lines" -gt 0 ] && [ "$num_tab_lines" -gt 0 ]; then
echo ""
echo " Whoa, buddy! It looks like you're starting some lines of code with"
echo " tabs, and other lines of code with spaces. You'll need to choose"
echo " one or the other."
echo ""
echo " Try running the following commands to see which of your lines begin"
echo " with spaces (the first command below) and which ones begin with tabs"
echo " (the second command below):"
echo ""
echo " grep \"^ \" Pathfinder.java -n"
echo " grep \"\$(printf '^\t')\" Pathfinder.java -n"
elif [ "$num_spc_lines" -gt 0 ]; then
echo ""
echo " Looks like you're using spaces for all your indentation! (Yay!)"
PASS_CNT=`expr $PASS_CNT + 1`
elif [ "$num_tab_lines" -gt 0 ]; then
echo ""
echo " Looks like you're using tabs for all your indentation! (Yay!)"
PASS_CNT=`expr $PASS_CNT + 1`
else
echo ""
echo " Whoa, buddy! It looks like none of your lines of code are indented!"
fi
fi
################################################################################
# Cleanup phase.
################################################################################
rm -f *.class
rm -f myoutput.txt
################################################################################
# Final thoughts.
################################################################################
echo ""
echo "================================================================"
echo "Final Report"
echo "================================================================"
if [ $PASS_CNT -eq $TOTAL_TEST_CNT ]; then
echo ""
echo " ,)))))))),,,"
echo " ,(((((((((((((((,"
echo " )\\\`\\)))))))))))))),"
echo " *--===///\`_ \`\`\`((((((((("
echo " \\\\\\ b\\ \\ \`\`)))))))"
echo " ))\\ | (((((((( ,,,,"
echo " ( \\ |\`. )))))))) ____ ,)))))),"
echo " \\, / ) ((((((((-.___.-\" \`\"((((((("
echo " \`\" / ))))))) \\\`)))))"
echo " / ((((\`\` \\((((("
echo " _____| \`)) / |)))))"
echo " / \\ | / ((((("
echo " / --.__) / _\\ / )))))"
echo " / / / /'\`\"~----~\` \`. \\ (((("
echo " / / / /\` \`-._ \`-. \`)))"
echo " /_ ( / /\` \`-._ \\ (("
echo " /__|\` / /\` \`\\\`-. \\ ')"
echo " / /\` \`\\ \\ \\"
echo " / / \\ \\ \\"
echo " /_ ( /_()_("
echo " /__|\` /__/__|"
echo ""
echo " Legendary."
echo ""
echo " 10/10 would run this program again."
echo ""
echo " CONGRATULATIONS! You appear to be passing all required test"
echo " cases! (Now, don't forget to create some extra test cases of"
echo " your own. These test cases are not necessarily comprehensive.)"
echo ""
else
echo " ."
echo " \":\""
echo " ___:____ |\"\\/\"|"
echo " ,' \`. \\ /"
echo " | o \\___/ |"
echo " ~^~^~^~^~^~^~^~^~^~^~^~^~"
echo ""
echo " (fail whale)"
echo ""
echo " The fail whale is friendly and adorable! He is not here to"
echo " demoralize you, but rather, to bring you comfort and joy"
echo " in your time of need. \"Keep plugging away,\" he says! \"You"
echo " can do this!\""
echo ""
echo " For instructions on how to run these test cases individually"
echo " and inspect how your output differs from the expected output,"
echo " be sure to consult the assignment PDF."
echo ""
echo " You must also pass the indentation check in order to part ways"
echo " with the fail whale."
echo ""
fi