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

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

Comments

@thanm
Copy link
Contributor

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)?

linux/amd64

What did you do?

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

https://go.dev/play/p/sJ-n2bOWQSi

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:

https://go.googlesource.com/go/+/51af90445696772703ed88d967e8c23c8e9e992d/src/cmd/go/internal/load/pkg.go#3403

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
@gopherbot
Copy link

Change https://go.dev/cl/445917 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-on: https://go-review.googlesource.com/c/go/+/445917
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
@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.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Projects
None yet
Development

No branches or pull requests

2 participants