# Ensure buildinfo is populated on test binaries even if they
# are not tests for package main. See issue #33976.

[short] skip 'invokes go test'

go mod init foo
go get example.com/version@v1.0.0

go test -v
stdout '(devel)'
stdout 'example.com/version v1.0.0'

-- foo_test.go --
package foo

import (
        "runtime/debug"
        "testing"

        _ "example.com/version"
)

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

        for _, d := range info.Deps {
                t.Log(d.Path, d.Version)
        }
}
