Skip to content

Commit 171ab52

Browse files
committed
remove tracking of cover profile size and raise error using base.Errorf and return
1 parent bf6ed10 commit 171ab52

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

src/cmd/go/internal/test/cover.go

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ import (
1919
// across multiple test runs and packages.
2020
var coverMerge struct {
2121
f *os.File
22-
fsize int64 // Tracks the size of valid data written to f
23-
sync.Mutex // for f.Write
22+
sync.Mutex // for f.Write
2423
}
2524

2625
// initCoverProfile initializes the test coverage profile.
@@ -40,16 +39,15 @@ func initCoverProfile() {
4039
if err != nil {
4140
base.Fatalf("%v", err)
4241
}
43-
s, err := fmt.Fprintf(f, "mode: %s\n", cfg.BuildCoverMode)
42+
_, err = fmt.Fprintf(f, "mode: %s\n", cfg.BuildCoverMode)
4443
if err != nil {
4544
base.Fatalf("%v", err)
4645
}
4746
coverMerge.f = f
48-
coverMerge.fsize = int64(s)
4947
}
5048

5149
// mergeCoverProfile merges file into the profile stored in testCoverProfile.
52-
// It prints any errors it encounters to ew.
50+
// Errors encountered are logged and cause a non-zero exit status.
5351
func mergeCoverProfile(file string) {
5452
if coverMerge.f == nil {
5553
return
@@ -71,25 +69,20 @@ func mergeCoverProfile(file string) {
7169
return
7270
}
7371
if err != nil || string(buf) != expect {
74-
base.Errorf("error: test wrote malformed coverage profile %s: header %q, expected %q: %v", file, string(buf), expect, err)
72+
base.Errorf("test wrote malformed coverage profile %s: header %q, expected %q: %v", file, string(buf), expect, err)
7573
return
7674
}
77-
s, err := io.Copy(coverMerge.f, r)
75+
_, err = io.Copy(coverMerge.f, r)
7876
if err != nil {
79-
base.Errorf("error: saving coverage profile: %v", err)
77+
base.Errorf("saving coverage profile: %v", err)
8078
return
8179
}
82-
coverMerge.fsize += s
8380
}
8481

8582
func closeCoverProfile() {
8683
if coverMerge.f == nil {
8784
return
8885
}
89-
// Discard any partially written data from a failed merge.
90-
if err := coverMerge.f.Truncate(coverMerge.fsize); err != nil {
91-
base.Errorf("closing coverage profile: %v", err)
92-
}
9386
if err := coverMerge.f.Close(); err != nil {
9487
base.Errorf("closing coverage profile: %v", err)
9588
}

src/cmd/go/internal/test/test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2058,11 +2058,12 @@ func (c *runCache) saveOutput(a *work.Action, coverProfileFile string) {
20582058
}
20592059
defer func() {
20602060
if err := coverProfile.Close(); err != nil && cache.DebugTest {
2061-
fmt.Fprintf(os.Stderr, "testcache: %s: closing temporary coverprofile: %v", a.Package.ImportPath, err)
2061+
base.Errorf("closing temporary coverprofile: %v", err)
20622062
}
20632063
}()
20642064
} else if cache.DebugTest {
2065-
fmt.Fprintf(os.Stderr, "testcache: %s: failed to open temporary coverprofile: %s", a.Package.ImportPath, err)
2065+
base.Errorf("failed to open temporary coverprofile: %s", err)
2066+
return
20662067
}
20672068
}
20682069
if c.id1 != (cache.ActionID{}) {

0 commit comments

Comments
 (0)