Debian Codegraph @

utest/report.sh

raw
1 #!/usr/bin/env bash
2 #
3 # boxes - Command line filter to draw/remove ASCII boxes around text
4 # Copyright (c) 1999-2024 Thomas Jensen and the boxes contributors
5 #
6 # This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
7 # License, version 3, as published by the Free Software Foundation.
8 # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
9 # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
10 # details.
11 # You should have received a copy of the GNU General Public License along with this program.
12 # If not, see <https://www.gnu.org/licenses/>.
13 # ____________________________________________________________________________________________________________________
14 #
15 # Calculate and report the unit test coverage. Invoked by Makefile.
16 # ____________________________________________________________________________________________________________________
17
18
19 # Expects environment variables OUT_DIR and SRC_DIR.
20 declare -r tcBaseName=unittest
21 declare -r testResultsDir=${OUT_DIR}/test-results/${tcBaseName}
22 declare -r testReportDir=${OUT_DIR}/report-utest
23
24 declare branchCoverage=lcov_branch_coverage
25 if [[ $(uname) == "Darwin" ]]; then
26 branchCoverage=branch_coverage
27 fi
28
29 if test -n "$(find "${OUT_DIR}" -maxdepth 1 -name '*.gcda' -print -quit)" \
30 && test -n "$(find "${OUT_DIR}" -maxdepth 1 -name '*.gcno' -print -quit)" \
31 && test -n "$(lcov --version)"
32 then
33 mkdir -p "${testResultsDir}"
34 mkdir -p "${testReportDir}"
35 cp "${OUT_DIR}"/*.gc* "${testResultsDir}"
36 lcov --capture --directory "${testResultsDir}" --base-directory "${SRC_DIR}" --test-name ${tcBaseName} --quiet \
37 --exclude '*/lex.yy.c' --exclude '*/parser.c' --rc "${branchCoverage}=1" \
38 --output-file "${testResultsDir}/coverage.info"
39 echo -n "[ Coverage ] "
40 genhtml --title "Boxes / Unit Tests" --branch-coverage --legend --output-directory "${testReportDir}" \
41 "${testResultsDir}/coverage.info" | grep 'lines...' | grep -oP '\d+\.\d*%'
42 echo "[ Report ] Unit test coverage report available at ${testReportDir}/index.html"
43 fi