]> Cypherpunks repositories - gostls13.git/commitdiff
all: extract "can I exec?" check from tests into internal/testenv
authorRuss Cox <rsc@golang.org>
Fri, 5 Jun 2015 15:01:53 +0000 (11:01 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 16 Jun 2015 18:07:36 +0000 (18:07 +0000)
Change-Id: I7b54be9d8b50b39e01c6be21f310ae9a10404e9d
Reviewed-on: https://go-review.googlesource.com/10753
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
21 files changed:
src/cmd/addr2line/addr2line_test.go
src/cmd/cover/cover_test.go
src/cmd/go/go_test.go
src/cmd/go/note_test.go
src/cmd/go/vcs_test.go
src/cmd/internal/obj/x86/obj6_test.go
src/cmd/nm/nm_test.go
src/cmd/objdump/objdump_test.go
src/cmd/pack/pack_test.go
src/cmd/vet/vet_test.go
src/crypto/x509/x509_test.go
src/go/build/deps_test.go
src/internal/testenv/testenv.go [new file with mode: 0644]
src/net/http/cgi/matryoshka_test.go
src/os/exec/exec_test.go
src/os/os_test.go
src/runtime/crash_test.go
src/runtime/pprof/pprof_test.go
src/runtime/pprof/trace_test.go
src/syscall/exec_unix_test.go
src/syscall/syscall_unix_test.go

index c83a883b8c36de2ad470900d9a07adf19547e43f..e8234e2da227a63f3901b64d7d1d63afad7a9cf2 100644 (file)
@@ -7,6 +7,7 @@ package main
 import (
        "bufio"
        "bytes"
+       "internal/testenv"
        "io/ioutil"
        "os"
        "os/exec"
@@ -85,22 +86,14 @@ func testAddr2Line(t *testing.T, exepath, addr string) {
        if !os.SameFile(fi1, fi2) {
                t.Fatalf("addr2line_test.go and %s are not same file", srcPath)
        }
-       if srcLineNo != "94" {
-               t.Fatalf("line number = %v; want 94", srcLineNo)
+       if srcLineNo != "95" {
+               t.Fatalf("line number = %v; want 95", srcLineNo)
        }
 }
 
-// This is line 93. The test depends on that.
+// This is line 94. The test depends on that.
 func TestAddr2Line(t *testing.T) {
-       switch runtime.GOOS {
-       case "nacl", "android":
-               t.Skipf("skipping on %s", runtime.GOOS)
-       case "darwin":
-               switch runtime.GOARCH {
-               case "arm", "arm64":
-                       t.Skipf("skipping on %s/%s, cannot fork", runtime.GOOS, runtime.GOARCH)
-               }
-       }
+       testenv.MustHaveGoBuild(t)
 
        syms := loadSyms(t)
 
index af7ea443cd5bf71beaaf723c6e79dfc8f8eca405..f01f138cd0232c0636df8f7c61710561ed8cc908 100644 (file)
@@ -7,11 +7,11 @@ package main_test
 import (
        "bytes"
        "fmt"
+       "internal/testenv"
        "io/ioutil"
        "os"
        "os/exec"
        "path/filepath"
-       "runtime"
        "testing"
 )
 
@@ -41,15 +41,8 @@ var debug = false // Keeps the rewritten files around if set.
 //     go run ./testdata/main.go ./testdata/test.go
 //
 func TestCover(t *testing.T) {
-       switch runtime.GOOS {
-       case "nacl":
-               t.Skipf("skipping; %v/%v no support for forking", runtime.GOOS, runtime.GOARCH)
-       case "darwin", "android":
-               switch runtime.GOARCH {
-               case "arm", "arm64":
-                       t.Skipf("skipping; %v/%v no support for forking", runtime.GOOS, runtime.GOARCH)
-               }
-       }
+       testenv.MustHaveGoBuild(t)
+
        // Read in the test file (testTest) and write it, with LINEs specified, to coverInput.
        file, err := ioutil.ReadFile(testTest)
        if err != nil {
index b6d2705309562a9f8ba973c1529c0daa1c02c15d..c36e59586b53c306ae53c9fc152954b784c0f7be 100644 (file)
@@ -8,6 +8,7 @@ import (
        "bytes"
        "flag"
        "fmt"
+       "internal/testenv"
        "io/ioutil"
        "os"
        "os/exec"
@@ -129,19 +130,7 @@ type testgoData struct {
 
 // testgo sets up for a test that runs testgo.
 func testgo(t *testing.T) *testgoData {
-       if !canRun {
-               switch runtime.GOOS {
-               case "android", "nacl":
-                       t.Skipf("skipping on %s", runtime.GOOS)
-               case "darwin":
-                       switch runtime.GOARCH {
-                       case "arm", "arm64":
-                               t.Skipf("skipping on %s/%s, no fork", runtime.GOOS, runtime.GOARCH)
-                       }
-               default:
-                       t.Skip("skipping for unknown reason")
-               }
-       }
+       testenv.MustHaveGoBuild(t)
 
        return &testgoData{t: t}
 }
@@ -835,9 +824,8 @@ func TestInternalPackagesOutsideGOROOTAreRespected(t *testing.T) {
 }
 
 func testMove(t *testing.T, vcs, url, base, config string) {
-       if testing.Short() {
-               t.Skip("skipping test that uses network in short mode")
-       }
+       testenv.MustHaveExternalNetwork(t)
+
        tg := testgo(t)
        defer tg.cleanup()
        tg.parallel()
@@ -1053,9 +1041,7 @@ func TestInstallToGOBINCommandLinePackage(t *testing.T) {
 }
 
 func TestGodocInstalls(t *testing.T) {
-       if testing.Short() {
-               t.Skip("skipping test that uses network in short mode")
-       }
+       testenv.MustHaveExternalNetwork(t)
 
        // godoc installs into GOBIN
        tg := testgo(t)
@@ -1248,9 +1234,7 @@ func TestMissingGOPATHIsReported(t *testing.T) {
 // Issue 4186.  go get cannot be used to download packages to $GOROOT.
 // Test that without GOPATH set, go get should fail.
 func TestWithoutGOPATHGoGetFails(t *testing.T) {
-       if testing.Short() {
-               t.Skip("skipping test that uses network in short mode")
-       }
+       testenv.MustHaveExternalNetwork(t)
 
        tg := testgo(t)
        defer tg.cleanup()
@@ -1263,9 +1247,7 @@ func TestWithoutGOPATHGoGetFails(t *testing.T) {
 
 // Test that with GOPATH=$GOROOT, go get should fail.
 func TestWithGOPATHEqualsGOROOTGoGetFails(t *testing.T) {
-       if testing.Short() {
-               t.Skip("skipping test that uses network in short mode")
-       }
+       testenv.MustHaveExternalNetwork(t)
 
        tg := testgo(t)
        defer tg.cleanup()
@@ -1799,9 +1781,7 @@ func TestGoGenerateRunFlag(t *testing.T) {
 }
 
 func TestGoGetWorksWithVanityWildcards(t *testing.T) {
-       if testing.Short() {
-               t.Skip("skipping test that uses network in short mode")
-       }
+       testenv.MustHaveExternalNetwork(t)
 
        tg := testgo(t)
        defer tg.cleanup()
@@ -1812,9 +1792,7 @@ func TestGoGetWorksWithVanityWildcards(t *testing.T) {
 }
 
 func TestGoVetWithExternalTests(t *testing.T) {
-       if testing.Short() {
-               t.Skip("skipping test that uses network in short mode")
-       }
+       testenv.MustHaveExternalNetwork(t)
 
        tg := testgo(t)
        defer tg.cleanup()
@@ -1827,9 +1805,7 @@ func TestGoVetWithExternalTests(t *testing.T) {
 }
 
 func TestGoVetWithTags(t *testing.T) {
-       if testing.Short() {
-               t.Skip("skipping test that uses network in short mode")
-       }
+       testenv.MustHaveExternalNetwork(t)
 
        tg := testgo(t)
        defer tg.cleanup()
@@ -1843,9 +1819,7 @@ func TestGoVetWithTags(t *testing.T) {
 
 // Issue 9767.
 func TestGoGetRscIoToolstash(t *testing.T) {
-       if testing.Short() {
-               t.Skip("skipping test that uses network in short mode")
-       }
+       testenv.MustHaveExternalNetwork(t)
 
        tg := testgo(t)
        defer tg.cleanup()
index f2390cbae5d910c6352a34c07fb8245c3644e50b..ae5514188da0e45b73af7f67471a2a3733b1cf50 100644 (file)
@@ -13,14 +13,7 @@ import (
 )
 
 func TestNoteReading(t *testing.T) {
-       // No file system access on these systems.
-       switch sys := runtime.GOOS + "/" + runtime.GOARCH; sys {
-       case "darwin/arm", "darwin/arm64", "nacl/386", "nacl/amd64p32", "nacl/arm":
-               t.Skipf("skipping on %s/%s - no file system", runtime.GOOS, runtime.GOARCH)
-       }
-       if runtime.GOOS == "android" {
-               t.Skipf("skipping; requires go tool")
-       }
+       testenv.MustHaveGoBuild(t)
 
        // TODO: Replace with new test scaffolding by iant.
        d, err := ioutil.TempDir("", "go-test-")
index 14d681ba6afc5e1f88f566a27322874c53e77ed1..7c7adbe5e9ed07332e273a9555f1c2130896ac95 100644 (file)
@@ -5,20 +5,15 @@
 package main
 
 import (
-       "runtime"
+       "internal/testenv"
        "testing"
 )
 
 // Test that RepoRootForImportPath creates the correct RepoRoot for a given importPath.
 // TODO(cmang): Add tests for SVN and BZR.
 func TestRepoRootForImportPath(t *testing.T) {
-       if testing.Short() {
-               t.Skip("skipping test to avoid external network")
-       }
-       switch runtime.GOOS {
-       case "nacl", "android":
-               t.Skipf("no networking available on %s", runtime.GOOS)
-       }
+       testenv.MustHaveExternalNetwork(t)
+
        tests := []struct {
                path string
                want *repoRoot
index b4526fc9a681f50e460c8d674024866dd3ce0078..63021075367c3e5461e1505e673cf4c1e4235f4a 100644 (file)
@@ -5,12 +5,12 @@ import (
        "bytes"
        "fmt"
        "go/build"
+       "internal/testenv"
        "io/ioutil"
        "os"
        "os/exec"
        "path/filepath"
        "regexp"
-       "runtime"
        "strconv"
        "strings"
        "testing"
@@ -148,10 +148,8 @@ func parseOutput(t *testing.T, td *ParsedTestData, asmout []byte) {
 }
 
 func TestDynlink(t *testing.T) {
-       iOS := runtime.GOOS == "darwin" && (runtime.GOARCH == "arm" || runtime.GOARCH == "arm64")
-       if runtime.GOOS == "nacl" || runtime.GOOS == "android" || iOS {
-               t.Skipf("skipping on %s/%s, cannot fork", runtime.GOOS, runtime.GOARCH)
-       }
+       testenv.MustHaveGoBuild(t)
+
        testdata := parseTestData(t)
        asmout := asmOutput(t, testdata.input)
        parseOutput(t, testdata, asmout)
index 155d103ee7fd1201ba7b4cd73418c788e680f6c0..602a2881045d9fdca2d96c003553be37b02783b0 100644 (file)
@@ -8,6 +8,7 @@ import (
        "bufio"
        "bytes"
        "fmt"
+       "internal/testenv"
        "io/ioutil"
        "os"
        "os/exec"
@@ -55,15 +56,7 @@ func checkSymbols(t *testing.T, nmoutput []byte) {
 }
 
 func TestNM(t *testing.T) {
-       switch runtime.GOOS {
-       case "android", "nacl":
-               t.Skipf("skipping on %s", runtime.GOOS)
-       case "darwin":
-               switch runtime.GOARCH {
-               case "arm", "arm64":
-                       t.Skipf("skipping on %s/%s, cannot fork", runtime.GOOS, runtime.GOARCH)
-               }
-       }
+       testenv.MustHaveGoBuild(t)
 
        tmpDir, err := ioutil.TempDir("", "TestNM")
        if err != nil {
index 9bd71495afb97e315a0e3cf1cd4c48636466e35e..54e26552e0aae0c41b02ea2a9c2942cb6b7b3128 100644 (file)
@@ -5,6 +5,7 @@
 package main
 
 import (
+       "internal/testenv"
        "io/ioutil"
        "os"
        "os/exec"
@@ -15,15 +16,7 @@ import (
 )
 
 func buildObjdump(t *testing.T) (tmp, exe string) {
-       switch runtime.GOOS {
-       case "android", "nacl":
-               t.Skipf("skipping on %s", runtime.GOOS)
-       case "darwin":
-               switch runtime.GOARCH {
-               case "arm", "arm64":
-                       t.Skipf("skipping on %s/%s, cannot fork", runtime.GOOS, runtime.GOARCH)
-               }
-       }
+       testenv.MustHaveGoBuild(t)
 
        tmp, err := ioutil.TempDir("", "TestObjDump")
        if err != nil {
index cd320205014834c88e405eee73089034d15116b1..c305a87b57d08c90dd0ff8896a186e6e2f51ed8e 100644 (file)
@@ -8,12 +8,12 @@ import (
        "bufio"
        "bytes"
        "fmt"
+       "internal/testenv"
        "io"
        "io/ioutil"
        "os"
        "os/exec"
        "path/filepath"
-       "runtime"
        "testing"
        "time"
        "unicode/utf8"
@@ -198,15 +198,7 @@ func TestExtract(t *testing.T) {
 
 // Test that pack-created archives can be understood by the tools.
 func TestHello(t *testing.T) {
-       switch runtime.GOOS {
-       case "android", "nacl":
-               t.Skipf("skipping on %s", runtime.GOOS)
-       case "darwin":
-               switch runtime.GOARCH {
-               case "arm", "arm64":
-                       t.Skipf("skipping on %s/%s, cannot fork", runtime.GOOS, runtime.GOARCH)
-               }
-       }
+       testenv.MustHaveGoBuild(t)
 
        dir := tmpDir(t)
        defer os.RemoveAll(dir)
@@ -238,15 +230,7 @@ func TestHello(t *testing.T) {
 
 // Test that pack works with very long lines in PKGDEF.
 func TestLargeDefs(t *testing.T) {
-       switch runtime.GOOS {
-       case "android", "nacl":
-               t.Skipf("skipping on %s", runtime.GOOS)
-       case "darwin":
-               switch runtime.GOARCH {
-               case "arm", "arm64":
-                       t.Skipf("skipping on %s/%s, cannot fork", runtime.GOOS, runtime.GOARCH)
-               }
-       }
+       testenv.MustHaveGoBuild(t)
 
        dir := tmpDir(t)
        defer os.RemoveAll(dir)
index af374787f0ca3128ef9a4447ce899d4105309373..9aae8dd930fff3ab8fa89fbf09dddd826bfa6a98 100644 (file)
@@ -6,11 +6,11 @@ package main_test
 
 import (
        "bytes"
+       "internal/testenv"
        "os"
        "os/exec"
        "path/filepath"
        "runtime"
-       "strings"
        "testing"
 )
 
@@ -25,18 +25,12 @@ const (
 //     rm testvet
 //
 func TestVet(t *testing.T) {
+       testenv.MustHaveGoBuild(t)
+
        switch runtime.GOOS {
        case "plan9", "windows":
                // Plan 9 and Windows systems can't be guaranteed to have Perl and so can't run errchk.
                t.Skipf("skipping test; no Perl on %q", runtime.GOOS)
-       case "nacl":
-               t.Skip("skipping test; no command execution on nacl")
-       case "darwin":
-               if strings.HasPrefix(runtime.GOARCH, "arm") {
-                       t.Skipf("skipping test; no command execution on darwin/%s", runtime.GOARCH)
-               }
-       case "android":
-               t.Skip("skipping test; no go toolchain available")
        }
 
        // go build
@@ -84,16 +78,7 @@ func run(c *exec.Cmd, t *testing.T) bool {
 
 // TestTags verifies that the -tags argument controls which files to check.
 func TestTags(t *testing.T) {
-       switch runtime.GOOS {
-       case "nacl":
-               t.Skip("skipping test; no command execution on nacl")
-       case "darwin":
-               if strings.HasPrefix(runtime.GOARCH, "arm") {
-                       t.Skip("skipping test; no command execution on darwin/%s", runtime.GOARCH)
-               }
-       case "android":
-               t.Skip("skipping test; no go toolchain available")
-       }
+       testenv.MustHaveGoBuild(t)
 
        // go build
        cmd := exec.Command("go", "build", "-o", binary)
index 86a8b16cba164c3b2127ccf0516f6cf5d369671a..d83147bb291c763f7e37c259bbeebab737dc71f7 100644 (file)
@@ -18,11 +18,11 @@ import (
        "encoding/base64"
        "encoding/hex"
        "encoding/pem"
+       "internal/testenv"
        "math/big"
        "net"
        "os/exec"
        "reflect"
-       "runtime"
        "testing"
        "time"
 )
@@ -848,15 +848,7 @@ func TestParsePEMCRL(t *testing.T) {
 }
 
 func TestImports(t *testing.T) {
-       switch runtime.GOOS {
-       case "android", "nacl":
-               t.Skipf("skipping on %s", runtime.GOOS)
-       case "darwin":
-               switch runtime.GOARCH {
-               case "arm", "arm64":
-                       t.Skipf("skipping on %s/%s, cannot fork", runtime.GOOS, runtime.GOARCH)
-               }
-       }
+       testenv.MustHaveGoRun(t)
 
        if err := exec.Command("go", "run", "x509_test_import.go").Run(); err != nil {
                t.Errorf("failed to run x509_test_import.go: %s", err)
index 8e985aa05b962871954a0a06a0844fd40820b414..187e9d1bb536efb2679372423a6756e72e90e61f 100644 (file)
@@ -352,6 +352,7 @@ var pkgDeps = map[string][]string{
        "internal/syscall/unix":             {"runtime", "sync/atomic", "syscall", "unsafe"},
        "internal/syscall/windows":          {"syscall", "unsafe"},
        "internal/syscall/windows/registry": {"errors", "io", "syscall", "unicode/utf16", "unsafe"},
+       "internal/testenv":                  {"runtime", "strings", "testing"},
        "internal/trace":                    {"bufio", "bytes", "fmt", "io", "os", "os/exec", "sort", "strconv", "strings"},
        "net/http/cookiejar":                {"errors", "fmt", "net", "net/http", "net/url", "sort", "strings", "sync", "time", "unicode/utf8"},
        "net/http/internal":                 {"bufio", "bytes", "errors", "fmt", "io"},
diff --git a/src/internal/testenv/testenv.go b/src/internal/testenv/testenv.go
new file mode 100644 (file)
index 0000000..a1de61f
--- /dev/null
@@ -0,0 +1,90 @@
+// Copyright 2015 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Package testenv provides information about what functionality
+// is available in different testing environments run by the Go team.
+//
+// It is an internal package because these details are specific
+// to the Go team's test setup (on build.golang.org) and not
+// fundamental to tests in general.
+package testenv
+
+import (
+       "runtime"
+       "strings"
+       "testing"
+)
+
+// HasGoBuild reports whether the current system can build programs with ``go build''
+// and then run them with os.StartProcess or exec.Command.
+func HasGoBuild() bool {
+       switch runtime.GOOS {
+       case "android", "nacl":
+               return false
+       case "darwin":
+               if strings.HasPrefix(runtime.GOARCH, "arm") {
+                       return false
+               }
+       }
+       return true
+}
+
+// MustHaveGoBuild checks that the current system can build programs with ``go build''
+// and then run them with os.StartProcess or exec.Command.
+// If not, MustHaveGoBuild calls t.Skip with an explanation.
+func MustHaveGoBuild(t *testing.T) {
+       if !HasGoBuild() {
+               t.Skipf("skipping test: 'go build' not available on %s/%s", runtime.GOOS, runtime.GOARCH)
+       }
+}
+
+// HasGoRun reports whether the current system can run programs with ``go run.''
+func HasGoRun() bool {
+       // For now, having go run and having go build are the same.
+       return HasGoBuild()
+}
+
+// MustHaveGoRun checks that the current system can run programs with ``go run.''
+// If not, MustHaveGoRun calls t.Skip with an explanation.
+func MustHaveGoRun(t *testing.T) {
+       if !HasGoRun() {
+               t.Skipf("skipping test: 'go run' not available on %s/%s", runtime.GOOS, runtime.GOARCH)
+       }
+}
+
+// HasExec reports whether the current system can start new processes
+// using os.StartProcess or (more commonly) exec.Command.
+func HasExec() bool {
+       switch runtime.GOOS {
+       case "nacl":
+               return false
+       case "darwin":
+               if strings.HasPrefix(runtime.GOARCH, "arm") {
+                       return false
+               }
+       }
+       return true
+}
+
+// MustHaveExec checks that the current system can start new processes
+// using os.StartProcess or (more commonly) exec.Command.
+// If not, MustHaveExec calls t.Skip with an explanation.
+func MustHaveExec(t *testing.T) {
+       if !HasExec() {
+               t.Skipf("skipping test: cannot exec subprocess on %s/%s", runtime.GOOS, runtime.GOARCH)
+       }
+}
+
+// HasExternalNetwork reports whether the current system can use
+// external (non-localhost) networks.
+func HasExternalNetwork() bool {
+       return !testing.Short()
+}
+
+// MustHaveExternalNetwork checks that the current system can use
+// external (non-localhost) networks.
+// If not, MustHaveExternalNetwork calls t.Skip with an explanation.
+func MustHaveExternalNetwork(t *testing.T) {
+       t.Skipf("skipping test: no external network in -short mode")
+}
index c89c6d525e6a48bb0ff2a031deafba3276cd781c..32d59c09a3c52be726386978852960b3677c45b0 100644 (file)
@@ -12,24 +12,19 @@ import (
        "bytes"
        "errors"
        "fmt"
+       "internal/testenv"
        "io"
        "net/http"
        "net/http/httptest"
        "os"
-       "runtime"
        "testing"
        "time"
 )
 
-// iOS cannot fork, so we skip some tests
-var iOS = runtime.GOOS == "darwin" && (runtime.GOARCH == "arm" || runtime.GOARCH == "arm64")
-
 // This test is a CGI host (testing host.go) that runs its own binary
 // as a child process testing the other half of CGI (child.go).
 func TestHostingOurselves(t *testing.T) {
-       if runtime.GOOS == "nacl" || iOS {
-               t.Skipf("skipping on %s/%s", runtime.GOOS, runtime.GOARCH)
-       }
+       testenv.MustHaveExec(t)
 
        h := &Handler{
                Path: os.Args[0],
@@ -96,9 +91,7 @@ func (w *limitWriter) Write(p []byte) (n int, err error) {
 // If there's an error copying the child's output to the parent, test
 // that we kill the child.
 func TestKillChildAfterCopyError(t *testing.T) {
-       if runtime.GOOS == "nacl" || iOS {
-               t.Skipf("skipping on %s/%s", runtime.GOOS, runtime.GOARCH)
-       }
+       testenv.MustHaveExec(t)
 
        defer func() { testHookStartProcess = nil }()
        proc := make(chan *os.Process, 1)
@@ -143,9 +136,7 @@ func TestKillChildAfterCopyError(t *testing.T) {
 // Test that a child handler writing only headers works.
 // golang.org/issue/7196
 func TestChildOnlyHeaders(t *testing.T) {
-       if runtime.GOOS == "nacl" || iOS {
-               t.Skipf("skipping on %s/%s", runtime.GOOS, runtime.GOARCH)
-       }
+       testenv.MustHaveExec(t)
 
        h := &Handler{
                Path: os.Args[0],
index db84eabf26e999845c28577b0d171de098873311..3773963cb0dd3772fe1d11348870ee1de9de78b8 100644 (file)
@@ -11,6 +11,7 @@ import (
        "bufio"
        "bytes"
        "fmt"
+       "internal/testenv"
        "io"
        "io/ioutil"
        "log"
@@ -27,13 +28,9 @@ import (
        "time"
 )
 
-// iOS cannot fork
-var iOS = runtime.GOOS == "darwin" && (runtime.GOARCH == "arm" || runtime.GOARCH == "arm64")
-
 func helperCommand(t *testing.T, s ...string) *exec.Cmd {
-       if runtime.GOOS == "nacl" || iOS {
-               t.Skipf("skipping on %s/%s, cannot fork", runtime.GOOS, runtime.GOARCH)
-       }
+       testenv.MustHaveExec(t)
+
        cs := []string{"-test.run=TestHelperProcess", "--"}
        cs = append(cs, s...)
        cmd := exec.Command(os.Args[0], cs...)
@@ -52,9 +49,7 @@ func TestEcho(t *testing.T) {
 }
 
 func TestCommandRelativeName(t *testing.T) {
-       if iOS {
-               t.Skip("skipping on darwin/%s, cannot fork", runtime.GOARCH)
-       }
+       testenv.MustHaveExec(t)
 
        // Run our own binary as a relative path
        // (e.g. "_test/exec.test") our parent directory.
@@ -427,13 +422,11 @@ func TestExtraFilesFDShuffle(t *testing.T) {
 }
 
 func TestExtraFiles(t *testing.T) {
-       switch runtime.GOOS {
-       case "nacl", "windows":
+       testenv.MustHaveExec(t)
+
+       if runtime.GOOS == "windows" {
                t.Skipf("skipping test on %q", runtime.GOOS)
        }
-       if iOS {
-               t.Skipf("skipping test on %s/%s, cannot fork", runtime.GOOS, runtime.GOARCH)
-       }
 
        // Ensure that file descriptors have not already been leaked into
        // our environment.
index b1fc998a90c0492d6b2afeb84064bed2bd6db852..3c0dfd194d0c457c39e6273283bc781744c1bf30 100644 (file)
@@ -9,6 +9,7 @@ import (
        "errors"
        "flag"
        "fmt"
+       "internal/testenv"
        "io"
        "io/ioutil"
        . "os"
@@ -794,15 +795,7 @@ func exec(t *testing.T, dir, cmd string, args []string, expect string) {
 }
 
 func TestStartProcess(t *testing.T) {
-       switch runtime.GOOS {
-       case "android", "nacl":
-               t.Skipf("skipping on %s", runtime.GOOS)
-       case "darwin":
-               switch runtime.GOARCH {
-               case "arm", "arm64":
-                       t.Skipf("skipping on %s/%s, cannot fork", runtime.GOOS, runtime.GOARCH)
-               }
-       }
+       testenv.MustHaveExec(t)
 
        var dir, cmd string
        var args []string
@@ -1258,19 +1251,13 @@ func testWindowsHostname(t *testing.T) {
 func TestHostname(t *testing.T) {
        // There is no other way to fetch hostname on windows, but via winapi.
        // On Plan 9 it can be taken from #c/sysname as Hostname() does.
-       switch runtime.GOOS {
-       case "android", "nacl", "plan9":
-               t.Skipf("skipping on %s", runtime.GOOS)
-       case "darwin":
-               switch runtime.GOARCH {
-               case "arm", "arm64":
-                       t.Skipf("skipping on %s/%s, cannot fork", runtime.GOOS, runtime.GOARCH)
-               }
-       case "windows":
+       if runtime.GOOS == "windows" {
                testWindowsHostname(t)
                return
        }
 
+       testenv.MustHaveExec(t)
+
        // Check internal Hostname() against the output of /bin/hostname.
        // Allow that the internal Hostname returns a Fully Qualified Domain Name
        // and the /bin/hostname only returns the first component
@@ -1529,15 +1516,7 @@ func TestReadAtEOF(t *testing.T) {
 }
 
 func testKillProcess(t *testing.T, processKiller func(p *Process)) {
-       switch runtime.GOOS {
-       case "android", "nacl":
-               t.Skipf("skipping on %s", runtime.GOOS)
-       case "darwin":
-               switch runtime.GOARCH {
-               case "arm", "arm64":
-                       t.Skipf("skipping on %s/%s", runtime.GOOS, runtime.GOARCH)
-               }
-       }
+       testenv.MustHaveExec(t)
 
        // Re-exec the test binary itself to emulate "sleep 1".
        cmd := osexec.Command(Args[0], "-test.run", "TestSleep")
@@ -1574,19 +1553,13 @@ func TestKillStartProcess(t *testing.T) {
 }
 
 func TestGetppid(t *testing.T) {
-       switch runtime.GOOS {
-       case "nacl":
-               t.Skip("skipping on nacl")
-       case "plan9":
+       if runtime.GOOS == "plan9" {
                // TODO: golang.org/issue/8206
                t.Skipf("skipping test on plan9; see issue 8206")
-       case "darwin":
-               switch runtime.GOARCH {
-               case "arm", "arm64":
-                       t.Skipf("skipping test on %s/%s, no fork", runtime.GOOS, runtime.GOARCH)
-               }
        }
 
+       testenv.MustHaveExec(t)
+
        if Getenv("GO_WANT_HELPER_PROCESS") == "1" {
                fmt.Print(Getppid())
                Exit(0)
index 975defdb604a29410f9294ec03d51f3a9dc0e8d2..8efce4da2d4d5b626e6163dafa205f5b6f1bec1e 100644 (file)
@@ -6,6 +6,7 @@ package runtime_test
 
 import (
        "fmt"
+       "internal/testenv"
        "io/ioutil"
        "os"
        "os/exec"
@@ -38,15 +39,7 @@ func testEnv(cmd *exec.Cmd) *exec.Cmd {
 }
 
 func executeTest(t *testing.T, templ string, data interface{}, extra ...string) string {
-       switch runtime.GOOS {
-       case "android", "nacl":
-               t.Skipf("skipping on %s", runtime.GOOS)
-       case "darwin":
-               switch runtime.GOARCH {
-               case "arm", "arm64":
-                       t.Skipf("skipping on %s/%s, no fork", runtime.GOOS, runtime.GOARCH)
-               }
-       }
+       testenv.MustHaveGoBuild(t)
 
        checkStaleRuntime(t)
 
index 0189f457a7bccb83f41e7c53dd5961c49db04d95..e9fd1466ee5755089948ae900d22cdffe1ff8d44 100644 (file)
@@ -9,6 +9,7 @@ package pprof_test
 import (
        "bytes"
        "fmt"
+       "internal/testenv"
        "math/big"
        "os"
        "os/exec"
@@ -209,12 +210,7 @@ func testCPUProfile(t *testing.T, need []string, f func()) {
 // Fork can hang if preempted with signals frequently enough (see issue 5517).
 // Ensure that we do not do this.
 func TestCPUProfileWithFork(t *testing.T) {
-       if runtime.GOOS == "darwin" {
-               switch runtime.GOARCH {
-               case "arm", "arm64":
-                       t.Skipf("skipping on %s/%s, cannot fork", runtime.GOOS, runtime.GOARCH)
-               }
-       }
+       testenv.MustHaveExec(t)
 
        heap := 1 << 30
        if runtime.GOOS == "android" {
index a333a3f83a0b3b21098b1b44659ddbf449467444..ba6eb669480d96df93d29e494822afe42e7e5ead 100644 (file)
@@ -24,6 +24,8 @@ func skipTraceTestsIfNeeded(t *testing.T) {
        case "darwin":
                switch runtime.GOARCH {
                case "arm", "arm64":
+                       // TODO(rsc): What does this have to do with the trace tests?
+                       // There is no forking here.
                        t.Skipf("skipping on %s/%s, cannot fork", runtime.GOOS, runtime.GOARCH)
                }
        }
index ff8261111eed9d42d1b5c0b2baa31da3e0edc40e..9bb95c0f39508a9bd7bdc2761eadb8af7c66cc9a 100644 (file)
@@ -7,11 +7,11 @@
 package syscall_test
 
 import (
+       "internal/testenv"
        "io"
        "os"
        "os/exec"
        "os/signal"
-       "runtime"
        "syscall"
        "testing"
        "unsafe"
@@ -48,9 +48,8 @@ func (c *command) Stop() {
 }
 
 func create(t *testing.T) *command {
-       if runtime.GOOS == "darwin" && (runtime.GOARCH == "arm" || runtime.GOARCH == "arm64") {
-               t.Skipf("skipping on %s/%s, cannot fork", runtime.GOOS, runtime.GOARCH)
-       }
+       testenv.MustHaveExec(t)
+
        proc := exec.Command("cat")
        stdin, err := proc.StdinPipe()
        if err != nil {
index af9201373953eb6b222b750ac38b6f15a6dcca58..6895458165c0c1916af0fc586a9f8c9023d5cf35 100644 (file)
@@ -9,6 +9,7 @@ package syscall_test
 import (
        "flag"
        "fmt"
+       "internal/testenv"
        "io/ioutil"
        "net"
        "os"
@@ -130,12 +131,10 @@ func TestPassFD(t *testing.T) {
        case "solaris":
                // TODO(aram): Figure out why ReadMsgUnix is returning empty message.
                t.Skip("skipping test on solaris, see issue 7402")
-       case "darwin":
-               switch runtime.GOARCH {
-               case "arm", "arm64":
-                       t.Skipf("skipping test on %d/%s, no fork", runtime.GOOS, runtime.GOARCH)
-               }
        }
+
+       testenv.MustHaveExec(t)
+
        if os.Getenv("GO_WANT_HELPER_PROCESS") == "1" {
                passFDChild()
                return