-
Notifications
You must be signed in to change notification settings - Fork 0
/
MimirTestRunner.sh
executable file
·106 lines (93 loc) · 3.17 KB
/
MimirTestRunner.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
#!/bin/bash
wget -q https://raw.githubusercontent.com/toddawhittaker/MimirTestCoverage/master/hamcrest-core-1.3.jar
wget -q https://raw.githubusercontent.com/toddawhittaker/MimirTestCoverage/master/junit-4.13.jar
wget -q https://raw.githubusercontent.com/toddawhittaker/MimirTestCoverage/master/jacocoagent.jar
wget -q https://raw.githubusercontent.com/toddawhittaker/MimirTestCoverage/master/jacococli.jar
wget -q https://raw.githubusercontent.com/toddawhittaker/MimirTestCoverage/master/MimirTestRunner.java
# get rid of old grading files if exist
rm -f DEBUG
rm -f OUTPUT
# move all jar files into lib
mkdir -p lib
mv ./*.jar lib 2>/dev/null
# build up a nice classpath with all libraries
DIR=$(pwd)
export CLASSPATH=${DIR}/bin
count=$(find lib -type f -name "*.jar" 2>/dev/null | wc -l)
if [ "$count" != 0 ]
then
for filename in lib/*.jar; do
export CLASSPATH=${CLASSPATH}:${DIR}/${filename}
done
fi
# compile into separate bin directory (part of classpath)
javac -d bin ./*.java
# compile error triggers zero grade
if [ $? -ne 0 ]; then
echo "Compile errors. Your score is 0%" > "${DIR}/DEBUG"
echo 0 > "${DIR}/OUTPUT"
exit 1
fi
# produce any student output for their own testing
# this doesn't count for coverage points.
if [ -f "RunMe.java" ]; then
java RunMe >> "${DIR}/DEBUG"
fi
# run test cases instrumented with JaCoCo
java -javaagent:lib/jacocoagent.jar=destfile=results.exec MimirTestRunner >> "${DIR}/DEBUG"
pass_pct=$?
echo "Passed $pass_pct% of tests." >> "${DIR}/DEBUG"
#if [ $pass_pct -ne 100 ]; then
# echo 0 > "${DIR}/OUTPUT"
# echo "Since not all test cases have passed, your coverage score will be lowered." >> "${DIR}/DEBUG"
# exit 1
#fi
# produce JaCoCo report as CSV
java -jar lib/jacococli.jar report results.exec --classfiles bin --csv results.csv --sourcefiles . --quiet #>> ${DIR}/DEBUG
if [ ! -f results.csv ]; then
echo 0 > "${DIR}/OUTPUT"
echo "No coverage results generated. Your score is 0%" >> "${DIR}/DEBUG"
exit 1
fi
# ugly Bash processing of CSV file
total=0;
covered=0;
{
echo ""
echo "Coverage results:"
echo ""
} >> "${DIR}/DEBUG"
counter=1
IFS=','
while read -r GROUP PACKAGE CLASS INSTRUCTION_MISSED \
INSTRUCTION_COVERED BRANCH_MISSED BRANCH_COVERED \
LINE_MISSED LINE_COVERED COMPLEXITY_MISSED \
COMPLEXITY_COVERED METHOD_MISSED METHOD_COVERED
do
# ignore coverage of test classes and the test runner
if [[ ! ${CLASS} =~ .+Test(Runner)?$ ]]; then
class_lines=$((LINE_MISSED+LINE_COVERED))
class_branch=$((BRANCH_MISSED+BRANCH_COVERED))
covered=$((covered+LINE_COVERED+BRANCH_COVERED))
total=$((total+class_lines+class_branch))
{
echo "$counter. Class $CLASS"
echo " $LINE_COVERED of $class_lines lines covered"
echo " $BRANCH_COVERED of $class_branch branches covered"
} >> "${DIR}/DEBUG"
let counter++
fi
done < <(tail -n +2 results.csv)
cover_pct=0
if [ $total -ne 0 ]; then
cover_pct=$((covered*100/total))
fi
score=$((cover_pct*pass_pct/100))
{
echo "$covered of $total elements covered."
echo "Covered $cover_pct% of code."
echo ""
echo "Your score is $cover_pct% coverage * $pass_pct% passed tests = $score%"
} >> "${DIR}/DEBUG"
# produce final grade
echo "$score" > "${DIR}/OUTPUT"