Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: go 1.22.0 inconsistent and variable code coverage output for the same folder #65570

Closed
dev-gto opened this issue Feb 7, 2024 · 15 comments
Assignees
Labels
Milestone

Comments

@dev-gto
Copy link

dev-gto commented Feb 7, 2024

Go version

go version go1.22.0 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/hamada/.cache/go-build'
GOENV='/home/hamada/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/hamada/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/hamada/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go1.22.0'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go1.22.0/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.0'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/hamada/go/src/gitlab.in.registro.br/dev/br/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3637209596=/tmp/go-build -gno-record-gcc-switches'

What did you do?

Having a directory called, e.g., holiday with some go files and their corresponding test files, I called the go test -cover from the parent directory. Depending on directories arguments, I have different percentage values, which wasn't occurring on go < 1.22.0.

What did you see happen?

DEV=dev go test -tags dev -cover -buildvcs=false -ldflags '-s -w' ./holiday/
ok  	gitlab.in.registro.br/dev/br/core/holiday	(cached)	coverage: 97.6% of statements

DEV=dev go test -tags dev -cover -buildvcs=false -ldflags '-s -w' ./h*
...
ok  	gitlab.in.registro.br/dev/br/core/holiday	0.005s	coverage: 47.3% of statements

DEV=dev go test -tags dev -cover -buildvcs=false -ldflags '-s -w' ./...
...
ok  	gitlab.in.registro.br/dev/br/core/holiday	(cached)	coverage: 23.5% of statements
...

What did you expect to see?

A consistent percentage value (in this case, 97.6%) for all commands:

DEV=dev go test -tags dev -cover -buildvcs=false -ldflags '-s -w' ./holiday/
ok  	gitlab.in.registro.br/dev/br/core/holiday	(cached)	coverage: 97.6% of statements

DEV=dev go test -tags dev -cover -buildvcs=false -ldflags '-s -w' ./h*
...
ok  	gitlab.in.registro.br/dev/br/core/holiday	0.005s	coverage: 97.6% of statements

DEV=dev go test -tags dev -cover -buildvcs=false -ldflags '-s -w' ./...
...
ok  	gitlab.in.registro.br/dev/br/core/holiday	(cached)	coverage: 97.6% of statements
...
@dev-gto dev-gto changed the title go 1.22.0: inconsistent and variable code coverage output for the same folder cmd/go: go 1.22.0 inconsistent and variable code coverage output for the same folder Feb 7, 2024
@bcmills
Copy link
Contributor

bcmills commented Feb 7, 2024

@bcmills bcmills added the GoCommand cmd/go label Feb 7, 2024
@bcmills bcmills added this to the Backlog milestone Feb 7, 2024
@thanm thanm self-assigned this Feb 7, 2024
@thanm
Copy link
Contributor

thanm commented Feb 7, 2024

Thanks for the report. I'll take a look.

@thanm
Copy link
Contributor

thanm commented Feb 7, 2024

@dev-gto would you kindly post a pointer to the code that you are working with, so that I can reproduce the problem on my machine? Thanks.

@thanm thanm added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Feb 7, 2024
@dev-gto
Copy link
Author

dev-gto commented Feb 7, 2024

@thanm , actually my project is a private and large one.

Despite some testing errors (the original project does not emit any errors), you can reproduce with
https://github.com/registrobr/zxcvbn-go

go test -cover ./...
ok  	github.com/registrobr/zxcvbn-go	(cached)	coverage: 60.6% of statements
ok  	github.com/registrobr/zxcvbn-go/adjacency	(cached)	coverage: 40.8% of statements
	github.com/registrobr/zxcvbn-go/data		coverage: 0.0% of statements
	github.com/registrobr/zxcvbn-go/data/ptbr		coverage: 0.0% of statements
ok  	github.com/registrobr/zxcvbn-go/entropy	(cached)	coverage: 35.9% of statements
...
go test -cover ./[ae]*
ok  	github.com/registrobr/zxcvbn-go/adjacency	(cached)	coverage: 83.3% of statements
ok  	github.com/registrobr/zxcvbn-go/entropy	(cached)	coverage: 50.0% of statements

@AlexanderYastrebov
Copy link
Contributor

#62212 might be related

@aaron42net
Copy link

GOEXPERIMENT=nocoverageredesign go test -cover ./... does appear to provide the expected coverage result, matching running go test -cover for each package separately. So this does seem related to the coverage redesign.

I've confirmed this with both @dev-gto's example above and a large private monorepo where I also encountered the issue.

@dev-gto
Copy link
Author

dev-gto commented Feb 9, 2024

Indeed, GOEXPERIMENT=nocoverageredesign returns the expected values on my original files

@dev-gto
Copy link
Author

dev-gto commented Apr 5, 2024

hi!
Any news on this? go 1.22.2 still has this issue.

@jehowell
Copy link

Code coverage has been broken for about a year now... Please can someone make this a priority to fix.

@sfc-gh-jlangefeld
Copy link

I came here because I just ran into this as well on 1.22.2

youngbupark added a commit to radius-project/radius that referenced this issue May 1, 2024
# Description

This is to upgrade to 1.22.2. However we might need to wait until the
fix for coverage drop issue is ready -
golang/go#65570

## Type of change

- This pull request is a minor refactor, code cleanup, test improvement,
or other maintenance task and doesn't change the functionality of Radius
(issue link optional).

<!--

Please update the following to link the associated issue. This is
required for some kinds of changes (see above).

-->

Fixes: #issue_number

Signed-off-by: Young Bu Park <youngp@microsoft.com>
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/592204 mentions this issue: internal/coverage: refactor EmitPercent in preparation for bugfix

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/592205 mentions this issue: cmd/go: fix problems with coverage percentage reporting w/ -coverpkg

gopherbot pushed a commit that referenced this issue Jun 14, 2024
Refactor cformat.EmitPercent to accept a package filter (list of
packages to report). This is a no-op in terms of exposed coverage
functionality, but we will need this feature in a subsequent patch.

Updates #65570.

Change-Id: I04ddc624a634837ea31c12ec395aa1295a0ea1f1
Reviewed-on: https://go-review.googlesource.com/c/go/+/592204
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
@dev-gto
Copy link
Author

dev-gto commented Sep 5, 2024

1.23.1 and 1.22.7 still have this issue, although it was closed.

@dev-gto
Copy link
Author

dev-gto commented Sep 5, 2024

1.23.1 and 1.22.7 still have this issue, although it was closed.

sorry about that, actually it is working

@pepehandsjpg
Copy link

1.23.1 and 1.22.7 still have this issue, although it was closed.

sorry about that, actually it is working

is it? Can't see the difference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

10 participants