runtime/coverage: confusing go test -cover + GOCOVERDIR behavior #66225
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
GoCommand
cmd/go
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
Go version
go1.22
Output of
go env
in your module/workspace:What did you do?
I've created an example here: https://github.com/hugelgupf/gocoverdir/blob/main/main_test.go
The gist is: I'd like to be able to use GOCOVERDIR with
go test -cover
.What did you see happen?
go test -cover
seems to create a temporaryGOCOVERDIR
, but does not expose that collected coverage literally anywhere.Clone that repo, and run the following commands:
$ go test -v === RUN TestXxx main_test.go:18: gocoverdir: main_test.go:22: out: warning: GOCOVERDIR not set, no coverage data emitted hello world --- PASS: TestXxx (0.28s) PASS ok github.com/hugelgupf/gocoverdir 0.307s
ok, that seems expected.
blowing a raspberry here. Why does
go test
create a GOCOVERDIR but not give me the results?If I supply my own
GOCOVERDIR
, why is it not available?$ GOCOVERDIR=cover go test -v === RUN TestXxx main_test.go:18: gocoverdir: cover main_test.go:22: out: hello world --- PASS: TestXxx (0.29s) PASS ok github.com/hugelgupf/gocoverdir 0.315s $ go tool covdata func -i=cover github.com/hugelgupf/gocoverdir/main.go:7: main 100.0% total (statements) 100.0%
the only combo that works!
What did you expect to see?
The use case of
GOCOVERDIR=x go test -coverprofile
is that I'd like to be able to have (a) mixed tests, and (b) be able to have onego test -cover ./...
at the root of the project. This makes that hard, as a test that wantsGOCOVERDIR
can't be run with-cover
.In order of priority, I'd request:
go
cmd docs document any of this.GOCOVERDIR
, don't makego test
set one.GOCOVERDIR
is set, I'd likego test -cover
to set it, collect the coverage, and expose it through the old text format with a conversion.GOCOVERDIR=./relative-path go test ./...
is likely a bit weird, because it'll expect arelative-path
directory in each package directory that it is running in. May be worth printing a warning and pointing the user to thego test -coverprofile=foo
behavior auto-collectingGOCOVERDIR
coverage in that case, as in point 3.The text was updated successfully, but these errors were encountered: