]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: fix 'go test foo_test.go'
authorRuss Cox <rsc@golang.org>
Tue, 13 May 2014 00:45:31 +0000 (20:45 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 13 May 2014 00:45:31 +0000 (20:45 -0400)
Fixes race build.

TBR=iant
CC=golang-codereviews
https://golang.org/cl/100410044

src/cmd/go/test.bash
src/cmd/go/test.go
src/cmd/go/testdata/standalone_test.go [new file with mode: 0644]

index 07114fe863dd20dacd69ddd9c2c791b92d17c2f8..92b6cf5962ac2ec07d4ab0ad9f1d43f46b1b23bc 100755 (executable)
@@ -783,6 +783,12 @@ fi
 rm -f testdata/err.out
 unset GOPATH
 
+TEST 'go test foo_test.go works'
+if ! ./testgo test testdata/standalone_test.go; then
+       echo "go test testdata/standalone_test.go failed"
+       ok=false
+fi
+
 # clean up
 if $started; then stop; fi
 rm -rf testdata/bin testdata/bin1
index 6a499b80e1edfa0d3106f24ee59d9b5411e73d46..e309501f827766e6b57bac273cd11306003cf7b6 100644 (file)
@@ -661,11 +661,14 @@ func (b *builder) test(p *Package) (buildAction, runAction, printAction *action,
                        build: &build.Package{
                                ImportPos: p.build.XTestImportPos,
                        },
-                       imports: append(ximports, ptest),
+                       imports: ximports,
                        pkgdir:  testDir,
                        fake:    true,
                        Stale:   true,
                }
+               if ptest != p {
+                       pxtest.imports = append(pxtest.imports, ptest)
+               }
        }
 
        // Action for building pkg.test.
@@ -675,13 +678,15 @@ func (b *builder) test(p *Package) (buildAction, runAction, printAction *action,
                GoFiles:    []string{"_testmain.go"},
                ImportPath: "testmain",
                Root:       p.Root,
-               imports:    []*Package{ptest},
                build:      &build.Package{Name: "main"},
                pkgdir:     testDir,
                fake:       true,
                Stale:      true,
                omitDWARF:  !testC && !testNeedBinary,
        }
+       if ptest != p {
+               pmain.imports = append(pmain.imports, ptest)
+       }
        if pxtest != nil {
                pmain.imports = append(pmain.imports, pxtest)
        }
diff --git a/src/cmd/go/testdata/standalone_test.go b/src/cmd/go/testdata/standalone_test.go
new file mode 100644 (file)
index 0000000..59cf918
--- /dev/null
@@ -0,0 +1,6 @@
+package standalone_test
+
+import "testing"
+
+func Test(t *testing.T) {
+}