Skip to content

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

Closed
@dev-gto

Description

@dev-gto

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
...

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions