-
Notifications
You must be signed in to change notification settings - Fork 1
/
coverage_calc.sh
51 lines (43 loc) · 1.24 KB
/
coverage_calc.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
#!/bin/bash
totalLines=0
testedLines=0
generateCovMessage="Run 'bash gencov.sh' in order to generate code coverage."
# Get the named parameters --threshold, --severity
while [ $# -gt 0 ]; do
if [[ $1 == *"--"* ]]; then
param="${1/--/}"
declare $param="$2"
fi
shift
done
if [ -z "$threshold" ]; then
echo "Please provide the coverage threshold using the --threshold option" && exit 1
fi
if [[ ! -d coverage ]];then
echo "$generateCovMessage" && exit 0
fi
lines=`cat coverage/lcov.info`
for line in $lines; do
firstPart=${line:0:2}
if [[ "$firstPart" == "LF" ]]; then
count=`cut -d ":" -f2 <<< $line""`
totalLines=$(($totalLines + $count))
fi
if [[ "$firstPart" == "LH" ]]; then
testedCount=`cut -d ":" -f2 <<< $line`
testedLines=$(($testedLines + $testedCount))
fi
done
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
coverage=$(bc <<< "scale=3; $testedLines / $totalLines")
if (( $(echo "$coverage < $threshold" | bc -l) )); then
# No Color
printf "${RED}Code coverage too low: minimum: ${threshold} acctual ${coverage}.\n${NC}${generateCovMessage}\n"
if [[ "$severity" == "error" ]]; then
exit 1
fi
else
printf "${GREEN}Code coverage test passed: minimum: ${threshold} acctual ${coverage}.\n${NC}"
fi