Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cpp/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/build
build-coverage
/.cache
11 changes: 11 additions & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ option(MLT_WITH_JSON "Include JSON support" ON)
option(MLT_WITH_FASTPFOR "Include FastPFor support" ON)
option(MLT_WITH_TESTS "Include Tests" ON)
option(MLT_WITH_TOOLS "Include CLI tools" ON)
option(MLT_WITH_COVERAGE "Enable code coverage instrumentation" OFF)

set_target_properties(
mlt-cpp
Expand Down Expand Up @@ -76,6 +77,16 @@ add_cxx_compiler_flag(-wd4514) # MSVC: unreferenced inline function has been rem
add_cxx_compiler_flag(-wd4710) # MSVC: function not inlined
add_cxx_compiler_flag(-wd4820) # MSVC: padding added after data member

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.
target_link_options(mlt-cpp PRIVATE --coverage)
else()
message(WARNING "[MLT] Coverage is not supported for compiler ${CMAKE_CXX_COMPILER_ID}")
endif()
endif()

target_include_directories(mlt-cpp
PUBLIC ${PROJECT_SOURCE_DIR}/include
PRIVATE ${PROJECT_SOURCE_DIR}/src
Expand Down
13 changes: 13 additions & 0 deletions cpp/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,16 @@ set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
add_subdirectory("${PROJECT_SOURCE_DIR}/vendor/googletest" "${CMAKE_CURRENT_BINARY_DIR}/googletest" EXCLUDE_FROM_ALL SYSTEM)

target_link_libraries(mlt-cpp-test mlt-cpp gtest_main)

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.
target_link_options(mlt-cpp-test PRIVATE --coverage)
# On macOS, force-load the static library to include coverage symbols
# Coverage initialization/writeout functions are not referenced, so they won't be
# linked from static libraries unless we force-load them
if(APPLE)
target_link_options(mlt-cpp-test PRIVATE -Wl,-force_load,$<TARGET_LINKER_FILE:mlt-cpp>)
endif()
endif()
endif()
18 changes: 18 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,24 @@ test-js: install-js
test-rust:
cd rust && cargo test

# Generate code coverage report for C++
[working-directory: 'cpp']
coverage-cpp:
mkdir -p coverage
cmake -B build-coverage -S . -DMLT_WITH_COVERAGE=ON
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.
echo "Coverage report generated at cpp/coverage/coverage.info"
lcov --summary coverage/coverage.info --ignore-errors inconsistent,corrupt || true

# Generate HTML code coverage report for C++
[working-directory: 'cpp']
coverage-cpp-html: coverage-cpp
genhtml coverage/coverage.info --output-directory coverage/html --title "MLT C++ Coverage" --legend --demangle-cpp --show-details --branch-coverage --ignore-errors inconsistent,corrupt
echo "HTML coverage report generated at file://{{justfile_directory()}}/cpp/coverage/html/index.html"

# Delete integration test output files
[private]
clean-int-test:
Expand Down