36e75f67ab
This patch fixes some problems with how "go test -cover" was handling tests involving A) multiple package tests and B) multiple packages matched by "-coverpkg". In such scenarios the expectation is that the percent statements covered metric for each package needs to be relative to all statements in all packages matched by the -coverpkg arg (this aspect of the reporting here was broken as part of GOEXPERIMENT=coverageredesign). The new scheme works as follows. If -coverpkg is in effect and is matching multiple packages, and we have multiple test targets, then: - each time a package is built for coverage, capture a meta-data file fragment corresponding to just the meta-data for that package. - create a new "writeCoverMeta" action, and interpose it between the build actions for the covered packages and the run actions. The "writeCoverMeta" action at runtime will emit a file "metafiles.txt" containing a table mapping each covered package (by import path) to its corresponding meta-data file fragment. - pass in the "metafiles.txt" file to each run action, so that when the test finishes running it will have an accurate picture of _all_ covered packages, permitting it to calculate the correct percentage. Concrete example: suppose we have a top level directory with three package subdirs, "a", "b", and "c", and from the top level, a user runs "go test -coverpkg=./... ./...". This will result in (roughly) the following action graph: build("a") build("b") build("c") | | | link("a.test") link("b.test") link("c.test") | | | run("a.test") run("b.test") run("c.test") | | | print print print With the new scheme, the action graph is augmented with a writeCoverMeta action and additional dependence edges to form build("a") build("b") build("c") | \ / | / | | v v | / | | writecovmeta<-|-------------+ | | ||| | | | ||\ | | link("a.test")/\ \ link("b.test") link("c.test") | / \ +-|--------------+ | | / \ | \ | | v v | v | run("a.test") run("b.test") run("c.test") | | | print print print A note on init functions: prior to GOEXPERIMENT=coverageredesign the "-coverpkg=..." flag was implemented by force-importing all packages matched by "-coverpkg" into each instrumented package. This meant that for the example above, when executing "a.test", the init function for package "c" would fire even if package "a" did not ordinarily import package "c". The new implementation does not do this sort of forced importing, meaning that the coverage percentages can be slightly different between 1.21 and 1.19 if there are user-written init funcs. Fixes #58770. Updates #24570. Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest,gotip-windows-amd64-longtest Change-Id: I7749ed205dce81b96ad7f74ab98bc1e90e377302 Reviewed-on: https://go-review.googlesource.com/c/go/+/495452 Reviewed-by: Bryan Mills <bcmills@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> |
||
---|---|---|
.github | ||
api | ||
doc | ||
lib/time | ||
misc | ||
src | ||
test | ||
.gitattributes | ||
.gitignore | ||
codereview.cfg | ||
CONTRIBUTING.md | ||
go.env | ||
LICENSE | ||
PATENTS | ||
README.md | ||
SECURITY.md |
The Go Programming Language
Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.
Gopher image by Renee French, licensed under Creative Commons 4.0 Attributions license.
Our canonical Git repository is located at https://go.googlesource.com/go. There is a mirror of the repository at https://github.com/golang/go.
Unless otherwise noted, the Go source files are distributed under the BSD-style license found in the LICENSE file.
Download and Install
Binary Distributions
Official binary distributions are available at https://go.dev/dl/.
After downloading a binary release, visit https://go.dev/doc/install for installation instructions.
Install From Source
If a binary distribution is not available for your combination of operating system and architecture, visit https://go.dev/doc/install/source for source installation instructions.
Contributing
Go is the work of thousands of contributors. We appreciate your help!
To contribute, please read the contribution guidelines at https://go.dev/doc/contribute.
Note that the Go project uses the issue tracker for bug reports and proposals only. See https://go.dev/wiki/Questions for a list of places to ask questions about the Go language.