Go version
go version go1.22.0 linux/amd64, go version go1.22.0 darwin/amd64, go version go1.22.0 windows/amd64
Output of go env in your module/workspace:
GO111MODULE=''
GOARCH='amd64'
GOBIN='/home/martin/bin'
GOCACHE='/home/martin/.cache/go-build'
GOENV='/home/martin/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/mnt/c/dev/git/pkg/mod'
GONOPROXY='*.mycompany.com'
GONOSUMDB='*.mycompany.com'
GOOS='linux'
GOPATH='/mnt/c/dev/git'
GOPRIVATE='*.mycompany.com'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/mnt/c/dev/git/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.0.linux-amd64'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/mnt/c/dev/git/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.0.linux-amd64/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.0'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/mnt/c/dev/git/golang-test-cover/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-build2876750124=/tmp/go-build -gno-record-gcc-switches'
What did you do?
Have a main.go and a package internal with some functions.
See reproducer: https://github.com/sonic-martin/golang-test-cover
Run go test:
go test -v ./... -coverprofile=coverage.out -coverpkg=./internal/... -covermode count
go tool cover -html=coverage.out -o coverage.html
go tool cover -func=coverage.out
What did you see happen?
$ go test -v ./... -coverprofile=coverage.out -coverpkg=./internal/... -covermode count
example.com/m: open /tmp/go-build1123786392/b002/covmeta.f6e4431d5ec1fd71f02b3ce4e56eb691a86525173d917007425576a7d9db7c72: no such file or directory
=== RUN TestHelloer
--- PASS: TestHelloer (0.00s)
PASS
coverage: 100.0% of statements in ./internal/...
ok example.com/m/internal 0.003s coverage: 100.0% of statements in ./internal/...
$ echo $?
1
$ go tool cover -html=coverage.out -o coverage.html
$ go tool cover -func=coverage.out
example.com/m/internal/helloer.go:3: Helloer 100.0%
total: (statements) 100.0%
coverage.out:
mode: count
example.com/m/internal/helloer.go:3.23,5.2 1 1
The both outputs of go tool cover are fine.
What did you expect to see?
Before go 1.22.0 it worked fine and no no such file or directory errors happend.
There are two workarounds:
(1) go test with -coverpkg equal to the folder/packages processed
go test -v ./... -coverprofile=coverage.out -coverpkg=./... -covermode count
example.com/m coverage: 0.0% of statements
=== RUN TestHelloer
--- PASS: TestHelloer (0.00s)
PASS
coverage: 50.0% of statements in ./...
ok example.com/m/internal 0.003s coverage: 50.0% of statements in ./...
But changes semantic of the coverage result.
(2) go test with GOEXPERIMENT=nocoverageredesign
$ GOEXPERIMENT=nocoverageredesign go test -v ./... -coverprofile=coverage.out -coverpkg=./internal/... -covermode count
? example.com/m [no test files]
=== RUN TestHelloer
--- PASS: TestHelloer (0.00s)
PASS
coverage: 100.0% of statements in ./internal/...
ok example.com/m/internal 0.002s coverage: 100.0% of statements in ./internal/...
See the discussion from Brian Candler, Aldemar F, Thomas McNulty and me in the mailing list:
https://groups.google.com/g/golang-nuts/c/PjAWIdSdQHc
Go version
go version go1.22.0 linux/amd64, go version go1.22.0 darwin/amd64, go version go1.22.0 windows/amd64
Output of
go envin your module/workspace:What did you do?
Have a
main.goand a packageinternalwith some functions.See reproducer: https://github.com/sonic-martin/golang-test-cover
Run
go test:go test -v ./... -coverprofile=coverage.out -coverpkg=./internal/... -covermode count go tool cover -html=coverage.out -o coverage.html go tool cover -func=coverage.outWhat did you see happen?
coverage.out:
The both outputs of
go tool coverare fine.What did you expect to see?
Before
go 1.22.0it worked fine and nono such file or directoryerrors happend.There are two workarounds:
(1)
go testwith-coverpkgequal to the folder/packages processedBut changes semantic of the coverage result.
(2)
go testwithGOEXPERIMENT=nocoverageredesignSee the discussion from Brian Candler, Aldemar F, Thomas McNulty and me in the mailing list:
https://groups.google.com/g/golang-nuts/c/PjAWIdSdQHc