Skip to content

Commit 211dcd1

Browse files
committed
go/analysis/analysistest: unset GO111MODULE and GOPROXY
CL 139320 unset these env vars for the whole process in two tests, but the correct fix is to unset them for subprocesses forked by go/packages. Change-Id: I35e3ab9e424b00326e9e813e4daf0ae92ec36e26 Reviewed-on: https://go-review.googlesource.com/c/139477 Reviewed-by: Bryan C. Mills <[email protected]> Run-TryBot: Bryan C. Mills <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 1f2a8f4 commit 211dcd1

File tree

3 files changed

+1
-29
lines changed

3 files changed

+1
-29
lines changed

go/analysis/analysistest/analysistest.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func loadPackage(dir, pkgpath string) (*packages.Package, error) {
128128
Mode: packages.LoadAllSyntax,
129129
Dir: dir,
130130
Tests: true,
131-
Env: append(os.Environ(), "GOPATH="+dir),
131+
Env: append(os.Environ(), "GOPATH="+dir, "GO111MODULE=off", "GOPROXY=off"),
132132
}
133133
pkgs, err := packages.Load(cfg, pkgpath)
134134
if err != nil {

go/analysis/passes/findcall/findcall_test.go

-14
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
11
package findcall_test
22

33
import (
4-
"log"
5-
"os"
64
"testing"
75

86
"golang.org/x/tools/go/analysis/analysistest"
97
"golang.org/x/tools/go/analysis/passes/findcall"
108
)
119

12-
func init() {
13-
// This test currently requires GOPATH mode.
14-
// Explicitly disabling module mode should suffix, but
15-
// we'll also turn off GOPROXY just for good measure.
16-
if err := os.Setenv("GO111MODULE", "off"); err != nil {
17-
log.Fatal(err)
18-
}
19-
if err := os.Setenv("GOPROXY", "off"); err != nil {
20-
log.Fatal(err)
21-
}
22-
}
23-
2410
// TestFromStringLiterals demonstrates how to test an analysis using
2511
// a table of string literals for each test case.
2612
//

go/analysis/passes/pkgfact/pkgfact_test.go

-14
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
11
package pkgfact_test
22

33
import (
4-
"log"
5-
"os"
64
"testing"
75

86
"golang.org/x/tools/go/analysis/analysistest"
97
"golang.org/x/tools/go/analysis/passes/pkgfact"
108
)
119

12-
func init() {
13-
// This test currently requires GOPATH mode.
14-
// Explicitly disabling module mode should suffix, but
15-
// we'll also turn off GOPROXY just for good measure.
16-
if err := os.Setenv("GO111MODULE", "off"); err != nil {
17-
log.Fatal(err)
18-
}
19-
if err := os.Setenv("GOPROXY", "off"); err != nil {
20-
log.Fatal(err)
21-
}
22-
}
23-
2410
func Test(t *testing.T) {
2511
testdata := analysistest.TestData()
2612
analysistest.Run(t, testdata, pkgfact.Analyzer,

0 commit comments

Comments
 (0)