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: improperly synchronized -coverprofile output for packages with no tests #63356

Closed
thanm opened this issue Oct 3, 2023 · 1 comment
Closed
Assignees
Labels
GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@thanm
Copy link
Contributor

thanm commented Oct 3, 2023

What version of Go are you using (go version)?

Using tip:

$ go version
go version devel go1.22-90276c268b Tue Oct 3 18:06:38 2023 +0000 linux/amd64

Does this issue reproduce with the latest release?

No, only with tip.

What operating system and processor architecture are you using (go env)?

linux/amd64

What did you do?

For this set of packages:

https://go.dev/play/p/5nloPBjspW9?v=gotip

run

$ go test -coverprofile=foo.p ./...
...
$ go tool cover -html=foo.p

What did you expect to see?

No error from go tool -cover.

What did you see instead?

$ go test -coverprofile=foo.p ./...
?   	M/n	[no test files]
	M/xinternal/q		coverage: 0.0% of statements
	M/it		coverage: 0.0% of statements
	M/x		coverage: 0.0% of statements
	M/xinternal		coverage: 0.0% of statements
ok  	M/a	0.022s	coverage: 100.0% of statements
ok  	M/aa	0.020s	coverage: 77.8% of statements
ok  	M/b	0.021s	coverage: 100.0% of statements
ok  	M/deadstuff	0.019s	coverage: 33.3% of statements
ok  	M/main	0.018s	coverage: 75.0% of statements
ok  	M/onlytest	0.018s	coverage: [no statements]
$ go tool cover -html=foo.p
cover: can't read "t.go": open /tmp/covex/t.go: no such file or directory
$

What's happening here is that the cover profile fragments generated for the no-test packages are being written to a temporary coverage profile that has an unqualified path, meaning that if multiple test runs are happening in parallel we'll get a collision (this is what happens with foo.p above).

@thanm thanm added NeedsFix The path to resolution is known, but the work has not been done. GoCommand cmd/go labels Oct 3, 2023
@thanm thanm added this to the Go1.22 milestone Oct 3, 2023
@thanm thanm self-assigned this Oct 3, 2023
@gopherbot
Copy link

Change https://go.dev/cl/532555 mentions this issue: cmd/go: fix objdir for run actions for -cover no-test packages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

2 participants