README
¶
coverage-now
Measures test coverage for the lines you actually changed in your branch — not the whole codebase.
Go's built-in coverage tools report per-package totals. CI tools like SonarQube want to know if your PR is covered. coverage-now diffs your branch against a base, parses the coverage profile, and reports only the lines you touched.
Install
go install codeberg.org/canoozie/coverage-now@latest
Or build from source:
git clone https://codeberg.org/canoozie/coverage-now
cd coverage-now
go build -o coverage-now .
Usage
First, generate a coverage profile with the standard Go tooling:
go test -coverprofile=coverage.out ./...
Then run coverage-now from your repo root:
coverage-now
It auto-detects the base branch (origin/main, origin/master, main, or master) and reads coverage.out by default.
To exclude generated or mock files:
coverage-now --exclude '**/fakes/**' --exclude '**/mocks/**'
Example output
Coverage on changed lines: 73.3% (22/30 lines)
File breakdown:
internal/parser/parser.go 100.0% (8/8)
internal/runner/runner.go 60.0% (6/10)
pkg/report/report.go 66.7% (8/12)
With -v to see which lines are uncovered:
Coverage on changed lines: 73.3% (22/30 lines)
File breakdown:
internal/parser/parser.go 100.0% (8/8)
internal/runner/runner.go 60.0% (6/10)
uncovered: 45-48, 67
pkg/report/report.go 66.7% (8/12)
uncovered: 23, 89-92
Flags
| Flag | Default | Description |
|---|---|---|
--base |
auto-detected | Base branch or commit to diff against |
--profile |
coverage.out |
Path to Go coverage profile |
--exclude |
Glob pattern to exclude (repeatable) | |
--min |
0 |
Minimum required coverage %; exits with code 2 if below |
-v |
false | Show uncovered line numbers per file |
--version |
Print version and exit |
CI integration
GitHub Actions
- name: Run tests
run: go test -coverprofile=coverage.out ./...
- name: Check PR coverage
run: coverage-now --base origin/main --min 80
Exit codes:
0— success (or coverage meets minimum)1— error (bad args, missing profile, no git repo)2— coverage below--minthreshold
GitLab CI
test:
script:
- go test -coverprofile=coverage.out ./...
- coverage-now --base origin/main --min 75 -v
How it works
- Diffs your branch against the merge base of
<base>andHEAD, matching how PR tools (SonarQube, GitHub) compute changed lines - Parses the Go coverage profile to get covered/uncovered blocks
- For each changed line, checks whether it falls inside a coverage block and whether that block was executed
- Lines with no coverage block (comments, blank lines, import declarations) are excluded from the count
Only the lines you changed are scored — untouched code does not affect the result.
Notes
- Run
coverage-nowfrom the root of your Go module (wherego.modlives) - The coverage profile must be generated for the same code you are diffing; run tests before
coverage-now - Use
--baseexplicitly in CI where the auto-detected remote refs may not be fetched - Use
--excludeto skip generated, mock, or fake files that skew the result (e.g.--exclude '**/fakes/**')
Documentation
¶
There is no documentation for this package.