Fix code coverage: instrument the library and exclude third-party code#283
Open
K20shores wants to merge 3 commits into
Open
Fix code coverage: instrument the library and exclude third-party code#283K20shores wants to merge 3 commits into
K20shores wants to merge 3 commits into
Conversation
Coverage was reporting ~30% because the lcov capture only excluded test/*, so the totals included the FetchContent dependencies built under build/_deps/ (yaml-cpp, googletest, optionally fmt) plus inlined system/libstdc++ headers. The denominator was dominated by untested third-party code, masking the project's real coverage. - Add _deps/* and /usr/* to the lcov EXCLUDE list in CMakeLists.txt (BASE_DIRECTORY only sets path display, it does not restrict capture). - Add codecov.yml with an ignore list as a backstop for Codecov's own path matching. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #283 +/- ##
===========================================
+ Coverage 70.00% 89.13% +19.13%
===========================================
Files 5 37 +32
Lines 10 1611 +1601
===========================================
+ Hits 7 1436 +1429
- Misses 3 175 +172 🚀 New features to boost your workflow:
|
…ory) The real cause of the low (~30%) coverage: append_coverage_compiler_flags() was called after add_subdirectory(src), so CMAKE_CXX_FLAGS only picked up the coverage flags for the test targets defined later. The src/ library was built without instrumentation, so it produced no .gcno/.gcda data and the report covered only a handful of header lines inlined into the test TUs (51 lines). Move the include + append_coverage_compiler_flags() ahead of add_subdirectory(src) so the library itself is instrumented. The setup_target_for_coverage_lcov() target definition stays in the test block. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
COVERAGE_COMPILER_FLAGS included -fcheck=bounds,do,pointer and
-ffpe-trap=zero,overflow,invalid, which are gfortran-only. This is a
CXX-only project, so cc1plus rejects them ("valid for Fortran but not
for C++"). It went unnoticed because the flags were previously only
applied to the gtest test targets (no -Werror); now that the library
is instrumented (and built with -Werror), the warnings became errors.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Code coverage was reporting ~30%. Investigation found two issues, the second being the dominant one.
1. The library was never instrumented (root cause)
append_coverage_compiler_flags()was called afteradd_subdirectory(src). That function only appends toCMAKE_CXX_FLAGS, which affects targets defined after it runs — so thesrc/library was compiled without-fprofile-arcs -ftest-coverage. It produced no.gcno/.gcdadata, and the report covered only a handful of header lines inlined into the test translation units (lcov aggregated just 51 lines / 10 functions → 30% of functions).Fix: move the coverage
include()+append_coverage_compiler_flags()beforeadd_subdirectory(src)so the library is instrumented.2. Report included third-party / system code
The lcov capture only excluded
test/*, sobuild/_deps/*(yaml-cpp, googletest, fmt) and inlined/usr/*headers would be counted once the library is instrumented.Fix: add
_deps/*and/usr/*to the lcovEXCLUDElist, plus acodecov.ymlignore:backstop.Verification
Before this change the lcov summary reported
lines: 54.9% (28 of 51 lines)— i.e. it was measuring almost nothing. After instrumenting the library, the report should cover all ofsrc/**and the public headers, and the percentage will reflect real coverage.🤖 Generated with Claude Code