]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: don't try to initialize cover profile for go test -c
authorIan Lance Taylor <iant@golang.org>
Thu, 29 Mar 2018 13:31:38 +0000 (06:31 -0700)
committerIan Lance Taylor <iant@golang.org>
Thu, 29 Mar 2018 16:37:26 +0000 (16:37 +0000)
Using go test -c makes you responsible for managing and merging the
coverage profile yourself.

Fixes #24588

Change-Id: I2037a91ceb904f9f35d76c7b5e5fae6bcbed4e46
Reviewed-on: https://go-review.googlesource.com/103395
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/go/go_test.go
src/cmd/go/internal/test/cover.go

index 6bf826ad5bf185921e88c999fa83ec069d291f10..c4939ed1d9d7c4609ae9a807a7be578758bf9a10 100644 (file)
@@ -2622,6 +2622,17 @@ func TestCoverageFunc(t *testing.T) {
        tg.grepStdoutNot(`\tf\t*[0-9]`, "reported coverage for assembly function f")
 }
 
+// Issue 24588.
+func TestCoverageDashC(t *testing.T) {
+       tg := testgo(t)
+       defer tg.cleanup()
+       tg.parallel()
+       tg.makeTempdir()
+       tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
+       tg.run("test", "-c", "-o", tg.path("coverdep"), "-coverprofile="+tg.path("no/such/dir/cover.out"), "coverdep")
+       tg.wantExecutable(tg.path("coverdep"), "go -test -c -coverprofile did not create executable")
+}
+
 func TestPluginNonMain(t *testing.T) {
        wd, err := os.Getwd()
        if err != nil {
index 12538b4656421562bc20d87fa5c6e47f418ca0de..9841791552dbbc125afa5b3fa4e193a62d4aaad1 100644 (file)
@@ -23,7 +23,7 @@ var coverMerge struct {
 // Using this function clears the profile in case it existed from a previous run,
 // or in case it doesn't exist and the test is going to fail to create it (or not run).
 func initCoverProfile() {
-       if testCoverProfile == "" {
+       if testCoverProfile == "" || testC {
                return
        }
        if !filepath.IsAbs(testCoverProfile) && testOutputDir != "" {