Skip to content

feat(gocover): always collect coverage across all module packages - #47

Merged
thediveo merged 1 commit into
masterfrom
feat/gocover-cross-package-coverage
Nov 6, 2026
Merged

thediveo merged 1 commit into
masterfrom
feat/gocover-cross-package-coverage

Conversation

@thediveo

@thediveo thediveo commented Nov 6, 2026

Copy link
Copy Markdown
Owner

Problem

gocover only passes -coverpkg when uncovered-packages is configured. Without it, Go attributes coverage per package: statements of a package only count as covered when that package's own tests execute them. Code exercised only via the tests of other packages (for instance, a library package driven by the tests of a command or API package) shows up as uncovered, so the badge underreports.

Example: in Ghostwire, gocover reports 77.5 %, while the same root and non-root test runs with -coverpkg across all packages yield 80.0 %.

Change

  • gocover now always determines the packages of the module via go list ./... and passes them as -coverpkg, minus the uncovered-packages (unchanged behavior for those).
  • go list now honors the configured build tags (including --tags), so packages only built with these tags are included in the coverage, too.
  • Docs (NOTES.md and the generated README.md) mention the cross-package coverage.
  • Feature version bumped to 1.1.0, as badge values may change (increase) for existing users.

Tests

  • New scenario cross-package: package bar has its own test covering only half of its functions, while the other half is only covered by the tests of package foo. Expects 100 %; this scenario fails with the previous install.sh and passes with the change.
  • Ran all gocover scenarios (cross-package, default, root, uncovered-packages, run-only-tests, html, nonverbose, yellow) by installing the feature in a throwaway golang:1.26 container and running the scenario scripts as a non-root user (the devcontainer CLI wasn't available): all pass.

Previously, -coverpkg was only passed when uncovered-packages was set, so
code exercised only by the tests of other packages didn't count as
covered. gocover now always passes -coverpkg with all packages of the
module (honoring build tags), minus the uncovered-packages.

Signed-off-by: thediveo <thediveo@gmx.eu>
@thediveo
thediveo marked this pull request as ready for review November 6, 2026 15:48
@thediveo
thediveo merged commit 00fcb04 into master Nov 6, 2026
14 of 16 checks passed
@thediveo
thediveo deleted the feat/gocover-cross-package-coverage branch November 6, 2026 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant