all: skip tests if required tools are not found
Fixes golang/go#33950
Change-Id: Iefcb757e773bc052793611c099c25a457fd7e243
Reviewed-on: https://go-review.googlesource.com/c/tools/+/192400
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
diff --git a/cmd/callgraph/main_test.go b/cmd/callgraph/main_test.go
index 54953c7..6aeae6f 100644
--- a/cmd/callgraph/main_test.go
+++ b/cmd/callgraph/main_test.go
@@ -17,6 +17,8 @@
"path/filepath"
"strings"
"testing"
+
+ "golang.org/x/tools/internal/testenv"
)
func init() {
@@ -32,6 +34,8 @@
}
func TestCallgraph(t *testing.T) {
+ testenv.NeedsTool(t, "go")
+
gopath, err := filepath.Abs("testdata")
if err != nil {
t.Fatal(err)
diff --git a/cmd/cover/cover_test.go b/cmd/cover/cover_test.go
index a18778b..10a85fb 100644
--- a/cmd/cover/cover_test.go
+++ b/cmd/cover/cover_test.go
@@ -16,6 +16,8 @@
"os/exec"
"path/filepath"
"testing"
+
+ "golang.org/x/tools/internal/testenv"
)
const (
@@ -44,6 +46,8 @@
// go run ./testdata/main.go ./testdata/test.go
//
func TestCover(t *testing.T) {
+ testenv.NeedsTool(t, "go")
+
// Read in the test file (testTest) and write it, with LINEs specified, to coverInput.
file, err := ioutil.ReadFile(testTest)
if err != nil {
diff --git a/cmd/fiximports/main_test.go b/cmd/fiximports/main_test.go
index a2973a3..3ec5511 100644
--- a/cmd/fiximports/main_test.go
+++ b/cmd/fiximports/main_test.go
@@ -16,6 +16,8 @@
"runtime"
"strings"
"testing"
+
+ "golang.org/x/tools/internal/testenv"
)
// TODO(adonovan):
@@ -52,6 +54,8 @@
}
func TestFixImports(t *testing.T) {
+ testenv.NeedsTool(t, "go")
+
defer func() {
stderr = os.Stderr
*badDomains = "code.google.com"
@@ -239,6 +243,8 @@
// TestDryRun tests that the -n flag suppresses calls to writeFile.
func TestDryRun(t *testing.T) {
+ testenv.NeedsTool(t, "go")
+
*dryrun = true
defer func() { *dryrun = false }() // restore
stderr = new(bytes.Buffer)
diff --git a/cmd/godoc/godoc_test.go b/cmd/godoc/godoc_test.go
index c8efaab..b92b8e0 100644
--- a/cmd/godoc/godoc_test.go
+++ b/cmd/godoc/godoc_test.go
@@ -21,6 +21,8 @@
"strings"
"testing"
"time"
+
+ "golang.org/x/tools/internal/testenv"
)
// buildGodoc builds the godoc executable.
@@ -29,12 +31,15 @@
// TODO(adonovan): opt: do this at most once, and do the cleanup
// exactly once. How though? There's no atexit.
func buildGodoc(t *testing.T) (bin string, cleanup func()) {
+ t.Helper()
+
if runtime.GOARCH == "arm" {
t.Skip("skipping test on arm platforms; too slow")
}
if runtime.GOOS == "android" {
t.Skipf("the dependencies are not available on android")
}
+ testenv.NeedsTool(t, "go")
tmp, err := ioutil.TempDir("", "godoc-regtest-")
if err != nil {
diff --git a/cmd/gorename/gorename_test.go b/cmd/gorename/gorename_test.go
index ff9a195..3351977 100644
--- a/cmd/gorename/gorename_test.go
+++ b/cmd/gorename/gorename_test.go
@@ -14,6 +14,8 @@
"strconv"
"strings"
"testing"
+
+ "golang.org/x/tools/internal/testenv"
)
var haveCGO bool
@@ -32,6 +34,7 @@
if !haveCGO {
t.Skipf("skipping test: no cgo")
}
+ testenv.NeedsTool(t, "go")
tmp, bin, cleanup := buildGorename(t)
defer cleanup()
diff --git a/cmd/guru/guru_test.go b/cmd/guru/guru_test.go
index af3ddff..b322e9a 100644
--- a/cmd/guru/guru_test.go
+++ b/cmd/guru/guru_test.go
@@ -48,6 +48,7 @@
"testing"
guru "golang.org/x/tools/cmd/guru"
+ "golang.org/x/tools/internal/testenv"
)
func init() {
@@ -296,6 +297,7 @@
default:
cmd = exec.Command("/usr/bin/diff", "-u", golden, got)
}
+ testenv.NeedsTool(t, cmd.Path)
buf := new(bytes.Buffer)
cmd.Stdout = buf
cmd.Stderr = os.Stderr
diff --git a/cmd/stringer/endtoend_test.go b/cmd/stringer/endtoend_test.go
index 5762a7f..af106b5 100644
--- a/cmd/stringer/endtoend_test.go
+++ b/cmd/stringer/endtoend_test.go
@@ -19,6 +19,8 @@
"path/filepath"
"strings"
"testing"
+
+ "golang.org/x/tools/internal/testenv"
)
// This file contains a test that compiles and runs each program in testdata
@@ -151,6 +153,8 @@
// buildStringer creates a temporary directory and installs stringer there.
func buildStringer(t *testing.T) (dir string, stringer string) {
t.Helper()
+ testenv.NeedsTool(t, "go")
+
dir, err := ioutil.TempDir("", "stringer")
if err != nil {
t.Fatal(err)
diff --git a/cmd/stringer/golden_test.go b/cmd/stringer/golden_test.go
index 03e7da2..cef64b0 100644
--- a/cmd/stringer/golden_test.go
+++ b/cmd/stringer/golden_test.go
@@ -15,6 +15,8 @@
"path/filepath"
"strings"
"testing"
+
+ "golang.org/x/tools/internal/testenv"
)
// Golden represents a test case.
@@ -398,6 +400,8 @@
`
func TestGolden(t *testing.T) {
+ testenv.NeedsTool(t, "go")
+
dir, err := ioutil.TempDir("", "stringer")
if err != nil {
t.Error(err)