-
Notifications
You must be signed in to change notification settings - Fork 13
/
coverage.sh
executable file
·61 lines (51 loc) · 1.97 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
#!/bin/bash
# To use this locally, go to the root of your workspace
# cd ~/<workspace-name>/
# Then run ./src/easy_manipulation_deployment/coverage.sh html
# Coverage report will be generate automatically
# Enable branch coverage for local report
# ./src/easy_manipulation_deployment/coverage.sh html
if [ "$1" = "ci" ]; then
cd ~/target_ws || return 1
fi
branch_command=()
branch_html_command=()
if [ "$2" = "--branch" ]; then
branch_command=(--rc "lcov_branch_coverage=1")
branch_html_command=(--branch-coverage)
fi
package_name="easy_manipulation_deployment"
ignored_files="*/test/*"
# Install LCOV
if [ "$(dpkg-query -W -f='${Status}' lcov 2>/dev/null | grep -c 'ok installed')" -eq 0 ];
then
sudo apt-get install -y -qq lcov
fi
# Capture initial coverage info
lcov --capture --initial \
--directory build \
--output-file initial_coverage.info "${branch_command[@]}" | grep -ve "^Processing"
# Capture tested coverage info
lcov --capture \
--directory build \
--output-file test_coverage.info "${branch_command[@]}" | grep -ve "^Processing"
# Combine two report (exit function when none of the records are valid)
lcov --add-tracefile initial_coverage.info \
--add-tracefile test_coverage.info \
--output-file coverage.info "${branch_command[@]}" || return 0 \
&& rm initial_coverage.info test_coverage.info
# Extract repository files
lcov --extract coverage.info "$(pwd)/src/$package_name/*" \
--output-file coverage.info "${branch_command[@]}" | grep -ve "^Extracting"
# Filter out ignored files
lcov --remove coverage.info "$ignored_files" \
--output-file coverage.info "${branch_command[@]}" | grep -ve "^removing"
if [ "$1" = "ci" ]; then
# Some sed magic to remove identifiable absolute path
sed -i "s~$(pwd)/src/$package_name/~~g" coverage.info
lcov --list coverage.info "${branch_command[@]}"
cd - || return 1
cp -r ~/target_ws/coverage.info .
elif [ "$1" = "html" ]; then
genhtml "${branch_html_command[@]}" coverage.info -o coverage
fi