diff --git a/src/cmd/go/internal/test/cover.go b/src/cmd/go/internal/test/cover.go index c5444cc9b49..bc06133efda 100644 --- a/src/cmd/go/internal/test/cover.go +++ b/src/cmd/go/internal/test/cover.go @@ -19,8 +19,7 @@ import ( // across multiple test runs and packages. var coverMerge struct { f *os.File - fsize int64 // Tracks the size of valid data written to f - sync.Mutex // for f.Write + sync.Mutex // for f.Write } // initCoverProfile initializes the test coverage profile. @@ -40,16 +39,15 @@ func initCoverProfile() { if err != nil { base.Fatalf("%v", err) } - s, err := fmt.Fprintf(f, "mode: %s\n", cfg.BuildCoverMode) + _, err = fmt.Fprintf(f, "mode: %s\n", cfg.BuildCoverMode) if err != nil { base.Fatalf("%v", err) } coverMerge.f = f - coverMerge.fsize = int64(s) } // mergeCoverProfile merges file into the profile stored in testCoverProfile. -// It prints any errors it encounters to ew. +// Errors encountered are logged and cause a non-zero exit status. func mergeCoverProfile(file string) { if coverMerge.f == nil { return @@ -71,25 +69,20 @@ func mergeCoverProfile(file string) { return } if err != nil || string(buf) != expect { - base.Errorf("error: test wrote malformed coverage profile %s: header %q, expected %q: %v", file, string(buf), expect, err) + base.Errorf("test wrote malformed coverage profile %s: header %q, expected %q: %v", file, string(buf), expect, err) return } - s, err := io.Copy(coverMerge.f, r) + _, err = io.Copy(coverMerge.f, r) if err != nil { - base.Errorf("error: saving coverage profile: %v", err) + base.Errorf("saving coverage profile: %v", err) return } - coverMerge.fsize += s } func closeCoverProfile() { if coverMerge.f == nil { return } - // Discard any partially written data from a failed merge. - if err := coverMerge.f.Truncate(coverMerge.fsize); err != nil { - base.Errorf("closing coverage profile: %v", err) - } if err := coverMerge.f.Close(); err != nil { base.Errorf("closing coverage profile: %v", err) } diff --git a/src/cmd/go/internal/test/test.go b/src/cmd/go/internal/test/test.go index 7b4390c1ff3..d2ce0225683 100644 --- a/src/cmd/go/internal/test/test.go +++ b/src/cmd/go/internal/test/test.go @@ -2058,11 +2058,12 @@ func (c *runCache) saveOutput(a *work.Action, coverProfileFile string) { } defer func() { if err := coverProfile.Close(); err != nil && cache.DebugTest { - fmt.Fprintf(os.Stderr, "testcache: %s: closing temporary coverprofile: %v", a.Package.ImportPath, err) + base.Errorf("closing temporary coverprofile: %v", err) } }() } else if cache.DebugTest { - fmt.Fprintf(os.Stderr, "testcache: %s: failed to open temporary coverprofile: %s", a.Package.ImportPath, err) + base.Errorf("failed to open temporary coverprofile: %s", err) + return } } if c.id1 != (cache.ActionID{}) {