Open alainstoffels opened 8 months ago
In our codebase, this has caused our coverage file to increase from 260 MB to 1.53 GB.
Also, it's likely that this is related to https://github.com/golang/go/issues/65570
Does GOEXPERIMENT=nocoverageredesign go test -cover -coverpkg=./... -coverprofile=coverage.out ./...
work around the problem? If so, it is also related to the coverage redesign (which seems likely).
Does
GOEXPERIMENT=nocoverageredesign go test -cover -coverpkg=./... -coverprofile=coverage.out ./...
work around the problem? If so, it is also related to the coverage redesign (which seems likely).
That does indeed solve the problem.
From what I can see, this behavior is present well prior to the coverage redesign work (I see it in Go 1.19).
Here is an example:
$ go version
go version go1.19.13 linux/amd64
$ go test -short -coverprofile=/tmp/c.p -coverpkg=bytes,archive/tar bytes archive/tar
ok bytes 0.097s coverage: 40.4% of statements in bytes, archive/tar
ok archive/tar 0.122s coverage: 57.2% of statements in bytes, archive/tar
$ fgrep buffer.go:77 /tmp/c.p
bytes/buffer.go:77.28,77.49 1 1
bytes/buffer.go:77.28,77.49 1 0
$
Similar behavior on tip with GOEXPERIMENT=nocoverageredesign:
$ go version
go version devel go1.23-39ec246e73 Tue Feb 6 22:21:42 2024 +0000 linux/amd64
$ rm -f /tmp/c.p
$ GOEXPERIMENT=nocoverageredesign go test -short -coverprofile=/tmp/c.p -coverpkg=bytes,archive/tar bytes archive/tar
ok bytes 0.108s coverage: 40.3% of statements in bytes, archive/tar
ok archive/tar 0.095s coverage: 56.7% of statements in bytes, archive/tar
$ fgrep buffer.go:66 /tmp/c.p
bytes/buffer.go:66.34,67.14 1 0
bytes/buffer.go:66.34,67.14 1 1
$
Go version
go version go1.22.0 windows/amd64
Output of
go env
in your module/workspace:What did you do?
Clone https://github.com/alainstoffels/coverageRepro Run inside the root of the repo:
go test -cover -coverpkg=./... -coverprofile=coverage.out ./...
What did you see happen?
coverage.out now contains 2 lines for
coverageRepro/bar/bar.go
. One where it indicates that it's not covered, and another where it indicates that it is covered:foo.Foo()
callsbar.Bar()
, sofoo.TestFoo()
should coverbar.Bar()
.What did you expect to see?
I would expect it to output a single line for
coverageRepro/bar/bar.go
, indicating it as covered, like it did before the 1.22 update: