Skip to content

Conversation

@louwers
Copy link
Member

@louwers louwers commented Nov 19, 2025

@TimSylvester Could you try this with

just coverage-cpp-html

I only tried on macOS.

image

You need to have lcov installed

brew install lcov

Copilot finished reviewing on behalf of louwers November 19, 2025 17:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds C++ code coverage support using lcov and genhtml tools to generate coverage reports for the C++ codebase.

  • Introduces CMake option MLT_WITH_COVERAGE to enable coverage instrumentation
  • Adds two new justfile recipes: coverage-cpp for generating raw coverage data and coverage-cpp-html for HTML reports
  • Configures compiler/linker flags for coverage in both the main library and test targets, with special handling for macOS static library linking

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
justfile Adds coverage-cpp and coverage-cpp-html recipes that build with coverage flags, run tests, and generate lcov/HTML reports
cpp/CMakeLists.txt Introduces MLT_WITH_COVERAGE option and applies coverage compiler/linker flags to the mlt-cpp library when enabled
cpp/test/CMakeLists.txt Applies coverage flags to the test target and adds macOS-specific force_load linker option to include static library coverage symbols
cpp/.gitignore Adds build-coverage directory to ignore list for coverage build artifacts

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

if(MLT_WITH_COVERAGE)
message(STATUS "[MLT] Enabling code coverage instrumentation")
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang")
target_compile_options(mlt-cpp PRIVATE --coverage -fprofile-arcs -ftest-coverage)
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The --coverage flag already includes -fprofile-arcs -ftest-coverage, making the explicit addition of these flags redundant. You can simplify this to just --coverage.

Suggested change
target_compile_options(mlt-cpp PRIVATE --coverage -fprofile-arcs -ftest-coverage)
target_compile_options(mlt-cpp PRIVATE --coverage)

Copilot uses AI. Check for mistakes.

if(MLT_WITH_COVERAGE)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang")
target_compile_options(mlt-cpp-test PRIVATE --coverage -fprofile-arcs -ftest-coverage)
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The --coverage flag already includes -fprofile-arcs -ftest-coverage, making the explicit addition of these flags redundant. You can simplify this to just --coverage.

Suggested change
target_compile_options(mlt-cpp-test PRIVATE --coverage -fprofile-arcs -ftest-coverage)
target_compile_options(mlt-cpp-test PRIVATE --coverage)

Copilot uses AI. Check for mistakes.
cmake --build build-coverage --target mlt-cpp-test
build-coverage/test/mlt-cpp-test
lcov --directory build-coverage --capture --output-file coverage/coverage.info --ignore-errors inconsistent
lcov --extract coverage/coverage.info '*/cpp/src/mlt/*' '*/cpp/include/mlt/*' --output-file coverage/coverage.info --ignore-errors inconsistent
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the same file for both input (coverage/coverage.info) and output (--output-file coverage/coverage.info) in the lcov extract command is risky. If the extraction fails midway, you could lose the original data. Consider using a temporary file first (e.g., coverage/coverage.filtered.info) and then moving it, or at minimum using a different intermediate filename.

Suggested change
lcov --extract coverage/coverage.info '*/cpp/src/mlt/*' '*/cpp/include/mlt/*' --output-file coverage/coverage.info --ignore-errors inconsistent
lcov --extract coverage/coverage.info '*/cpp/src/mlt/*' '*/cpp/include/mlt/*' --output-file coverage/coverage.filtered.info --ignore-errors inconsistent
mv coverage/coverage.filtered.info coverage/coverage.info

Copilot uses AI. Check for mistakes.
@TimSylvester
Copy link
Collaborator

I had to add additional ignores to make it work:

-    lcov --directory build-coverage --capture --output-file coverage/coverage.info --ignore-errors inconsistent
+    lcov --directory build-coverage --capture --output-file coverage/coverage.info --ignore-errors inconsistent,format

-    genhtml coverage/coverage.info --output-directory coverage/html --title "MLT C++ Coverage" --legend --demangle-cpp --show-details --branch-coverage --ignore-errors inconsistent,corrupt
+    genhtml coverage/coverage.info --output-directory coverage/html --title "MLT C++ Coverage" --legend --demangle-cpp --show-details --branch-coverage --ignore-errors inconsistent,corrupt,category

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants