Skip to content

Commit 42144ed

Browse files
committed
remove tracking of cover profile size and raise error using base.Errorf and return
1 parent d5e4022 commit 42144ed

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
@@ -2085,11 +2085,12 @@ func (c *runCache) saveOutput(a *work.Action, coverProfileFile string) {
20852085
}
20862086
defer func() {
20872087
if err := coverProfile.Close(); err != nil && cache.DebugTest {
2088-
fmt.Fprintf(os.Stderr, "testcache: %s: closing temporary coverprofile: %v", a.Package.ImportPath, err)
2088+
base.Errorf("closing temporary coverprofile: %v", err)
20892089
}
20902090
}()
20912091
} else if cache.DebugTest {
2092-
fmt.Fprintf(os.Stderr, "testcache: %s: failed to open temporary coverprofile: %s", a.Package.ImportPath, err)
2092+
base.Errorf("failed to open temporary coverprofile: %s", err)
2093+
return
20932094
}
20942095
}
20952096
if c.id1 != (cache.ActionID{}) {

0 commit comments

Comments
 (0)