-
Notifications
You must be signed in to change notification settings - Fork 0
/
coverage.sh
executable file
·69 lines (50 loc) · 1.78 KB
/
coverage.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
#!/bin/bash
#security and error mecanism, stops if a command fails
set -e
SCRIPT_DIR=$(dirname $0)
COV_DIR="coverage_output"
COV_FILE="coverage.info"
RESULTS="output.html"
if [ $# -ne 1 ]; then
echo -e "USAGE : ./coverage.sh <path_to_build_folder>"
exit 2
fi
if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
echo -e "USAGE : ./coverage.sh <path_to_build_folder>
This script compiles files generated by gcov, the code coverage tool,
into an html file in ${SCRIPT_DIR}/${COV_DIR}, then open it in your default browser."
echo -e "\nexiting..."
exit 1
fi
if ! [ -d "$1" ]; then
echo -e "ERROR : "$1" is not a valid directory"
echo -e "\nexiting..."
exit 3
fi
if ! command -v lcov > /dev/null; then
echo -e "coverage.sh : ERROR : lcov, used to generate human-readable ${COV_FILE}, seems not installed,
you must install it before being able to go further."
echo -e "\nexiting..."
exit 4
fi
echo "$1"
if [ -d "${SCRIPT_DIR}/"${COV_DIR}"" ]; then
read -p "The ${COV_DIR} directory already exists, do you want to regenerate it ?[Y/n] " -n1 ans
if [ "${ans}" == "Y" ]; then
rm -r "${SCRIPT_DIR}/${COV_DIR}"
echo ""
else
echo -e "\nAborting..."
exit 5
fi
fi
echo "Creating ${SCRIPT_DIR}/${COV_DIR}..."
mkdir ${SCRIPT_DIR}/"${COV_DIR}"
lcov -d $1 -c -o "${SCRIPT_DIR}/${COV_DIR}/${COV_FILE}"
#filtering out unecessary files
lcov -r "${COV_DIR}/coverage.info" "*Qt*.framework*" "*.h" "*/tests/*" "*Xcode.app*" "*.moc" "*moc_*.cpp" "*/test/*" "*/build*/*" -o "${COV_DIR}/coverage-filtered.info"
# Generate the HTML files
genhtml -o "${SCRIPT_DIR}/${COV_DIR}/${RESULTS}" "${SCRIPT_DIR}/${COV_DIR}/coverage-filtered.info"
# Reset our counts
lcov -d "${COV_DIR}" -z
firefox ${SCRIPT_DIR}/"${COV_DIR}"/output.html