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 <bcmills@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Trust: David Chase <drchase@google.com>
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
David Chase 2022-03-30 12:01:21 -04:00
parent 1ac1658642
commit 3b7fce24cd
2 changed files with 5 additions and 3 deletions

View File

@ -1,3 +1,4 @@
env GOWORK=off
env GO111MODULE=on
# golang.org/issue/32917 and golang.org/issue/28459: 'go build' and 'go test'

View File

@ -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()