From 41e5c398d92b271ca78d1770100051e35b233815 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Mon, 12 May 2014 20:45:31 -0400 Subject: [PATCH] cmd/go: fix 'go test foo_test.go' Fixes race build. TBR=iant CC=golang-codereviews https://golang.org/cl/100410044 --- src/cmd/go/test.bash | 6 ++++++ src/cmd/go/test.go | 9 +++++++-- src/cmd/go/testdata/standalone_test.go | 6 ++++++ 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 src/cmd/go/testdata/standalone_test.go diff --git a/src/cmd/go/test.bash b/src/cmd/go/test.bash index 07114fe863..92b6cf5962 100755 --- a/src/cmd/go/test.bash +++ b/src/cmd/go/test.bash @@ -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 diff --git a/src/cmd/go/test.go b/src/cmd/go/test.go index 6a499b80e1..e309501f82 100644 --- a/src/cmd/go/test.go +++ b/src/cmd/go/test.go @@ -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 index 0000000000..59cf918b9b --- /dev/null +++ b/src/cmd/go/testdata/standalone_test.go @@ -0,0 +1,6 @@ +package standalone_test + +import "testing" + +func Test(t *testing.T) { +} -- 2.50.0