1
0
mirror of https://github.com/golang/go synced 2024-11-21 23:14:40 -07:00

remove tracking of cover profile size and raise error using base.Errorf and return

This commit is contained in:
Ryan Currah 2024-09-09 17:07:34 -04:00
parent bf6ed10b91
commit 171ab52698
No known key found for this signature in database
GPG Key ID: A8F5EF04CC2222B3
2 changed files with 9 additions and 15 deletions

View File

@ -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)
}

View File

@ -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{}) {