import (
"bufio"
"bytes"
+ "internal/testenv"
"io/ioutil"
"os"
"os/exec"
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)
import (
"bytes"
"fmt"
+ "internal/testenv"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
- "runtime"
"testing"
)
// 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 {
"bytes"
"flag"
"fmt"
+ "internal/testenv"
"io/ioutil"
"os"
"os/exec"
// 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}
}
}
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()
}
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)
// 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()
// 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()
}
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()
}
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()
}
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()
// 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()
)
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-")
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
"bytes"
"fmt"
"go/build"
+ "internal/testenv"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"regexp"
- "runtime"
"strconv"
"strings"
"testing"
}
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)
"bufio"
"bytes"
"fmt"
+ "internal/testenv"
"io/ioutil"
"os"
"os/exec"
}
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 {
package main
import (
+ "internal/testenv"
"io/ioutil"
"os"
"os/exec"
)
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 {
"bufio"
"bytes"
"fmt"
+ "internal/testenv"
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
- "runtime"
"testing"
"time"
"unicode/utf8"
// 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)
// 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)
import (
"bytes"
+ "internal/testenv"
"os"
"os/exec"
"path/filepath"
"runtime"
- "strings"
"testing"
)
// 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
// 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)
"encoding/base64"
"encoding/hex"
"encoding/pem"
+ "internal/testenv"
"math/big"
"net"
"os/exec"
"reflect"
- "runtime"
"testing"
"time"
)
}
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)
"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"},
--- /dev/null
+// 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")
+}
"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],
// 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)
// 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],
"bufio"
"bytes"
"fmt"
+ "internal/testenv"
"io"
"io/ioutil"
"log"
"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...)
}
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.
}
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.
"errors"
"flag"
"fmt"
+ "internal/testenv"
"io"
"io/ioutil"
. "os"
}
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
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
}
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")
}
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)
import (
"fmt"
+ "internal/testenv"
"io/ioutil"
"os"
"os/exec"
}
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)
import (
"bytes"
"fmt"
+ "internal/testenv"
"math/big"
"os"
"os/exec"
// 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" {
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)
}
}
package syscall_test
import (
+ "internal/testenv"
"io"
"os"
"os/exec"
"os/signal"
- "runtime"
"syscall"
"testing"
"unsafe"
}
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 {
import (
"flag"
"fmt"
+ "internal/testenv"
"io/ioutil"
"net"
"os"
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