From 6ab582a80d329e69fb5c2e61eb72512131e17b4a Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 14 Jul 2015 01:14:08 -0400 Subject: [PATCH] cmd/go: go test -race -i runtime/race must not install race-enabled cmd/cgo Fix now uses same test as 'go build'. Fixes #10500. Change-Id: I2fcf2d95430643370aa29165d89a188988dee446 Reviewed-on: https://go-review.googlesource.com/12174 Reviewed-by: Rob Pike --- src/cmd/go/go_test.go | 17 +++++++++++++++++ src/cmd/go/test.go | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go index 61eecbebad9..59e90b7f603 100644 --- a/src/cmd/go/go_test.go +++ b/src/cmd/go/go_test.go @@ -2077,3 +2077,20 @@ func TestGoInstallPkgdir(t *testing.T) { _, err = os.Stat(filepath.Join(pkg, "runtime.a")) tg.must(err) } + +func TestGoTestRaceInstallCgo(t *testing.T) { + // golang.org/issue/10500. + // This used to install a race-enabled cgo. + tg := testgo(t) + defer tg.cleanup() + tg.run("tool", "-n", "cgo") + cgo := strings.TrimSpace(tg.stdout.String()) + old, err := os.Stat(cgo) + tg.must(err) + tg.run("test", "-race", "-i", "runtime/race") + new, err := os.Stat(cgo) + tg.must(err) + if new.ModTime() != old.ModTime() { + t.Fatalf("go test -i runtime/race reinstalled cmd/cgo") + } +} diff --git a/src/cmd/go/test.go b/src/cmd/go/test.go index 7ea8d53ad17..e62f4bd19d4 100644 --- a/src/cmd/go/test.go +++ b/src/cmd/go/test.go @@ -386,7 +386,7 @@ func runTest(cmd *Command, args []string) { if deps["C"] { delete(deps, "C") deps["runtime/cgo"] = true - if buildContext.GOOS == runtime.GOOS && buildContext.GOARCH == runtime.GOARCH { + if goos == runtime.GOOS && goarch == runtime.GOARCH && !buildRace { deps["cmd/cgo"] = true } }