Repository navigation
build: opt-in code-coverage targets (full report + patch/diff) - #30
Merged
Merged
Conversation
Adds a -DENABLE_COVERAGE=ON configure option plus three custom targets, all
off by default so normal and CI builds are unaffected:
- coverage full gcovr report for src/ + include/hotrod — terminal summary,
HTML (build/coverage/index.html), and Cobertura coverage.xml.
- coverage-diff patch coverage of only the lines changed vs COVERAGE_DIFF_BASE
(default origin/main) via diff-cover; HTML at coverage/patch.html.
-DCOVERAGE_DIFF_THRESHOLD=<pct> fails below a patch percentage.
- coverage-reset delete stale .gcda counters before a fresh run.
Tools (gcovr, diff-cover) are discovered with find_program, so a target is only
created when its tool is present.
Notes on two gotchas (see DECISIONS.md):
- ENABLE_COVERAGE forces a Debug build. Coverage wants -O0, but under a non-Debug
type the warnings block defines _FORTIFY_SOURCE=2, which errors at -O0 under
-Werror; appending -U_FORTIFY_SOURCE does not help because CMake de-duplicates
the repeated flag. Debug skips the define and yields -O0 -g.
- gcovr runs from the source root with relative --filters (from the build dir with
an absolute --root it matches no files); both targets pass the build dir as the
.gcda search path.
Docs: STATUS (where-things-live row), DECISIONS (rationale + gotchas), README
(Code coverage section).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
gcov can emit a negative branch hit count on some lines (e.g. src/codec/HeaderCodec.cpp:48) with a non-trivial data set, which gcovr treats as fatal and aborts the whole report. Pass gcovr's recommended --gcov-ignore-parse-errors negative_hits.warn_once_per_file so the report still generates (only the rare affected counts are unreliable). Applies to both the coverage and coverage-diff targets via the shared gcovr args. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68080 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
On a large data set (full ctest -> many .gcda), gcovr's parallel gcov workers race on the intermediate *.gcov.json.gz files written to the shared working dir, surfacing as "Output file ... doesn't exist but no error from GCOV detected" (a SanityCheckError, which is an AssertionError and therefore NOT catchable via --gcov-ignore-errors). Pass -j 1 so gcov runs serially. Slower but reliable; stacks with the existing negative-hits parse-error tolerance. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
diff-cover's --format html:.../coverage/patch.html does not create the parent directory, so running `coverage-diff` without first running `coverage` (which does the mkdir) failed with FileNotFoundError. Add an explicit make_directory step to the coverage-diff target so it works standalone. Co-Authored-By: Claude Opus 4.8 <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.
Closes #31.
Adds local code-coverage reporting to the build — a
-DENABLE_COVERAGE=ONoption plus three CMake targets. All off by default; normal and CI builds are unaffected. There is no coverage gate; these are developer reporting aids.Targets
coveragegcovrreport forsrc/+include/hotrod/— terminal summary, HTML (build/coverage/index.html), and Coberturacoverage.xml.coverage-diffCOVERAGE_DIFF_BASE(defaultorigin/main) viadiff-cover; HTML atcoverage/patch.html.-DCOVERAGE_DIFF_THRESHOLD=<pct>fails below a patch %.coverage-reset.gcdacounters before a fresh run.Tools (
gcovr,diff-cover) are discovered withfind_program, so a target is only created when its tool is present (with a helpful status message otherwise).Usage
Two gotchas handled (details in DECISIONS.md)
ENABLE_COVERAGEforces a Debug build. Coverage needs-O0, but under a non-Debug type the warnings block defines_FORTIFY_SOURCE=2, which errors at-O0under-Werror; appending-U_FORTIFY_SOURCEdoesn't help because CMake de-duplicates the repeated flag. Debug skips the define and gives-O0 -g.gcovris run from the source root with relative--filters (from the build dir with an absolute--rootit matches 0 files); both targets pass the build dir as the.gcdasearch path.Verified
coverage— produces summary + HTML + XML.coverage-diff— runs clean (modern--format html:syntax, no deprecation warning); reports real per-file patch coverage against a ref with source changes, and correctly "no lines" for a docs-only diff.RelWithDebInfo.Docs
STATUS (where-things-live row), DECISIONS (rationale + gotchas), README (a "Code coverage" section).
🤖 Generated with Claude Code