cmd/go: source path regression for "go test -coverprofile" in local mode with GOEXPERIMENT=coverageredesign
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.
Change https://go.dev/cl/445917 mentions this issue: cmd/{go,cover}: fix for -coverprofile path capture with local pkg