aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josharian@gmail.com>2016-09-08 18:50:59 -0700
committerJosh Bleecher Snyder <josharian@gmail.com>2016-09-10 20:50:12 +0000
commitc564aebce99fb92b8dc26b203f4f32e4977c0aed (patch)
tree1f6d5c1661819989e7b69a70569e5a1899f284b2
parent3d562de8e38317a06fbf860e60f71c5e4f0ceab6 (diff)
downloadgo-c564aebce99fb92b8dc26b203f4f32e4977c0aed.tar.xz
internal/testenv: add GoTool
GoToolPath requires a *testing.T to handle errors. GoTool provides a variant that returns errors for clients without a *testing.T, such as that found in CL 27811. Change-Id: I7ac8b7ec9d472894c37223c5f7b121ec823e7f61 Reviewed-on: https://go-review.googlesource.com/28787 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Rob Pike <r@golang.org> Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
-rw-r--r--src/internal/testenv/testenv.go21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/internal/testenv/testenv.go b/src/internal/testenv/testenv.go
index f99ec26557..a8aa2c7464 100644
--- a/src/internal/testenv/testenv.go
+++ b/src/internal/testenv/testenv.go
@@ -11,6 +11,7 @@
package testenv
import (
+ "errors"
"flag"
"os"
"os/exec"
@@ -67,26 +68,36 @@ func MustHaveGoRun(t *testing.T) {
}
// GoToolPath reports the path to the Go tool.
+// It is a convenience wrapper around GoTool.
// 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)
+ path, err := GoTool()
+ if err != nil {
+ t.Fatal(err)
+ }
+ return path
+}
+// GoTool reports the path to the Go tool.
+func GoTool() (string, error) {
+ if !HasGoBuild() {
+ return "", errors.New("platform cannot run go tool")
+ }
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
+ return path, nil
}
-
goBin, err := exec.LookPath("go" + exeSuffix)
if err != nil {
- t.Fatalf("cannot find go tool: %v", err)
+ return "", errors.New("cannot find go tool: " + err.Error())
}
- return goBin
+ return goBin, nil
}
// HasExec reports whether the current system can start new processes