mirror of
https://github.com/golang/go
synced 2024-11-24 20:20:03 -07:00
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>
This commit is contained in:
parent
596949c18a
commit
d37d3bdcfc
@ -168,7 +168,7 @@ var pkgDeps = map[string][]string{
|
|||||||
"testing": {"L2", "flag", "fmt", "os", "runtime/debug", "runtime/pprof", "runtime/trace", "time"},
|
"testing": {"L2", "flag", "fmt", "os", "runtime/debug", "runtime/pprof", "runtime/trace", "time"},
|
||||||
"testing/iotest": {"L2", "log"},
|
"testing/iotest": {"L2", "log"},
|
||||||
"testing/quick": {"L2", "flag", "fmt", "reflect"},
|
"testing/quick": {"L2", "flag", "fmt", "reflect"},
|
||||||
"internal/testenv": {"L2", "os", "testing"},
|
"internal/testenv": {"L2", "OS", "testing"},
|
||||||
|
|
||||||
// L4 is defined as L3+fmt+log+time, because in general once
|
// L4 is defined as L3+fmt+log+time, because in general once
|
||||||
// you're using L3 packages, use of fmt, log, or time is not a big deal.
|
// you're using L3 packages, use of fmt, log, or time is not a big deal.
|
||||||
|
@ -12,6 +12,7 @@ package testenv
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"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
|
// HasExec reports whether the current system can start new processes
|
||||||
// using os.StartProcess or (more commonly) exec.Command.
|
// using os.StartProcess or (more commonly) exec.Command.
|
||||||
func HasExec() bool {
|
func HasExec() bool {
|
||||||
|
@ -10,9 +10,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"internal/testenv"
|
"internal/testenv"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -67,16 +65,10 @@ func TestCleanHost(t *testing.T) {
|
|||||||
// This catches accidental dependencies between the HTTP transport and
|
// This catches accidental dependencies between the HTTP transport and
|
||||||
// server code.
|
// server code.
|
||||||
func TestCmdGoNoHTTPServer(t *testing.T) {
|
func TestCmdGoNoHTTPServer(t *testing.T) {
|
||||||
testenv.MustHaveGoBuild(t)
|
goBin := testenv.GoToolPath(t)
|
||||||
var exeSuffix string
|
out, err := exec.Command("go", "tool", "nm", goBin).CombinedOutput()
|
||||||
if runtime.GOOS == "windows" {
|
|
||||||
exeSuffix = ".exe"
|
|
||||||
}
|
|
||||||
|
|
||||||
goBin := filepath.Join(runtime.GOROOT(), "bin", "go"+exeSuffix)
|
|
||||||
out, err := exec.Command("go", "tool", "nm", goBin).Output()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("go tool nm: %v", err)
|
t.Fatalf("go tool nm: %v: %s", err, out)
|
||||||
}
|
}
|
||||||
wantSym := map[string]bool{
|
wantSym := map[string]bool{
|
||||||
// Verify these exist: (sanity checking this test)
|
// Verify these exist: (sanity checking this test)
|
||||||
|
Loading…
Reference in New Issue
Block a user