Skip to content

Commit d37d3bd

Browse files
committed
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 <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]> Run-TryBot: David Crawshaw <[email protected]>
1 parent 596949c commit d37d3bd

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

src/go/build/deps_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ var pkgDeps = map[string][]string{
168168
"testing": {"L2", "flag", "fmt", "os", "runtime/debug", "runtime/pprof", "runtime/trace", "time"},
169169
"testing/iotest": {"L2", "log"},
170170
"testing/quick": {"L2", "flag", "fmt", "reflect"},
171-
"internal/testenv": {"L2", "os", "testing"},
171+
"internal/testenv": {"L2", "OS", "testing"},
172172

173173
// L4 is defined as L3+fmt+log+time, because in general once
174174
// you're using L3 packages, use of fmt, log, or time is not a big deal.

src/internal/testenv/testenv.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ package testenv
1212

1313
import (
1414
"os"
15+
"os/exec"
1516
"runtime"
1617
"strings"
1718
"testing"
@@ -62,6 +63,22 @@ func MustHaveGoRun(t *testing.T) {
6263
}
6364
}
6465

66+
// GoToolPath reports the path to the Go tool.
67+
// If the tool is unavailable GoToolPath calls t.Skip.
68+
// If the tool should be available and isn't, GoToolPath calls t.Fatal.
69+
func GoToolPath(t *testing.T) string {
70+
MustHaveGoBuild(t)
71+
var exeSuffix string
72+
if runtime.GOOS == "windows" {
73+
exeSuffix = ".exe"
74+
}
75+
goBin, err := exec.LookPath("go" + exeSuffix)
76+
if err != nil {
77+
t.Fatal("cannot find go tool: %v", err)
78+
}
79+
return goBin
80+
}
81+
6582
// HasExec reports whether the current system can start new processes
6683
// using os.StartProcess or (more commonly) exec.Command.
6784
func HasExec() bool {

src/net/http/http_test.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ import (
1010
"bytes"
1111
"internal/testenv"
1212
"os/exec"
13-
"path/filepath"
1413
"reflect"
15-
"runtime"
1614
"testing"
1715
)
1816

@@ -67,16 +65,10 @@ func TestCleanHost(t *testing.T) {
6765
// This catches accidental dependencies between the HTTP transport and
6866
// server code.
6967
func TestCmdGoNoHTTPServer(t *testing.T) {
70-
testenv.MustHaveGoBuild(t)
71-
var exeSuffix string
72-
if runtime.GOOS == "windows" {
73-
exeSuffix = ".exe"
74-
}
75-
76-
goBin := filepath.Join(runtime.GOROOT(), "bin", "go"+exeSuffix)
77-
out, err := exec.Command("go", "tool", "nm", goBin).Output()
68+
goBin := testenv.GoToolPath(t)
69+
out, err := exec.Command("go", "tool", "nm", goBin).CombinedOutput()
7870
if err != nil {
79-
t.Fatalf("go tool nm: %v", err)
71+
t.Fatalf("go tool nm: %v: %s", err, out)
8072
}
8173
wantSym := map[string]bool{
8274
// Verify these exist: (sanity checking this test)

0 commit comments

Comments
 (0)