"testing": {"L2", "flag", "fmt", "os", "runtime/debug", "runtime/pprof", "runtime/trace", "time"},
"testing/iotest": {"L2", "log"},
"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
// you're using L3 packages, use of fmt, log, or time is not a big deal.
import (
"os"
+ "os/exec"
"runtime"
"strings"
"testing"
}
}
+// 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 {
"bytes"
"internal/testenv"
"os/exec"
- "path/filepath"
"reflect"
- "runtime"
"testing"
)
// This catches accidental dependencies between the HTTP transport and
// server code.
func TestCmdGoNoHTTPServer(t *testing.T) {
- testenv.MustHaveGoBuild(t)
- var exeSuffix string
- if runtime.GOOS == "windows" {
- exeSuffix = ".exe"
- }
-
- goBin := filepath.Join(runtime.GOROOT(), "bin", "go"+exeSuffix)
- out, err := exec.Command("go", "tool", "nm", goBin).Output()
+ goBin := testenv.GoToolPath(t)
+ out, err := exec.Command("go", "tool", "nm", goBin).CombinedOutput()
if err != nil {
- t.Fatalf("go tool nm: %v", err)
+ t.Fatalf("go tool nm: %v: %s", err, out)
}
wantSym := map[string]bool{
// Verify these exist: (sanity checking this test)