]> Cypherpunks repositories - gostls13.git/commitdiff
go/build: replace os.Setenv with T.Setenv
authorManlio Perillo <manlio.perillo@gmail.com>
Wed, 14 Apr 2021 10:45:42 +0000 (12:45 +0200)
committerIan Lance Taylor <iant@golang.org>
Wed, 14 Apr 2021 23:26:15 +0000 (23:26 +0000)
Updates #45448

Change-Id: I4d8e5d7e57818355ef2bc33b57ddf9c8b8da3e62
Reviewed-on: https://go-review.googlesource.com/c/go/+/310030
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Michael Knyszek <mknyszek@google.com>

src/go/build/build_test.go

index dcd845825250bac289e06064707a4843f43cfa4a..7e785680831868422b9c78b38afec1a634bf0686 100644 (file)
@@ -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