env []string
tempdir string
ran bool
+ inParallel bool
stdout, stderr bytes.Buffer
}
}
}
+// parallel runs the test in parallel by calling t.Parallel.
+func (tg *testgoData) parallel() {
+ if tg.ran {
+ tg.t.Fatal("internal testsuite error: call to parallel after run")
+ }
+ if tg.wd != "" {
+ tg.t.Fatal("internal testsuite error: call to parallel after cd")
+ }
+ for _, e := range tg.env {
+ if strings.HasPrefix(e, "GOROOT=") || strings.HasPrefix(e, "GOPATH=") || strings.HasPrefix(e, "GOBIN=") {
+ val := e[strings.Index(e, "=")+1:]
+ if strings.HasPrefix(val, "testdata") || strings.HasPrefix(val, "./testdata") {
+ tg.t.Fatalf("internal testsuite error: call to parallel with testdata in environment (%s)", e)
+ }
+ }
+ }
+ tg.inParallel = true
+ tg.t.Parallel()
+}
+
// pwd returns the current directory.
func (tg *testgoData) pwd() string {
wd, err := os.Getwd()
// using this means that the test must not be run in parallel with any
// other tests.
func (tg *testgoData) cd(dir string) {
+ if tg.inParallel {
+ tg.t.Fatal("internal testsuite error: changing directory when running in parallel")
+ }
if tg.wd == "" {
tg.wd = tg.pwd()
}
// setenv sets an environment variable to use when running the test go
// command.
func (tg *testgoData) setenv(name, val string) {
+ if tg.inParallel && (name == "GOROOT" || name == "GOPATH" || name == "GOBIN") && (strings.HasPrefix(val, "testdata") || strings.HasPrefix(val, "./testdata")) {
+ tg.t.Fatalf("internal testsuite error: call to setenv with testdata (%s=%s) after parallel", name, val)
+ }
tg.unsetenv(name)
tg.env = append(tg.env, name+"="+val)
}
if !canRun {
panic("testgoData.doRun called but canRun false")
}
+ if tg.inParallel {
+ for _, arg := range args {
+ if strings.HasPrefix(arg, "testdata") || strings.HasPrefix(arg, "./testdata") {
+ tg.t.Fatal("internal testsuite error: parallel run using testdata")
+ }
+ }
+ }
tg.t.Logf("running testgo %v", args)
var prog string
if tg.wd == "" {
func TestFileLineInErrorMessages(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
+ tg.parallel()
tg.tempFile("err.go", `package main; import "bar"`)
path := tg.path("err.go")
tg.runFail("run", path)
func TestProgramNameInCrashMessages(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
+ tg.parallel()
tg.tempFile("triv.go", `package main; func main() {}`)
tg.runFail("build", "-ldflags", "-crash_for_testing", tg.path("triv.go"))
tg.grepStderr(`[/\\]tool[/\\].*[/\\]link`, "missing linker name in error message")
}
func TestGoBuildDashAInDevBranch(t *testing.T) {
+ if testing.Short() {
+ t.Skip("don't rebuild the standard library in short mode")
+ }
+
tg := testgo(t)
defer tg.cleanup()
tg.run("install", "math") // should be up to date already but just in case
func TestGoBuilDashAInReleaseBranch(t *testing.T) {
if testing.Short() {
- t.Skip("don't rebuild the standard libary in short mode")
+ t.Skip("don't rebuild the standard library in short mode")
}
tg := testgo(t)
func TestGoInstallRebuildsStalePackagesInOtherGOPATH(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
+ tg.parallel()
tg.tempFile("d1/src/p1/p1.go", `package p1
import "p2"
func TestGoInstallDetectsRemovedFiles(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
+ tg.parallel()
tg.tempFile("src/mypkg/x.go", `package mypkg`)
tg.tempFile("src/mypkg/y.go", `package mypkg`)
tg.tempFile("src/mypkg/z.go", `// +build missingtag
func TestGoInstsallDetectsRemovedFilesInPackageMain(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
+ tg.parallel()
tg.tempFile("src/mycmd/x.go", `package main
func main() {}
}
tg := testgo(t)
defer tg.cleanup()
+ tg.parallel()
tg.tempDir("src")
tg.setenv("GOPATH", tg.path("."))
tg.run("get", "-d", url)
// godoc installs into GOBIN
tg := testgo(t)
defer tg.cleanup()
+ tg.parallel()
tg.tempDir("gobin")
tg.setenv("GOPATH", tg.path("."))
tg.setenv("GOBIN", tg.path("gobin"))
func TestInstalls(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
+ tg.parallel()
tg.tempDir("gobin")
tg.setenv("GOPATH", tg.path("."))
goroot := runtime.GOROOT()
tg := testgo(t)
defer tg.cleanup()
+ tg.parallel()
tg.tempDir("src")
tg.setenv("GOPATH", "")
tg.setenv("GOROOT", tg.path("."))
tg := testgo(t)
defer tg.cleanup()
+ tg.parallel()
tg.tempDir("src")
tg.setenv("GOPATH", tg.path("."))
tg.setenv("GOROOT", tg.path("."))
func TestLdflagsArgumentsWithSpacesIssue3941(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
+ tg.parallel()
tg.tempFile("main.go", `package main
var extern string
func main() {
func TestInstallWithTags(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
+ tg.parallel()
tg.tempDir("bin")
tg.tempFile("src/example/a/main.go", `package main
func main() {}`)
func TestCaseCollisions(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
+ tg.parallel()
tg.tempDir("src/example/a/pkg")
tg.tempDir("src/example/a/Pkg")
tg.tempDir("src/example/b")
tg := testgo(t)
defer tg.cleanup()
+ tg.parallel()
tg.makeTempdir()
tg.setenv("GOPATH", tg.path("."))
tg.run("get", "-t", "code.google.com/p/go-get-issue-8181/a", "code.google.com/p/go-get-issue-8181/b")
tg := testgo(t)
defer tg.cleanup()
+ tg.parallel()
tg.tempFile("src/x/y/dirname/foo.go", `
package foo
import "C"
tg := testgo(t)
defer tg.cleanup()
+ tg.parallel()
tg.tempFile("src/origin/origin.go", `package origin
// #cgo !darwin LDFLAGS: -Wl,-rpath -Wl,$ORIGIN
// void f(void) {}
tg := testgo(t)
defer tg.cleanup()
+ tg.parallel()
tg.tempFile("src/cgoref/cgoref.go", `
package main
// #cgo LDFLAGS: -L alibpath -lalib
func TestBuildDashIInstallsDependencies(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
+ tg.parallel()
tg.tempFile("src/x/y/foo/foo.go", `package foo
func F() {}`)
tg.tempFile("src/x/y/bar/bar.go", `package bar