Commit 4fb0af5d authored by Russ Cox's avatar Russ Cox

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 <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
parent 3716ba03
......@@ -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()
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment