Skip to content

cmd/go: coverpkg flag should be part of cache key #66504

@mitar

Description

@mitar

Go version

go version go1.22.1 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/root/.cache/go-build'
GOENV='/root/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.1'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='0'
GOMOD='/code/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 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3544536393=/tmp/go-build -gno-record-gcc-switches'

What did you do?

On this example repository I ran:

go test -covermode=atomic -cover -count 1 -coverpkg=./... ./...

and:

go test -covermode=atomic -cover -coverpkg=./... ./...

What did you see happen?

I expected in both cases all coverage numbers to be the same.

(I have the problem with coverage numbers themselves, but I will report that separately.)

What did you expect to see?

Different numbers:

$ go test -covermode=atomic -cover -count 1 -coverpkg=./... ./...
ok  	github.com/mitar/accurate-test-coverage	0.002s	coverage: 0.0% of statements in ./... [no tests to run]
ok  	github.com/mitar/accurate-test-coverage/otherpkg	0.002s	coverage: 75.0% of statements in ./...
ok  	github.com/mitar/accurate-test-coverage/pkg	0.003s	coverage: 25.0% of statements in ./...
$ go test -covermode=atomic -cover -coverpkg=./... ./...
ok  	github.com/mitar/accurate-test-coverage	(cached)	coverage: 0.0% of statements in ./... [no tests to run]
ok  	github.com/mitar/accurate-test-coverage/otherpkg	(cached)	coverage: 100.0% of statements in ./...
ok  	github.com/mitar/accurate-test-coverage/pkg	(cached)	coverage: 33.3% of statements in ./...

Metadata

Metadata

Assignees

No one assigned

    Labels

    GoCommandcmd/goNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions