diff options
| author | David Crawshaw <crawshaw@golang.org> | 2016-03-21 14:41:16 -0400 |
|---|---|---|
| committer | David Crawshaw <crawshaw@golang.org> | 2016-03-22 02:02:23 +0000 |
| commit | d37d3bdcfc429168adac5bf046172fd9c07bfdc2 (patch) | |
| tree | 6e9b5dc2d5273e73f4c536be1e98a5e4372308ce /src/internal/testenv | |
| parent | 596949c18a29c51fcfa3ec2596cae72241e256e1 (diff) | |
| download | go-d37d3bdcfc429168adac5bf046172fd9c07bfdc2.tar.xz | |
net/http, internal/testenv: find go binary in PATH
Fixes #14901
Change-Id: Ia32e09767374a341c9a36c5d977d47d7d1a82315
Reviewed-on: https://go-review.googlesource.com/20967
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: David Crawshaw <crawshaw@golang.org>
Diffstat (limited to 'src/internal/testenv')
| -rw-r--r-- | src/internal/testenv/testenv.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/internal/testenv/testenv.go b/src/internal/testenv/testenv.go index 99b2a2ea15..6c007f185c 100644 --- a/src/internal/testenv/testenv.go +++ b/src/internal/testenv/testenv.go @@ -12,6 +12,7 @@ package testenv import ( "os" + "os/exec" "runtime" "strings" "testing" @@ -62,6 +63,22 @@ 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" + } + goBin, err := exec.LookPath("go" + exeSuffix) + if err != nil { + t.Fatal("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 { |
