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 <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Alan Donovan 2018-10-03 17:43:12 -04:00
parent 1f2a8f46bd
commit 211dcd1cef
3 changed files with 1 additions and 29 deletions

View File

@ -128,7 +128,7 @@ func loadPackage(dir, pkgpath string) (*packages.Package, error) {
Mode: packages.LoadAllSyntax, Mode: packages.LoadAllSyntax,
Dir: dir, Dir: dir,
Tests: true, Tests: true,
Env: append(os.Environ(), "GOPATH="+dir), Env: append(os.Environ(), "GOPATH="+dir, "GO111MODULE=off", "GOPROXY=off"),
} }
pkgs, err := packages.Load(cfg, pkgpath) pkgs, err := packages.Load(cfg, pkgpath)
if err != nil { if err != nil {

View File

@ -1,26 +1,12 @@
package findcall_test package findcall_test
import ( import (
"log"
"os"
"testing" "testing"
"golang.org/x/tools/go/analysis/analysistest" "golang.org/x/tools/go/analysis/analysistest"
"golang.org/x/tools/go/analysis/passes/findcall" "golang.org/x/tools/go/analysis/passes/findcall"
) )
func init() {
// This test currently requires GOPATH mode.
// Explicitly disabling module mode should suffix, but
// we'll also turn off GOPROXY just for good measure.
if err := os.Setenv("GO111MODULE", "off"); err != nil {
log.Fatal(err)
}
if err := os.Setenv("GOPROXY", "off"); err != nil {
log.Fatal(err)
}
}
// TestFromStringLiterals demonstrates how to test an analysis using // TestFromStringLiterals demonstrates how to test an analysis using
// a table of string literals for each test case. // a table of string literals for each test case.
// //

View File

@ -1,26 +1,12 @@
package pkgfact_test package pkgfact_test
import ( import (
"log"
"os"
"testing" "testing"
"golang.org/x/tools/go/analysis/analysistest" "golang.org/x/tools/go/analysis/analysistest"
"golang.org/x/tools/go/analysis/passes/pkgfact" "golang.org/x/tools/go/analysis/passes/pkgfact"
) )
func init() {
// This test currently requires GOPATH mode.
// Explicitly disabling module mode should suffix, but
// we'll also turn off GOPROXY just for good measure.
if err := os.Setenv("GO111MODULE", "off"); err != nil {
log.Fatal(err)
}
if err := os.Setenv("GOPROXY", "off"); err != nil {
log.Fatal(err)
}
}
func Test(t *testing.T) { func Test(t *testing.T) {
testdata := analysistest.TestData() testdata := analysistest.TestData()
analysistest.Run(t, testdata, pkgfact.Analyzer, analysistest.Run(t, testdata, pkgfact.Analyzer,