go: testing: Coverage() returns different values in 1.21 than 1.19.X
What version of Go are you using (go version)?
$ go version go version go1.19.12 linux/amd64
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (go env)?
go env Output
$ go env GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/home/leo/.cache/go-build" GOENV="/home/leo/.config/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/leo/.gvm/pkgsets/go1.19.12/global/pkg/mod" GONOPROXY="github.ibm.com" GONOSUMDB="github.ibm.com" GOOS="linux" GOPATH="/home/leo/.gvm/pkgsets/go1.19.12/global" GOPRIVATE="github.ibm.com" GOPROXY="https://proxy.golang.org,direct" GOROOT="/home/leo/.gvm/gos/go1.19.12" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/home/leo/.gvm/gos/go1.19.12/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.19.12" GCCGO="/usr/bin/gccgo" GOAMD64="v1" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/home/leo/Code/gateway/go.mod" GOWORK="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build470846844=/tmp/go-build -gno-record-gcc-switches"
What did you do?
Call testing.Coverage() and comparing the resulting value with the expected vaue that is working in 1.19.X
What did you expect to see?
testing.Coverage() to return the same value as 1.19.X.
I did not update to 1.20.X due to https://github.com/golang/go/issues/59590, testing.Coverage() was totally broken in 1.20.X and in principle it was fixed for 1.21.0 but the return value is not the same as 1.19.X, it is quite lower
What did you see instead?
Different values:
coverage: 89.1% of statements
Tests passed but coverage at 55.0% < 88.3%
coverage: 73.5% of statements
Tests passed but coverage at 49.1% < 76.3%
coverage: 90.0% of statements
Tests passed but coverage at 25.0% < 80.0%
coverage: 94.4% of statements
Tests passed but coverage at 39.3% < 92.6%
coverage: 96.7% of statements
Tests passed but coverage at 54.8% < 94.5%
About this issue
- Original URL
- State: open
- Created 3 years ago
- Comments: 15 (6 by maintainers)
Commits related to this issue
- runtime/coverage: fix snapshot total calculation Fixes #62212 — committed to AlexanderYastrebov/go by AlexanderYastrebov 3 years ago
- runtime/coverage: fix snapshot total calculation Sum number of counters to obtain total number of coverable units instead of using length of the section data. Updates #62212 — committed to AlexanderYastrebov/go by AlexanderYastrebov 3 years ago
As a potential workaround, running the tests with
GOEXPERIMENT=nocoverageredesignyields the old, pre-1.20 results.changed isn’t a clear enough signal, we’ll need to see if the old or new numbers are the correct ones.