forked from ucsd-cse15l-w23/grader-skill-demo2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grade.sh
63 lines (47 loc) · 1.62 KB
/
grade.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
CPATH='.:lib/hamcrest-core-1.3.jar:lib/junit-4.13.2.jar'
rm -rf student-submission
git clone $1 student-submission
echo 'Finished cloning'
if [[ -f student-submission/ListExamples.java ]]
then
echo 'ListExamples.java found'
else
echo 'ListExamples.java not found'
echo 'Score: 0/4'
exit 1
fi
cp student-submission/ListExamples.java ./
javac -cp $CPATH *.java
java -cp $CPATH org.junit.runner.JUnitCore TestListExamples > junit-output.txt
# The strategy used here relies on the last few lines of JUnit output, which
# looks like:
# FAILURES!!!
# Tests run: 4, Failures: 2
# We check for "FAILURES!!!" and then do a bit of parsing of the last line to
# get the count
FAILURES=`grep -c FAILURES!!! junit-output.txt`
if [[ $FAILURES -eq 0 ]]
then
RESULT_LINE=`grep "OK " junit-output.txt`
PASSED=${RESULT_LINE:4:1}
TOTAL=$PASSED
else
# The ${VAR:N:M} syntax gets a substring of length M starting at index N
# Note that since this is a precise character count into the "Tests run:..."
# string, we'd need to update it if, say, we had a double-digit number of
# tests. But it's nice and simple for the purposes of this script.
# See, for example:
# https://stackoverflow.com/questions/16484972/how-to-extract-a-substring-in-bash
# https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Shell-Parameter-Expansion
RESULT_LINE=`grep "Tests run:" junit-output.txt`
COUNT=${RESULT_LINE:25:1}
TOTAL=${RESULT_LINE:11:1}
PASSED=$(echo "($TOTAL-$COUNT)" | bc)
echo "JUnit output was:"
cat junit-output.txt
fi
echo ""
echo "--------------"
echo "| Score: $PASSED/$TOTAL |"
echo "--------------"
echo ""