Skip to content

cmd/go: dependencies not included in buildinfo for tests #76926

@peterebden

Description

@peterebden

Go version

go version go1.25.5 linux/amd64

Output of go env in your module/workspace:

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

What did you do?

Wrote a test that uses a library which interrogates deps in the debug build info to check versions. A minimal example (with a simpler third-party setup for clarity, but the same problem is exhibited):

package exec_test

import (
	"runtime/debug"
	"testing"

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
)

func TestBuildInfo(t *testing.T) {
	bi, ok := debug.ReadBuildInfo()
	require.True(t, ok)
	assert.Equal(t, "github.com/volary-ai/volary/common/exec.test", bi.Path)
	assert.Equal(t, "github.com/volary-ai/volary", bi.Main.Path)
	assert.NotEmpty(t, bi.Deps)
}

What did you see happen?

        	Error Trace:	/home/peter/git/volary/common/exec/exec_test.go:16
        	Error:      	Should NOT be empty, but was []

i.e. the BuildInfo object has an empty slice for Deps. Path and Main are populated as expected though.

What did you expect to see?

That it was not empty, that Deps was populated with the set of modules that are dependencies of the test (in this case at least github.com/stretchr/testify should be there).

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.GoCommandcmd/goNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions