summaryrefslogtreecommitdiff
path: root/scripts/gen_coverage_report.sh
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-04 10:22:15 +0100
committerskal <pascal.massimino@gmail.com>2026-02-04 10:22:15 +0100
commit4194c8d4bbd5bc48c2f50a7377c616f147385016 (patch)
tree06b17897a068a45466cfa751a1a1d3449fc6ebf5 /scripts/gen_coverage_report.sh
parent24d39afe882c92da8a2dfb543b97008cf50d7ec1 (diff)
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.
Diffstat (limited to 'scripts/gen_coverage_report.sh')
-rwxr-xr-xscripts/gen_coverage_report.sh56
1 files changed, 56 insertions, 0 deletions
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"