coverage-now

command module
v0.0.0-...-155e19a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2026 License: MIT Imports: 10 Imported by: 0

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 --min threshold
GitLab CI
test:
  script:
    - go test -coverprofile=coverage.out ./...
    - coverage-now --base origin/main --min 75 -v

How it works

  1. Diffs your branch against the merge base of <base> and HEAD, matching how PR tools (SonarQube, GitHub) compute changed lines
  2. Parses the Go coverage profile to get covered/uncovered blocks
  3. For each changed line, checks whether it falls inside a coverage block and whether that block was executed
  4. 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-now from the root of your Go module (where go.mod lives)
  • The coverage profile must be generated for the same code you are diffing; run tests before coverage-now
  • Use --base explicitly in CI where the auto-detected remote refs may not be fetched
  • Use --exclude to skip generated, mock, or fake files that skew the result (e.g. --exclude '**/fakes/**')

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL