cmd/go: fix 'go test foo_test.go'

Fixes race build.

TBR=iant
CC=golang-codereviews
https://golang.org/cl/100410044
This commit is contained in:
Russ Cox 2014-05-12 20:45:31 -04:00
parent 26ad5d4ff0
commit 41e5c398d9
3 changed files with 19 additions and 2 deletions

View file

@ -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

View 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)
}

View file

@ -0,0 +1,6 @@
package standalone_test
import "testing"
func Test(t *testing.T) {
}