From 4194c8d4bbd5bc48c2f50a7377c616f147385016 Mon Sep 17 00:00:00 2001 From: skal Date: Wed, 4 Feb 2026 10:22:15 +0100 Subject: feat(tooling): Implement code coverage reporting (Task #44) Added CMake support for coverage builds and a script to generate HTML reports using lcov on macOS. Also cleaned up .gitignore. --- scripts/gen_coverage_report.sh | 56 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 scripts/gen_coverage_report.sh (limited to 'scripts/gen_coverage_report.sh') diff --git a/scripts/gen_coverage_report.sh b/scripts/gen_coverage_report.sh new file mode 100755 index 0000000..bae2141 --- /dev/null +++ b/scripts/gen_coverage_report.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +# Exit on error +set -e + +# Project root +PROJECT_ROOT=$(cd "$(dirname "$0")/.." && pwd) +BUILD_DIR="${PROJECT_ROOT}/build_coverage" +REPORT_DIR="${PROJECT_ROOT}/build_coverage/coverage_report" + +# Common lcov options to handle AppleClang quirks +LCOV_OPTS="--ignore-errors mismatch,inconsistent,gcov,format,unsupported,category" + +echo "=== Code Coverage Report Generator ===" +echo "Project Root: ${PROJECT_ROOT}" + +# Check for lcov +if ! command -v lcov &> /dev/null; then + echo "Error: lcov is not installed." + echo "Please install it using: brew install lcov" + exit 1 +fi + +# Cleanup previous build if requested (optional, but safer for coverage) +# rm -rf "${BUILD_DIR}" + +mkdir -p "${BUILD_DIR}" +cd "${BUILD_DIR}" + +echo "--- Configuring CMake with Coverage ---" +cmake "${PROJECT_ROOT}" -DDEMO_ENABLE_COVERAGE=ON -DDEMO_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Debug + +echo "--- Building Tests ---" +# Build only the test targets to save time, or all if needed. +# Building 'all' ensures everything is compiled with coverage flags. +cmake --build . -j $(sysctl -n hw.ncpu) + +echo "--- Running Tests ---" +# Run tests and ignore failures so we still get a report? +# Ideally tests should pass. Let's allow failures for now so we see what's covered. +ctest --output-on-failure || true + +echo "--- Capturing Coverage Data ---" +# Capture initial coverage data +lcov --capture --directory . --output-file coverage.info $LCOV_OPTS + +echo "--- Filtering Coverage Data ---" +# Remove system headers and third-party libraries +lcov --remove coverage.info '/usr/*' "${PROJECT_ROOT}/third_party/*" "${PROJECT_ROOT}/build_coverage/*" '*/test_*' --output-file coverage_filtered.info $LCOV_OPTS + +echo "--- Generating HTML Report ---" +genhtml coverage_filtered.info --output-directory "${REPORT_DIR}" $LCOV_OPTS + +echo "=== Coverage Report Generated ===" +echo "Open the report with:" +echo "open ${REPORT_DIR}/index.html" -- cgit v1.2.3