Commit c564aebc authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

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/28787Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: default avatarRob Pike <r@golang.org>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 3d562de8
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment