From: Russ Cox Date: Fri, 1 Dec 2017 15:45:49 +0000 (-0500) Subject: cmd/go: fix -x output for test build failure X-Git-Tag: go1.10beta1~67 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=4fb0af5d5391e5e5f8b47f425b5ceb17c3521a72;p=gostls13.git cmd/go: fix -x output for test build failure If the build of the test binary failed, the go command correctly avoided running the binary, but the -x output indicated otherwise. Fixes #22659. Change-Id: Ib4d262bf1735f057c994a45fc23c499d4ebe3246 Reviewed-on: https://go-review.googlesource.com/81495 Run-TryBot: Russ Cox TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go index 9e012ddb16..cf6a9175b0 100644 --- a/src/cmd/go/go_test.go +++ b/src/cmd/go/go_test.go @@ -2469,6 +2469,17 @@ func TestCoverageErrorLine(t *testing.T) { } } +func TestTestBuildFailureOutput(t *testing.T) { + tg := testgo(t) + defer tg.cleanup() + tg.parallel() + tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata")) + + // Doesn't build, -x output should not claim to run test. + tg.runFail("test", "-x", "coverbad") + tg.grepStderrNot(`[\\/]coverbad\.test( |$)`, "claimed to run test") +} + func TestCoverageFunc(t *testing.T) { tg := testgo(t) defer tg.cleanup() diff --git a/src/cmd/go/internal/test/test.go b/src/cmd/go/internal/test/test.go index 419e7270d6..9740b45276 100644 --- a/src/cmd/go/internal/test/test.go +++ b/src/cmd/go/internal/test/test.go @@ -1238,14 +1238,6 @@ func (c *runCache) builderRunTest(b *work.Builder, a *work.Action) error { return nil } - args := str.StringList(work.FindExecCmd(), a.Deps[0].Target, testArgs) - if cfg.BuildN || cfg.BuildX { - b.Showcmd("", "%s", strings.Join(args, " ")) - if cfg.BuildN { - return nil - } - } - if a.Failed { // We were unable to build the binary. a.Failed = false @@ -1255,6 +1247,8 @@ func (c *runCache) builderRunTest(b *work.Builder, a *work.Action) error { return nil } + args := str.StringList(work.FindExecCmd(), a.Deps[0].Target, testArgs) + if testCoverProfile != "" { // Write coverage to temporary profile, for merging later. for i, arg := range args { @@ -1264,6 +1258,13 @@ func (c *runCache) builderRunTest(b *work.Builder, a *work.Action) error { } } + if cfg.BuildN || cfg.BuildX { + b.Showcmd("", "%s", strings.Join(args, " ")) + if cfg.BuildN { + return nil + } + } + cmd := exec.Command(args[0], args[1:]...) cmd.Dir = a.Package.Dir cmd.Env = base.EnvForDir(cmd.Dir, cfg.OrigEnv)