Skip to content

Commit 1439482

Browse files
committed
fix: enhance lcov coverage report commands to handle inconsistent data and clean up gcda files
1 parent 09a918c commit 1439482

File tree

4 files changed

+417
-35
lines changed

4 files changed

+417
-35
lines changed

CMakeLists.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,12 +269,14 @@ if (UA2F_BUILD_TESTS)
269269
)
270270

271271
# Add lcov target for preprocessed coverage data
272+
# Note: delete ua2f.dir gcda first — the production binary is never executed,
273+
# so its empty coverage data would override test coverage for shared sources.
272274
add_custom_target(coverage-lcov
273-
COMMAND echo "Running unit tests and generating lcov report"
275+
COMMAND find ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/ua2f.dir -name "*.gcda" -delete
274276
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/ua2f_test
275277
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/ua2f_handler_test
276-
COMMAND lcov --capture --directory . --output-file coverage.info --ignore-errors mismatch --branch-coverage
277-
COMMAND lcov --remove coverage.info '*/test/*' '*/build*/_deps/*' '/usr/*' '*/googletest/*' '*_deps/*' '*/third/*' --output-file coverage.info --ignore-errors unused --branch-coverage
278+
COMMAND lcov --capture --directory . --output-file coverage.info --ignore-errors mismatch,inconsistent --branch-coverage
279+
COMMAND lcov --remove coverage.info '*/test/*' '*/build*/_deps/*' '/usr/*' '*/googletest/*' '*_deps/*' '*/third/*' --output-file coverage.info --ignore-errors unused,inconsistent --branch-coverage
278280
COMMAND lcov --list coverage.info --branch-coverage
279281
COMMENT "Generating lcov coverage report"
280282
DEPENDS ua2f_test ua2f_handler_test
@@ -342,8 +344,8 @@ if (UA2F_ENABLE_COVERAGE)
342344
)
343345

344346
add_custom_target(coverage-integration-process
345-
COMMAND lcov --capture --directory . --output-file coverage-integration.info --ignore-errors mismatch --branch-coverage
346-
COMMAND lcov --remove coverage-integration.info '*/test/*' '*/build*/_deps/*' '/usr/*' '*/googletest/*' '*_deps/*' '*/third/*' --output-file coverage-integration.info --ignore-errors unused --branch-coverage
347+
COMMAND lcov --capture --directory . --output-file coverage-integration.info --ignore-errors mismatch,inconsistent --branch-coverage
348+
COMMAND lcov --remove coverage-integration.info '*/test/*' '*/build*/_deps/*' '/usr/*' '*/googletest/*' '*_deps/*' '*/third/*' --output-file coverage-integration.info --ignore-errors unused,inconsistent --branch-coverage
347349
COMMAND lcov --list coverage-integration.info --branch-coverage
348350
COMMENT "Process integration test coverage data with lcov"
349351
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}

0 commit comments

Comments
 (0)