aboutsummaryrefslogtreecommitdiff
path: root/tools/coverage
blob: 8e5afcea370b55c3316ef9cf1ab21fff2bf09f96 (plain) (blame)
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
#!/bin/bash

BASEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"/..

INSTRUMENT_CMD="sh $BASEDIR/cobertura/cobertura-instrument.sh --datafile $BASEDIR/coverage.data --destination $BASEDIR/build-instrumented --ignore .*assert.*"

echo $INSTRUMENT_CMD

case "$1" in
instrument)
    echo "instrumenteing"

    mkdir -p "build-instrumented"

    cp -r -t "$BASEDIR/build-instrumented/" "$BASEDIR/build/"* "$BASEDIR/build-test/"* 

    find $BASEDIR/build/ -name *.class |
    grep -v .*Test.* |
    grep -v .*test/.* |
    grep -v .*Benchmark.* |
    grep -v .*Example.* |
    grep -v .*Exception.* |
    grep -v .*AnnotationProcessor.* |
    xargs $INSTRUMENT_CMD

    echo "instrumenteing end"

    ;;
clean)
    rm -r $BASEDIR/build-instrumented &>/dev/null
    rm $BASEDIR/coverage.data &>/dev/null
    rm -r $BASEDIR/coverage-report &>/dev/null
    exit 0
    ;;
report)
    sh $BASEDIR/cobertura/cobertura-report.sh --destination $BASEDIR/coverage-report --datafile $BASEDIR/coverage.data $BASEDIR/src/ $BASEDIR/test/
    ;;
run)
    cd "$BASEDIR/test"

    # find test classes by naming convention and convert file path to fqn
    TESTS=$( find . -name "*Test.java" | sed -e 's/\.java//' -e 's/..//' -e 's/\//\./g' )

    echo Testing classes: $TESTS

    COBERTURA="$BASEDIR/cobertura/cobertura.jar"

    java -ea -cp "$COBERTURA:$BASEDIR/build-instrumented:$BASEDIR/lib/*" \
        -Dnet.sourceforge.cobertura.datafile="$BASEDIR/coverage.data" \
        org.junit.runner.JUnitCore $TESTS
    ;;
all)
    $BASEDIR/tools/coverage clean && \
    echo "building..." && \
    $BASEDIR/tools/build && \
    $BASEDIR/tools/coverage instrument && \
    $BASEDIR/tools/coverage run && \
    $BASEDIR/tools/coverage report
    ;;
*)
    echo "Usage: $0 {instrument|clean|report|run|all}"
    exit 1
    ;;
esac