Skip to content

Commit

Permalink
Simplify saveCoverProfile using bcmills' comment
Browse files Browse the repository at this point in the history
  • Loading branch information
jproberts committed Aug 10, 2022
1 parent 4858e8a commit 3e83a00
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions src/cmd/go/internal/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1854,25 +1854,21 @@ func (c *runCache) saveOutput(a *work.Action, coverprofileFile string) {
if err != nil {
return
}
var coverprof *os.File
saveCoverProfile := func(testID cache.ActionID) {}
if coverprofileFile != "" {
coverprof, err = os.Open(coverprofileFile)
if err != nil && cache.DebugTest {
fmt.Fprintf(os.Stderr, "testcache: %s: failed to open temporary coverprofile: %s", a.Package.ImportPath, err)
}
}
if coverprof != nil {
defer func() {
if err := coverprof.Close(); err != nil && cache.DebugTest {
fmt.Fprintf(os.Stderr, "testcache: %s: closing temporary coverprofile: %v", a.Package.ImportPath, err)
coverprof, err := os.Open(coverprofileFile)
if err == nil {
saveCoverProfile = func(testID cache.ActionID) {
cache.Default().Put(testCoverProfileKey(testID, testInputsID), coverprof)
}
}()
}
saveCoverProfile := func(testID cache.ActionID) {
if coverprof == nil {
return
defer func() {
if err := coverprof.Close(); err != nil && cache.DebugTest {
fmt.Fprintf(os.Stderr, "testcache: %s: closing temporary coverprofile: %v", a.Package.ImportPath, err)
}
}()
} else if cache.DebugTest {
fmt.Fprintf(os.Stderr, "testcache: %s: failed to open temporary coverprofile: %s", a.Package.ImportPath, err)
}
cache.Default().Put(testCoverProfileKey(testID, testInputsID), coverprof)
}
if c.id1 != (cache.ActionID{}) {
if cache.DebugTest {
Expand Down

0 comments on commit 3e83a00

Please sign in to comment.