7a2f4c6c82d83e383f4912d95387d11333fc0fca
[dcaegen2/collectors/hv-ves.git] / hv-collector-coverage / check-coverage.sh
1 #!/usr/bin/env bash
2 set -euo pipefail
3
4 JACOCO_REPORT="$1"
5 MIN_COVERAGE_PERCENT="$2"
6
7 function coverage_from_report() {
8   local xpath_expr="string(/report/counter[@type='INSTRUCTION']/@$1)"
9   xpath -q -e "$xpath_expr" "$JACOCO_REPORT"
10 }
11
12 missed=`coverage_from_report missed`
13 covered=`coverage_from_report covered`
14 total=$(($missed + $covered))
15 coverage=$((100 * $covered / $total))
16
17 echo "Coverage: $coverage% (covered/total: $covered/$total)"
18
19 if [[ $coverage -lt $MIN_COVERAGE_PERCENT ]]; then
20   echo "Coverage is too low. Minimum coverage: $MIN_COVERAGE_PERCENT%"
21   exit 1
22 fi
23