From 3b7fce24cda8b9b245bae94aee9fafea87926c50 Mon Sep 17 00:00:00 2001 From: David Chase Date: Wed, 30 Mar 2022 12:01:21 -0400 Subject: [PATCH] cmd: make go and moddeps tests insensitive to presence of src/go.work If there is a go.work file in src, "go test cmd/internal/moddeps" and "go test cmd/go" fail. Setting GOWORK=off in various command invocations avoids this problem. Change-Id: I89fd021ff94998ceda6a3bbc4c3743f08558f98b Reviewed-on: https://go-review.googlesource.com/c/go/+/396777 Trust: Bryan Mills Reviewed-by: Bryan Mills Trust: David Chase Run-TryBot: David Chase TryBot-Result: Gopher Robot --- src/cmd/go/testdata/script/mod_dot.txt | 1 + src/cmd/internal/moddeps/moddeps_test.go | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cmd/go/testdata/script/mod_dot.txt b/src/cmd/go/testdata/script/mod_dot.txt index cb60e988b6..aa24986c72 100644 --- a/src/cmd/go/testdata/script/mod_dot.txt +++ b/src/cmd/go/testdata/script/mod_dot.txt @@ -1,3 +1,4 @@ +env GOWORK=off env GO111MODULE=on # golang.org/issue/32917 and golang.org/issue/28459: 'go build' and 'go test' diff --git a/src/cmd/internal/moddeps/moddeps_test.go b/src/cmd/internal/moddeps/moddeps_test.go index a63ac71a16..053cb8f548 100644 --- a/src/cmd/internal/moddeps/moddeps_test.go +++ b/src/cmd/internal/moddeps/moddeps_test.go @@ -55,7 +55,7 @@ func TestAllDependencies(t *testing.T) { // dependencies are vendored. If any imported package is missing, // 'go list -deps' will fail when attempting to load it. cmd := exec.Command(goBin, "list", "-mod=vendor", "-deps", "./...") - cmd.Env = append(os.Environ(), "GO111MODULE=on") + cmd.Env = append(os.Environ(), "GO111MODULE=on", "GOWORK=off") cmd.Dir = m.Dir cmd.Stderr = new(strings.Builder) _, err := cmd.Output() @@ -69,7 +69,7 @@ func TestAllDependencies(t *testing.T) { // There is no vendor directory, so the module must have no dependencies. // Check that the list of active modules contains only the main module. cmd := exec.Command(goBin, "list", "-mod=readonly", "-m", "all") - cmd.Env = append(os.Environ(), "GO111MODULE=on") + cmd.Env = append(os.Environ(), "GO111MODULE=on", "GOWORK=off") cmd.Dir = m.Dir cmd.Stderr = new(strings.Builder) out, err := cmd.Output() @@ -197,6 +197,7 @@ func TestAllDependencies(t *testing.T) { // Add GOROOTcopy/bin and bundleDir to front of PATH. "PATH="+filepath.Join(gorootCopyDir, "bin")+string(filepath.ListSeparator)+ bundleDir+string(filepath.ListSeparator)+os.Getenv("PATH"), + "GOWORK=off", ), } goBinCopy := filepath.Join(gorootCopyDir, "bin", "go") @@ -463,7 +464,7 @@ func findGorootModules(t *testing.T) []gorootModule { // Use 'go list' to describe the module contained in this directory (but // not its dependencies). cmd := exec.Command(goBin, "list", "-json", "-m") - cmd.Env = append(os.Environ(), "GO111MODULE=on") + cmd.Env = append(os.Environ(), "GO111MODULE=on", "GOWORK=off") cmd.Dir = dir cmd.Stderr = new(strings.Builder) out, err := cmd.Output() -- 2.48.1