Repository navigation
feat(gocover): always collect coverage across all module packages - #47
Merged
Merged
Conversation
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>
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.
Problem
gocoveronly passes-coverpkgwhenuncovered-packagesis 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,
gocoverreports 77.5 %, while the same root and non-root test runs with-coverpkgacross all packages yield 80.0 %.Change
gocovernow always determines the packages of the module viago list ./...and passes them as-coverpkg, minus theuncovered-packages(unchanged behavior for those).go listnow honors the configured build tags (including--tags), so packages only built with these tags are included in the coverage, too.NOTES.mdand the generatedREADME.md) mention the cross-package coverage.Tests
cross-package: packagebarhas its own test covering only half of its functions, while the other half is only covered by the tests of packagefoo. Expects 100 %; this scenario fails with the previousinstall.shand passes with the change.cross-package,default,root,uncovered-packages,run-only-tests,html,nonverbose,yellow) by installing the feature in a throwawaygolang:1.26container and running the scenario scripts as a non-root user (the devcontainer CLI wasn't available): all pass.