1
0
mirror of https://github.com/golang/go synced 2024-11-26 08:27:56 -07:00

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 <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
Manlio Perillo 2021-04-14 12:45:42 +02:00 committed by Ian Lance Taylor
parent f18715c18f
commit d27bb8ba2e

View 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