From d27bb8ba2ecf18b2d69d4eb72080a17ebff09f64 Mon Sep 17 00:00:00 2001 From: Manlio Perillo Date: Wed, 14 Apr 2021 12:45:42 +0200 Subject: [PATCH] go/build: replace os.Setenv with T.Setenv Updates #45448 Change-Id: I4d8e5d7e57818355ef2bc33b57ddf9c8b8da3e62 Reviewed-on: https://go-review.googlesource.com/c/go/+/310030 Run-TryBot: Ian Lance Taylor TryBot-Result: Go Bot Reviewed-by: Ian Lance Taylor Trust: Michael Knyszek --- src/go/build/build_test.go | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/src/go/build/build_test.go b/src/go/build/build_test.go index dcd8458252..7e78568083 100644 --- a/src/go/build/build_test.go +++ b/src/go/build/build_test.go @@ -539,8 +539,7 @@ func TestImportDirNotExist(t *testing.T) { func TestImportVendor(t *testing.T) { testenv.MustHaveGoBuild(t) // really must just have source - defer os.Setenv("GO111MODULE", os.Getenv("GO111MODULE")) - os.Setenv("GO111MODULE", "off") + t.Setenv("GO111MODULE", "off") ctxt := Default wd, err := os.Getwd() @@ -561,8 +560,7 @@ func TestImportVendor(t *testing.T) { func TestImportVendorFailure(t *testing.T) { testenv.MustHaveGoBuild(t) // really must just have source - defer os.Setenv("GO111MODULE", os.Getenv("GO111MODULE")) - os.Setenv("GO111MODULE", "off") + t.Setenv("GO111MODULE", "off") ctxt := Default wd, err := os.Getwd() @@ -584,8 +582,7 @@ func TestImportVendorFailure(t *testing.T) { func TestImportVendorParentFailure(t *testing.T) { testenv.MustHaveGoBuild(t) // really must just have source - defer os.Setenv("GO111MODULE", os.Getenv("GO111MODULE")) - os.Setenv("GO111MODULE", "off") + t.Setenv("GO111MODULE", "off") ctxt := Default wd, err := os.Getwd() @@ -615,8 +612,7 @@ func TestImportPackageOutsideModule(t *testing.T) { // Disable module fetching for this test so that 'go list' fails quickly // without trying to find the latest version of a module. - defer os.Setenv("GOPROXY", os.Getenv("GOPROXY")) - os.Setenv("GOPROXY", "off") + t.Setenv("GOPROXY", "off") // Create a GOPATH in a temporary directory. We don't use testdata // because it's in GOROOT, which interferes with the module heuristic. @@ -628,10 +624,8 @@ func TestImportPackageOutsideModule(t *testing.T) { t.Fatal(err) } - defer os.Setenv("GO111MODULE", os.Getenv("GO111MODULE")) - os.Setenv("GO111MODULE", "on") - defer os.Setenv("GOPATH", os.Getenv("GOPATH")) - os.Setenv("GOPATH", gopath) + t.Setenv("GO111MODULE", "on") + t.Setenv("GOPATH", gopath) ctxt := Default ctxt.GOPATH = gopath ctxt.Dir = filepath.Join(gopath, "src/example.com/p") @@ -684,12 +678,9 @@ func TestMissingImportErrorRepetition(t *testing.T) { if err := os.WriteFile(filepath.Join(tmp, "go.mod"), []byte("module m"), 0666); err != nil { t.Fatal(err) } - defer os.Setenv("GO111MODULE", os.Getenv("GO111MODULE")) - os.Setenv("GO111MODULE", "on") - defer os.Setenv("GOPROXY", os.Getenv("GOPROXY")) - os.Setenv("GOPROXY", "off") - defer os.Setenv("GONOPROXY", os.Getenv("GONOPROXY")) - os.Setenv("GONOPROXY", "none") + t.Setenv("GO111MODULE", "on") + t.Setenv("GOPROXY", "off") + t.Setenv("GONOPROXY", "none") ctxt := Default ctxt.Dir = tmp -- 2.50.0