diff options
| author | Russ Cox <rsc@golang.org> | 2015-06-05 11:01:53 -0400 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2015-06-16 18:07:36 +0000 |
| commit | 7bc3e5880675ce4aae245f46d193924cff5efdfb (patch) | |
| tree | bc5991015f83aa4852edaf31b096fc968c3f6369 /src/cmd | |
| parent | 047f07a285edbc60f64018973be7ce6b341fe22d (diff) | |
| download | go-7bc3e5880675ce4aae245f46d193924cff5efdfb.tar.xz | |
all: extract "can I exec?" check from tests into internal/testenv
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>
Diffstat (limited to 'src/cmd')
| -rw-r--r-- | src/cmd/addr2line/addr2line_test.go | 17 | ||||
| -rw-r--r-- | src/cmd/cover/cover_test.go | 13 | ||||
| -rw-r--r-- | src/cmd/go/go_test.go | 48 | ||||
| -rw-r--r-- | src/cmd/go/note_test.go | 9 | ||||
| -rw-r--r-- | src/cmd/go/vcs_test.go | 11 | ||||
| -rw-r--r-- | src/cmd/internal/obj/x86/obj6_test.go | 8 | ||||
| -rw-r--r-- | src/cmd/nm/nm_test.go | 11 | ||||
| -rw-r--r-- | src/cmd/objdump/objdump_test.go | 11 | ||||
| -rw-r--r-- | src/cmd/pack/pack_test.go | 22 | ||||
| -rw-r--r-- | src/cmd/vet/vet_test.go | 23 |
10 files changed, 37 insertions, 136 deletions
diff --git a/src/cmd/addr2line/addr2line_test.go b/src/cmd/addr2line/addr2line_test.go index c83a883b8c..e8234e2da2 100644 --- a/src/cmd/addr2line/addr2line_test.go +++ b/src/cmd/addr2line/addr2line_test.go @@ -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) diff --git a/src/cmd/cover/cover_test.go b/src/cmd/cover/cover_test.go index af7ea443cd..f01f138cd0 100644 --- a/src/cmd/cover/cover_test.go +++ b/src/cmd/cover/cover_test.go @@ -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 { diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go index b6d2705309..c36e59586b 100644 --- a/src/cmd/go/go_test.go +++ b/src/cmd/go/go_test.go @@ -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() diff --git a/src/cmd/go/note_test.go b/src/cmd/go/note_test.go index f2390cbae5..ae5514188d 100644 --- a/src/cmd/go/note_test.go +++ b/src/cmd/go/note_test.go @@ -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-") diff --git a/src/cmd/go/vcs_test.go b/src/cmd/go/vcs_test.go index 14d681ba6a..7c7adbe5e9 100644 --- a/src/cmd/go/vcs_test.go +++ b/src/cmd/go/vcs_test.go @@ -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 diff --git a/src/cmd/internal/obj/x86/obj6_test.go b/src/cmd/internal/obj/x86/obj6_test.go index b4526fc9a6..6302107536 100644 --- a/src/cmd/internal/obj/x86/obj6_test.go +++ b/src/cmd/internal/obj/x86/obj6_test.go @@ -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) diff --git a/src/cmd/nm/nm_test.go b/src/cmd/nm/nm_test.go index 155d103ee7..602a288104 100644 --- a/src/cmd/nm/nm_test.go +++ b/src/cmd/nm/nm_test.go @@ -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 { diff --git a/src/cmd/objdump/objdump_test.go b/src/cmd/objdump/objdump_test.go index 9bd71495af..54e26552e0 100644 --- a/src/cmd/objdump/objdump_test.go +++ b/src/cmd/objdump/objdump_test.go @@ -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 { diff --git a/src/cmd/pack/pack_test.go b/src/cmd/pack/pack_test.go index cd32020501..c305a87b57 100644 --- a/src/cmd/pack/pack_test.go +++ b/src/cmd/pack/pack_test.go @@ -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) diff --git a/src/cmd/vet/vet_test.go b/src/cmd/vet/vet_test.go index af374787f0..9aae8dd930 100644 --- a/src/cmd/vet/vet_test.go +++ b/src/cmd/vet/vet_test.go @@ -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) |
