Skip to content

cmd/go: go ignores overlay map when using coverpkg flag #73802

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

Open
AdamKorcz opened this issue May 20, 2025 · 2 comments · May be fixed by #73824
Open

cmd/go: go ignores overlay map when using coverpkg flag #73802

AdamKorcz opened this issue May 20, 2025 · 2 comments · May be fixed by #73824
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@AdamKorcz
Copy link

AdamKorcz commented May 20, 2025

Go version

go1.23.4 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/adam/.cache/go-build'
GOENV='/home/adam/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/adam/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/adam/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/adam/go/pkg/mod/golang.org/[email protected]'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/adam/go/pkg/mod/golang.org/[email protected]/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.23.4'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/adam/.config/go/telemetry'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/tmp/gopoc/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build4048790992=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I created the following files:

/tmp/mymodule/go.mod:

module module3

go 1.23.4

/tmp/mymodule/overlay.json:

{
        "Replace": {
                "/tmp/mymodule/test/context_builder.go": "/tmp/context_builder.go"
        }
}

/tmp/mymodule/submodule1/one.go:

package submodule1

/tmp/mymodule/submodule1/one_test.go:

package submodule1

import (
        "strings"
        "testing"
        _ "module3/test"
)

func TestSomething(t *testing.T) {
        _ = strings.Repeat("abc", 2)
}

/tmp/mymodule/test/context_builder.go:

package test

import (
        "testing"
)

type StringGenerator func(n int) string

type Builder struct {
        T *testing.T
}

/tmp/context_builder.go:

package test

import (
        "testing"
)

func init() {
        panic("Here")
}

type StringGenerator func(n int) string

type Builder struct {
        T *testing.T
}

From /tmp/mymodule I then ran go test -run TestSomething ./submodule1 -coverpkg=./... -overlay=$PWD/overlay.json

What did you see happen?

ok module3/submodule1 0.005s coverage: [no statements]

What did you expect to see?

panic: Here

goroutine 1 [running]:
module3/test.init.0()
        /tmp/mymodule/test/context_builder.go:8 +0x25
FAIL    module3/submodule1      0.008s
FAIL

If I instead run go test -run TestSomething ./submodule1 -overlay=$PWD/overlay.json (without the coverpkg flag), I see this panic.

@dr2chase
Copy link
Contributor

@adonovan @golang/command-line

@dr2chase dr2chase added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label May 21, 2025
@adonovan adonovan added the GoCommand cmd/go label May 21, 2025
@kumarlokesh kumarlokesh linked a pull request May 22, 2025 that will close this issue
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/675435 mentions this issue: cmd/go: fix coverage overlay

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants