diff options
| author | Stefan VanBuren <vanburenstefan@gmail.com> | 2026-03-17 20:09:35 -0400 |
|---|---|---|
| committer | Michael Matloob <matloob@golang.org> | 2026-03-20 09:31:43 -0700 |
| commit | a45c8032bbfdfb4c43cb56536f987501e6709a70 (patch) | |
| tree | da656ebe3052ef5f393d38aae32c9181b23e8695 /src | |
| parent | 79a8ccab29c435966dd41fc8dda144de5dca073e (diff) | |
| download | go-a45c8032bbfdfb4c43cb56536f987501e6709a70.tar.xz | |
cmd/go: include test deps in buildinfo
Fixes #76926
Change-Id: I822dd6363dea1c4ad73df5958964c1bfe2c46d19
Reviewed-on: https://go-review.googlesource.com/c/go/+/756240
Reviewed-by: Michael Matloob <matloob@google.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/cmd/go/internal/load/test.go | 18 | ||||
| -rw-r--r-- | src/cmd/go/testdata/script/test_buildinfo.txt | 13 |
2 files changed, 20 insertions, 11 deletions
diff --git a/src/cmd/go/internal/load/test.go b/src/cmd/go/internal/load/test.go index f9bdd5e1fc..bb1bedd0d8 100644 --- a/src/cmd/go/internal/load/test.go +++ b/src/cmd/go/internal/load/test.go @@ -294,15 +294,6 @@ func TestPackagesAndErrors(loaderstate *modload.State, ctx context.Context, done pb := p.Internal.Build pmain.DefaultGODEBUG = defaultGODEBUG(loaderstate, pmain, pb.Directives, pb.TestDirectives, pb.XTestDirectives) - if !opts.SuppressBuildInfo && (pmain.Internal.BuildInfo == nil || pmain.DefaultGODEBUG != p.DefaultGODEBUG) { - // Either we didn't generate build info for the package under test (because it wasn't package main), or - // the DefaultGODEBUG used to build the test main package is different from the DefaultGODEBUG - // used to build the package under test. If we didn't set build info for the package under test - // pmain won't have buildinfo set (since we copy it from the package under test). If the default GODEBUG - // used for the package under test is different from that of the test main, the BuildInfo assigned above from the package - // under test incorrect for the test main package. Either set or correct pmain's build info. - pmain.setBuildInfo(ctx, loaderstate.Fetcher(), opts.AutoVCS) - } // The generated main also imports testing, regexp, and os. // Also the linker introduces implicit dependencies reported by LinkerDeps. @@ -379,6 +370,15 @@ func TestPackagesAndErrors(loaderstate *modload.State, ctx context.Context, done ptest.Incomplete = true } + if !opts.SuppressBuildInfo { + // Now that pmain.Internal.Imports includes the test dependencies, + // regenerate build info for the test binary. We can't reuse p's + // build info because the test variants of packages can add + // packages from modules that don't already have transitive + // imports from p. + pmain.setBuildInfo(ctx, loaderstate.Fetcher(), opts.AutoVCS) + } + if cover != nil { // Here ptest needs to inherit the proper coverage mode (since // it contains p's Go files), whereas pmain contains only diff --git a/src/cmd/go/testdata/script/test_buildinfo.txt b/src/cmd/go/testdata/script/test_buildinfo.txt index fbf097c0a6..2edc02dc13 100644 --- a/src/cmd/go/testdata/script/test_buildinfo.txt +++ b/src/cmd/go/testdata/script/test_buildinfo.txt @@ -4,15 +4,20 @@ [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_test +package foo import ( "runtime/debug" "testing" + + _ "example.com/version" ) func TestBuildInfo(t *testing.T) { @@ -21,4 +26,8 @@ func TestBuildInfo(t *testing.T) { t.Fatal("no debug info") } t.Log(info.Main.Version) -}
\ No newline at end of file + + for _, d := range info.Deps { + t.Log(d.Path, d.Version) + } +} |
