From 15c72d4d9924fe37544e355a0aba3aec402ecb43 Mon Sep 17 00:00:00 2001 From: Thomas Jensen Date: Sat, 2 Dec 2023 14:36:19 +0100 Subject: [PATCH] Restore branch coverage for tests on Linux --- test/testrunner.sh | 10 ++++++++-- utest/report.sh | 7 ++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/test/testrunner.sh b/test/testrunner.sh index 5f239eb..7388c28 100755 --- a/test/testrunner.sh +++ b/test/testrunner.sh @@ -152,19 +152,20 @@ function measure_coverage() mkdir -p "${testResultsDir}" cp ${OUT_DIR}/*.gc* "${testResultsDir}" lcov --capture --directory "${testResultsDir}" --base-directory ${SRC_DIR} --test-name "${tcBaseName}" --quiet \ - --exclude '*/lex.yy.c' --exclude '*/parser.c' --rc branch_coverage=1 \ + --exclude '*/lex.yy.c' --exclude '*/parser.c' --rc "${branchCoverage}=1" \ --output-file "${testResultsDir}/coverage.info" echo -n " Coverage: " lcov --summary "${testResultsDir}/coverage.info" 2>&1 | grep 'lines...' | grep -oP '\d+\.\d*%' fi } + function consolidate_coverage() { echo -e "\nConsolidating test coverage ..." pushd ${OUT_DIR}/test-results || exit 1 find . -name "*.info" | xargs printf -- '--add-tracefile %s\n' | xargs --exit \ - lcov --rc branch_coverage=1 --exclude '*/lex.yy.c' --exclude '*/parser.c' \ + lcov --rc "${branchCoverage}=1" --exclude '*/lex.yy.c' --exclude '*/parser.c' \ --output-file ../${COVERAGE_FILE} --add-tracefile ../${BASELINE_FILE} popd || exit 1 echo "" @@ -265,6 +266,11 @@ parse_arguments "$@" check_prereqs cov_baseline +declare branchCoverage=lcov_branch_coverage +if [[ $(uname) == "Darwin" ]]; then + branchCoverage=branch_coverage +fi + # Execute the entire test suite if [ ${opt_suite} == true ]; then declare -i overallResult=0 diff --git a/utest/report.sh b/utest/report.sh index 224a54f..e570ed9 100755 --- a/utest/report.sh +++ b/utest/report.sh @@ -21,6 +21,11 @@ declare -r tcBaseName=unittest declare -r testResultsDir=${OUT_DIR}/test-results/${tcBaseName} declare -r testReportDir=${OUT_DIR}/report-utest +declare branchCoverage=lcov_branch_coverage +if [[ $(uname) == "Darwin" ]]; then + branchCoverage=branch_coverage +fi + if test -n "$(find ${OUT_DIR} -maxdepth 1 -name '*.gcda' -print -quit)" \ && test -n "$(find ${OUT_DIR} -maxdepth 1 -name '*.gcno' -print -quit)" \ && test -n "$(lcov --version)" @@ -29,7 +34,7 @@ then mkdir -p ${testReportDir} cp ${OUT_DIR}/*.gc* ${testResultsDir} lcov --capture --directory ${testResultsDir} --base-directory ${SRC_DIR} --test-name ${tcBaseName} --quiet \ - --exclude '*/lex.yy.c' --exclude '*/parser.c' --rc branch_coverage=1 \ + --exclude '*/lex.yy.c' --exclude '*/parser.c' --rc "${branchCoverage}=1" \ --output-file ${testResultsDir}/coverage.info echo -n "[ Coverage ] " genhtml --title "Boxes / Unit Tests" --branch-coverage --legend --output-directory ${testReportDir} \