Skip to content

cmd/go: runtime/debug build information not populated for test binaries when package name is not 'main' #33976

Closed
@bcmills

Description

@bcmills

What did you do?

https://play.golang.org/p/0ITNcl4kXGN

$ gotip version
go version devel +8c5de667 Fri Aug 30 08:28:40 2019 +0000 linux/amd64

foo$ gotip mod init foo
go: creating new go.mod: module foo

foo$ cat > foo_test.go
package foo_test

import (
        "runtime/debug"
        "testing"
)

func TestBuildInfo(t *testing.T) {
        info, ok := debug.ReadBuildInfo()
        if !ok {
                t.Fatal("no debug info")
        }
        t.Log(info.Main.Version)
}

foo$ go test

What did you expect to see?

=== RUN   TestBuildInfo
--- PASS: TestBuildInfo (0.00s)
    foo_test.go:13: (devel)
PASS

(https://play.golang.org/p/0ITNcl4kXGN)

What did you see instead?

--- FAIL: TestBuildInfo (0.00s)
    foo_test.go:11: no debug info
FAIL

CC @jayconrod @rsc; see also #33975.

Metadata

Metadata

Assignees

No one assigned

    Labels

    GoCommandcmd/goNeedsFixThe path to resolution is known, but the work has not been done.modules

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions