forked from nus-cs2030s-2021-s2/lab3-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·102 lines (96 loc) · 1.87 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
#!/bin/bash
set -o nounset
JSHELL_TESTS="QueueTest ArrayTest"
function control_c() {
if [ -e $out ]
then
rm -f $out
fi
}
trap control_c INT
if [ $# -ne 1 ]
then
echo "usage: $0 <main class>"
exit 1
fi
num_failed=0
for script in $JSHELL_TESTS
do
if [ $(uname) == "Darwin" ]
then
out=$(mktemp -t $script)
else
out=$(mktemp --suffix=$script)
fi
jshell -q < $script.jsh > $out 2>&1
if [ -e $out ]
then
if [ `diff -bB $out outputs/$script.out | wc -l` -ne 0 ]
then
echo "$script: failed"
num_failed=$((num_failed + 1))
else
echo "$script: passed"
fi
rm -f $out
else
echo "$PROG: cannot find output file. Execution interrupted?"
num_failed=$((num_failed + 1))
fi
done
PROG=$1
if [ ! -e $PROG.class ]
then
echo "$PROG.class does not exist. Have you compiled it with make or javac?"
exit 1
fi
i=1
while true
do
if [ -e inputs/$PROG.$i.in ]
then
if [ $(uname) == "Darwin" ]
then
out=$(mktemp -t $PROG)
else
out=$(mktemp --suffix=$PROG)
fi
java $PROG < inputs/$PROG.$i.in > $out
status="$?"
if [ "$status" -ne "0" ]
then
echo "$PROG: return non-zero status $status for test case $i"
# cat inputs/$PROG.$i.in
num_failed=$((num_failed + 1))
else
if [ -e $out ]
then
if [ `diff -bB $out outputs/$PROG.$i.out | wc -l` -ne 0 ]
then
echo "$PROG test $i: failed"
#cat inputs/$PROG.$i.in
num_failed=$((num_failed + 1))
else
echo "$PROG test $i: passed"
fi
rm -f $out
else
echo "$PROG: cannot find output file. Execution interrupted?"
num_failed=$((num_failed + 1))
fi
fi
i=$((i + 1))
else
break
fi
done
if [ $i -eq 1 ]
then
echo "$PROG: no test cases found 🤷"
elif [ $num_failed -eq 0 ]
then
echo "$PROG: passed everything 🎉"
fi
# Run style checker
java -jar ~cs2030s/bin/checkstyle.jar -c ~cs2030s/bin/cs2030_checks.xml *.java
# vim:noexpandtab:sw=4:ts=4