aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/internal/testenv/testenv.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/internal/testenv/testenv.go')
-rw-r--r--libgo/go/internal/testenv/testenv.go43
1 files changed, 42 insertions, 1 deletions
diff --git a/libgo/go/internal/testenv/testenv.go b/libgo/go/internal/testenv/testenv.go
index 1071908..e76e339 100644
--- a/libgo/go/internal/testenv/testenv.go
+++ b/libgo/go/internal/testenv/testenv.go
@@ -1,4 +1,4 @@
-// Copyright 2015 The Go Authors. All rights reserved.
+// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
@@ -11,8 +11,12 @@
package testenv
import (
+ "flag"
"os"
+ "os/exec"
+ "path/filepath"
"runtime"
+ "strconv"
"strings"
"testing"
)
@@ -65,6 +69,29 @@ func MustHaveGoRun(t *testing.T) {
}
}
+// GoToolPath reports the path to the Go tool.
+// If the tool is unavailable GoToolPath calls t.Skip.
+// If the tool should be available and isn't, GoToolPath calls t.Fatal.
+func GoToolPath(t *testing.T) string {
+ MustHaveGoBuild(t)
+
+ var exeSuffix string
+ if runtime.GOOS == "windows" {
+ exeSuffix = ".exe"
+ }
+
+ path := filepath.Join(runtime.GOROOT(), "bin", "go"+exeSuffix)
+ if _, err := os.Stat(path); err == nil {
+ return path
+ }
+
+ goBin, err := exec.LookPath("go" + exeSuffix)
+ if err != nil {
+ t.Fatalf("cannot find go tool: %v", err)
+ }
+ return goBin
+}
+
// HasExec reports whether the current system can start new processes
// using os.StartProcess or (more commonly) exec.Command.
func HasExec() bool {
@@ -102,3 +129,17 @@ func MustHaveExternalNetwork(t *testing.T) {
t.Skipf("skipping test: no external network in -short mode")
}
}
+
+var flaky = flag.Bool("flaky", false, "run known-flaky tests too")
+
+func SkipFlaky(t *testing.T, issue int) {
+ if !*flaky {
+ t.Skipf("skipping known flaky test without the -flaky flag; see golang.org/issue/%d", issue)
+ }
+}
+
+func SkipFlakyNet(t *testing.T) {
+ if v, _ := strconv.ParseBool(os.Getenv("GO_BUILDER_FLAKY_NET")); v {
+ t.Skip("skipping test on builder known to have frequent network failures")
+ }
+}