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: source path regression for "go test -coverprofile" in local mode with GOEXPERIMENT=coverageredesign #56433

thanm opened this issue Oct 26, 2022 · 1 comment
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker


Copy link

thanm commented Oct 26, 2022

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

$ go version
go version devel go1.20-93957b0896 Fri Oct 21 12:13:58 2022 -0400 linux/amd64

Does this issue reproduce with the latest release?

No, only on tip.

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


What did you do?

Here is a toy program with two files, "prog.go" and "prog_test.go":

Run this command:

$ cd /tmp
$ go test -coverprofile=cov.out prog.go prog_test.go

What did you expect to see?

Expect to see a cov.out file with these contents:

mode: set
/tmp/prog.go:3.24,4.11 1 1
/tmp/prog.go:7.2,7.11 1 1
/tmp/prog.go:4.11,6.3 1 0
/tmp/prog.go:10.25,12.2 1 0
/tmp/prog.go:14.14,15.2 0 0

What did you see instead?

$ cat cov.out
mode: set
command-line-arguments/prog.go:3.24,4.11 1 1
command-line-arguments/prog.go:4.11,6.3 1 0
command-line-arguments/prog.go:7.2,7.11 1 1
command-line-arguments/prog.go:10.25,12.2 1 0
command-line-arguments/prog.go:14.14,15.2 0 0

It looks as though the new coverage implementation didn't properly bring forward this code in cmd/go:

This blob has the effect of forcing a full path for the source file recorded in the coverage instrumentation in the "local" case. This is happening for old-style instrumentation but not with new style instrumentation.

@thanm thanm added NeedsFix The path to resolution is known, but the work has not been done. release-blocker labels Oct 26, 2022
@thanm thanm added this to the Go1.20 milestone Oct 26, 2022
@thanm thanm self-assigned this Oct 26, 2022
Copy link

Change mentions this issue: cmd/{go,cover}: fix for -coverprofile path capture with local pkg

romaindoumenc pushed a commit to TroutSoftware/go that referenced this issue Nov 3, 2022
When coverage testing a local package (defined by a relative import
path such as "./foo/bar") the convention when "-coverprofile" is used
has been to capture source files by full pathname, as opposed to
recording the full import path or the invented import path
("command-line-arguments/") created by the go command in the case of
building named Go files. Doing this makes it much easier to use
collected profiles with "go tool -cover -html=<profile>".

The support for this feature/convention wound up being inadvertantly
dropped during the GOEXPERIMENT=coverageredesign implementation; this
patch restores it.

Fixes golang#56433.

Change-Id: Ib9556fdc86011b00c155caa614ab23e5148f3eb4
Reviewed-by: Bryan Mills <>
Run-TryBot: Than McIntosh <>
TryBot-Result: Gopher Robot <>
@golang golang locked and limited conversation to collaborators Nov 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
None yet

No branches or pull requests

2 participants