all: set GO111MODULE=off for tests that use GOPATHs in testdata.
Some users may set GO111MODULE=on, and we will eventually want to be able to build x/tools itself in module mode. Updates golang/go#27858 Updates golang/go#27852 Change-Id: Iaf488b2a89e6526471530245cb580f1f0391a770 Reviewed-on: https://go-review.googlesource.com/137815 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org>
This commit is contained in:
parent
9599141856
commit
9fb5a2f241
|
@ -12,11 +12,25 @@ package main
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
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 TestCallgraph(t *testing.T) {
|
func TestCallgraph(t *testing.T) {
|
||||||
gopath, err := filepath.Abs("testdata")
|
gopath, err := filepath.Abs("testdata")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -491,15 +491,18 @@ func list(args ...string) ([]*listPackage, error) {
|
||||||
return pkgs, nil
|
return pkgs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var cwd string
|
// cwd contains the current working directory of the tool.
|
||||||
|
//
|
||||||
func init() {
|
// It is initialized directly so that its value will be set for any other
|
||||||
var err error
|
// package variables or init functions that depend on it, such as the gopath
|
||||||
cwd, err = os.Getwd()
|
// variable in main_test.go.
|
||||||
|
var cwd string = func() string {
|
||||||
|
cwd, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("os.Getwd: %v", err)
|
log.Fatalf("os.Getwd: %v", err)
|
||||||
}
|
}
|
||||||
}
|
return cwd
|
||||||
|
}()
|
||||||
|
|
||||||
// shortPath returns an absolute or relative name for path, whatever is shorter.
|
// shortPath returns an absolute or relative name for path, whatever is shorter.
|
||||||
// Plundered from $GOROOT/src/cmd/go/build.go.
|
// Plundered from $GOROOT/src/cmd/go/build.go.
|
||||||
|
|
|
@ -10,6 +10,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
@ -32,11 +33,25 @@ import (
|
||||||
// titanic.biz/bar -- domain is sinking; package has jumped ship to new.com/bar
|
// titanic.biz/bar -- domain is sinking; package has jumped ship to new.com/bar
|
||||||
// titanic.biz/foo -- domain is sinking but package has no import comment yet
|
// titanic.biz/foo -- domain is sinking but package has no import comment yet
|
||||||
|
|
||||||
func TestFixImports(t *testing.T) {
|
var gopath = filepath.Join(cwd, "testdata")
|
||||||
gopath := filepath.Join(cwd, "testdata")
|
|
||||||
|
func init() {
|
||||||
if err := os.Setenv("GOPATH", gopath); err != nil {
|
if err := os.Setenv("GOPATH", gopath); err != nil {
|
||||||
t.Fatalf("os.Setenv: %v", err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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 TestFixImports(t *testing.T) {
|
||||||
defer func() {
|
defer func() {
|
||||||
stderr = os.Stderr
|
stderr = os.Stderr
|
||||||
*badDomains = "code.google.com"
|
*badDomains = "code.google.com"
|
||||||
|
@ -224,11 +239,6 @@ import (
|
||||||
|
|
||||||
// TestDryRun tests that the -n flag suppresses calls to writeFile.
|
// TestDryRun tests that the -n flag suppresses calls to writeFile.
|
||||||
func TestDryRun(t *testing.T) {
|
func TestDryRun(t *testing.T) {
|
||||||
gopath := filepath.Join(cwd, "testdata")
|
|
||||||
if err := os.Setenv("GOPATH", gopath); err != nil {
|
|
||||||
t.Fatalf("os.Setenv: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
*dryrun = true
|
*dryrun = true
|
||||||
defer func() { *dryrun = false }() // restore
|
defer func() { *dryrun = false }() // restore
|
||||||
stderr = new(bytes.Buffer)
|
stderr = new(bytes.Buffer)
|
||||||
|
|
|
@ -233,10 +233,14 @@ func testWeb(t *testing.T, withIndex bool) {
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
cmd.Args[0] = "godoc"
|
cmd.Args[0] = "godoc"
|
||||||
|
|
||||||
// Set GOPATH variable to non-existing path.
|
// Set GOPATH variable to non-existing path
|
||||||
|
// and GOPROXY=off to disable module fetches.
|
||||||
// We cannot just unset GOPATH variable because godoc would default it to ~/go.
|
// We cannot just unset GOPATH variable because godoc would default it to ~/go.
|
||||||
// (We don't want the indexer looking at the local workspace during tests.)
|
// (We don't want the indexer looking at the local workspace during tests.)
|
||||||
cmd.Env = append(os.Environ(), "GOPATH=does_not_exist")
|
cmd.Env = append(os.Environ(),
|
||||||
|
"GOPATH=does_not_exist",
|
||||||
|
"GOPROXY=off",
|
||||||
|
"GO111MODULE=off")
|
||||||
|
|
||||||
if err := cmd.Start(); err != nil {
|
if err := cmd.Start(); err != nil {
|
||||||
t.Fatalf("failed to start godoc: %s", err)
|
t.Fatalf("failed to start godoc: %s", err)
|
||||||
|
@ -448,6 +452,8 @@ func main() { print(lib.V) }
|
||||||
cmd.Env = os.Environ()
|
cmd.Env = os.Environ()
|
||||||
cmd.Env = append(cmd.Env, fmt.Sprintf("GOROOT=%s", filepath.Join(tmpdir, "goroot")))
|
cmd.Env = append(cmd.Env, fmt.Sprintf("GOROOT=%s", filepath.Join(tmpdir, "goroot")))
|
||||||
cmd.Env = append(cmd.Env, fmt.Sprintf("GOPATH=%s", filepath.Join(tmpdir, "gopath")))
|
cmd.Env = append(cmd.Env, fmt.Sprintf("GOPATH=%s", filepath.Join(tmpdir, "gopath")))
|
||||||
|
cmd.Env = append(cmd.Env, "GO111MODULE=off")
|
||||||
|
cmd.Env = append(cmd.Env, "GOPROXY=off")
|
||||||
cmd.Stdout = os.Stderr
|
cmd.Stdout = os.Stderr
|
||||||
stderr, err := cmd.StderrPipe()
|
stderr, err := cmd.StderrPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -35,6 +35,7 @@ import (
|
||||||
"go/token"
|
"go/token"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -49,6 +50,18 @@ import (
|
||||||
guru "golang.org/x/tools/cmd/guru"
|
guru "golang.org/x/tools/cmd/guru"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var updateFlag = flag.Bool("update", false, "Update the golden files.")
|
var updateFlag = flag.Bool("update", false, "Update the golden files.")
|
||||||
|
|
||||||
type query struct {
|
type query struct {
|
||||||
|
|
|
@ -1,12 +1,26 @@
|
||||||
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.
|
||||||
//
|
//
|
||||||
|
|
|
@ -1,12 +1,26 @@
|
||||||
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,
|
||||||
|
|
Loading…
Reference in New Issue