]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: run the real test binary if the test link was cached
authorIan Lance Taylor <iant@golang.org>
Fri, 15 Dec 2017 20:38:59 +0000 (12:38 -0800)
committerRuss Cox <rsc@golang.org>
Wed, 10 Jan 2018 16:13:38 +0000 (16:13 +0000)
Fixes #23150

Change-Id: Ia82c2d482a8dc53cabb3f173e4301fee66288821
Reviewed-on: https://go-review.googlesource.com/84376
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
src/cmd/go/go_test.go
src/cmd/go/internal/test/test.go
src/cmd/go/internal/work/action.go

index 83c126e11ecefe23ef674be5ff7cfb7c3a6d363c..42eea06dc205a0f8263f52b8f93486c51028d019 100644 (file)
@@ -5590,3 +5590,24 @@ func init() {}
        tg.run("build", "-o", tg.path("a.exe"), "a")
        tg.run("test", "a")
 }
+
+// Issue 23150.
+func TestCpuprofileTwice(t *testing.T) {
+       tg := testgo(t)
+       defer tg.cleanup()
+       tg.parallel()
+       tg.tempFile("prof/src/x/x_test.go", `
+               package x_test
+               import (
+                       "testing"
+                       "time"
+               )
+               func TestSleep(t *testing.T) { time.Sleep(10 * time.Millisecond) }`)
+       tg.setenv("GOPATH", tg.path("prof"))
+       bin := tg.path("x.test")
+       out := tg.path("cpu.out")
+       tg.run("test", "-o="+bin, "-cpuprofile="+out, "x")
+       tg.must(os.Remove(out))
+       tg.run("test", "-o="+bin, "-cpuprofile="+out, "x")
+       tg.mustExist(out)
+}
index b224d8a46dd98c315d992d32a622a663713b823b..f7f6c64a86ed4ed8adca4c8a9577e563d67cd598 100644 (file)
@@ -1321,7 +1321,7 @@ func (c *runCache) builderRunTest(b *work.Builder, a *work.Action) error {
        if !c.disableCache && len(execCmd) == 0 {
                testlogArg = []string{"-test.testlogfile=" + a.Objdir + "testlog.txt"}
        }
-       args := str.StringList(execCmd, a.Deps[0].Target, testlogArg, testArgs)
+       args := str.StringList(execCmd, a.Deps[0].BuiltTarget(), testlogArg, testArgs)
 
        if testCoverProfile != "" {
                // Write coverage to temporary profile, for merging later.
index 46ba3447c663bfbc768cf8b8697dbc59453ead4b..f75230132367040c6a877dfc268407b469cbb1ec 100644 (file)
@@ -98,6 +98,10 @@ func (a *Action) BuildContentID() string { return contentID(a.buildID) }
 // BuildID returns a's build ID.
 func (a *Action) BuildID() string { return a.buildID }
 
+// BuiltTarget returns the actual file that was built. This differs
+// from Target when the result was cached.
+func (a *Action) BuiltTarget() string { return a.built }
+
 // An actionQueue is a priority queue of actions.
 type actionQueue []*Action