This document explains how to set up and use Codecov for code coverage reporting in this project.
Codecov is a code coverage reporting service that:
- Tracks coverage trends over time
- Shows coverage changes in pull requests
- Provides detailed coverage reports
- Is free for public repositories
- Go to https://codecov.io
- Click "Sign Up"
- Choose "Sign up with GitHub"
- Authorize Codecov to access your GitHub account
- After signing in, click "Add new repository"
- Find your repository in the list
- Click "Enable"
- Codecov will now track coverage for this repository
For public repositories, the token is optional but recommended for reliability:
- In Codecov, go to your repository settings
- Copy the Repository Upload Token
- In your GitHub repository, go to Settings → Secrets and variables → Actions
- Click "New repository secret"
- Name:
CODECOV_TOKEN - Value: paste the token from Codecov
- Click "Add secret"
Note: For public repos, the GitHub Action will auto-detect the token, so this step is optional.
When you run the debug-full preset locally:
cmake --preset debug-full
cmake --build --preset debug-full
ctest --preset debug-full
cmake --build --preset debug-full --target coverageThe coverage target will:
- Generate coverage data
- Create an HTML report at
build/debug-full/coverage/html/index.html - Check if coverage meets the 80% threshold (fails if below)
In GitHub Actions, the debug-full preset job will:
- Build and test with coverage enabled
- Generate the coverage report
- Upload to Codecov (only on Linux + Clang to avoid duplicates)
- Fail if coverage is below 80%
The project enforces a minimum 80% line coverage threshold.
- Locally: The
cmake --build --preset debug-full --target coveragecommand will fail if coverage is below 80% - In CI: The GitHub Actions job will fail if coverage is below 80%
To change the threshold, modify the COVERAGE_THRESHOLD CMake variable:
Locally:
cmake --preset debug-full -DCOVERAGE_THRESHOLD=90In CI: Edit .github/workflows/ci.yml and add the variable to the CMake configure step.
In CMakePresets.json: Add to the debug-full preset:
{
"name": "debug-full",
"cacheVariables": {
"ENABLE_SANITIZERS": "ON",
"ENABLE_COVERAGE": "ON",
"ENABLE_LINTING": "ON",
"COVERAGE_THRESHOLD": "90"
}
}- Go to https://codecov.io
- Select your repository
- View:
- Overall coverage percentage
- Coverage trends (graphs over time)
- File-by-file coverage
- PR coverage changes
Codecov automatically comments on PRs with:
- Coverage change (e.g., "Coverage increased by 2.3%")
- Files with decreased coverage
- Link to detailed report
Open the HTML report in your browser:
# Linux
xdg-open build/debug-full/coverage/html/index.html
# macOS
open build/debug-full/coverage/html/index.htmlCause: CI might be using a different coverage file path.
Solution: Check the Codecov upload step in .github/workflows/ci.yml to ensure the path matches your build directory.
Cause: Coverage file is empty or malformed.
Solution:
- Ensure tests ran successfully:
ctest --preset debug-full - Check that
.gcdafiles were generated inbuild/debug-full/ - Re-run the coverage target
Cause: Token not configured or upload failed.
Solution:
- Check GitHub Actions logs for the "Upload coverage to Codecov" step
- Ensure the repository is enabled in Codecov
- (Optional) Add
CODECOV_TOKENsecret to GitHub
Cause: Coverage excludes tests, external code, and system headers.
Solution: This is intentional. The coverage percentage only measures your production code in src/, not test code or dependencies.
-
Run coverage locally before pushing:
cmake --build --preset debug-full --target coverage
-
Check PR coverage comments: Codecov will warn you if your PR decreases coverage
-
Aim for meaningful coverage: Don't just write tests to hit 80% — write tests that verify behavior
-
Review coverage reports: Use the HTML report to find untested code paths
-
Update threshold as needed: If 80% is too easy/hard, adjust it in
CMakePresets.json
| Task | Command |
|---|---|
| Generate coverage locally | cmake --build --preset debug-full --target coverage |
| View HTML report | open build/debug-full/coverage/html/index.html |
| Check threshold | Automatic (fails if < 80%) |
| View Codecov dashboard | https://codecov.io |
| Change threshold | cmake --preset debug-full -DCOVERAGE_THRESHOLD=90 |
For more information on testing and sanitizers, see Testing Guide.