diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go index 6bf826ad5b..c4939ed1d9 100644 --- a/src/cmd/go/go_test.go +++ b/src/cmd/go/go_test.go @@ -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 { diff --git a/src/cmd/go/internal/test/cover.go b/src/cmd/go/internal/test/cover.go index 12538b4656..9841791552 100644 --- a/src/cmd/go/internal/test/cover.go +++ b/src/cmd/go/internal/test/cover.go @@ -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 != "" {