]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: fix -x output for test build failure
authorRuss Cox <rsc@golang.org>
Fri, 1 Dec 2017 15:45:49 +0000 (10:45 -0500)
committerRuss Cox <rsc@golang.org>
Fri, 1 Dec 2017 19:47:30 +0000 (19:47 +0000)
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 <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/go/go_test.go
src/cmd/go/internal/test/test.go

index 9e012ddb168ce0ce8b3ad0ae7a8fd76b907ca9a6..cf6a9175b0cf05adcb4056405782b92780aeaeef 100644 (file)
@@ -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()
index 419e7270d6d86c26e35b11af2738a64488696ad5..9740b45276e6d4db110ecbc1601b51008b3cb074 100644 (file)
@@ -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)