From 81efdbcac4736176ac97c60577b0069f76414c44 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Wed, 29 Sep 2021 20:57:24 +0000 Subject: [PATCH] cover: add function to parse profiles from an io.Reader Fixes golang/go#19404 Change-Id: I893fbb999bb8d0a6c62ab8752790fce75912be0c GitHub-Last-Rev: 101a2f5bd6e2c2e278deafc8238fa4319a697541 GitHub-Pull-Request: golang/tools#331 Reviewed-on: https://go-review.googlesource.com/c/tools/+/336329 Reviewed-by: Bryan C. Mills Trust: Bryan C. Mills Trust: Michael Knyszek --- cover/profile.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cover/profile.go b/cover/profile.go index 57195774ce..47a9a54116 100644 --- a/cover/profile.go +++ b/cover/profile.go @@ -10,6 +10,7 @@ import ( "bufio" "errors" "fmt" + "io" "math" "os" "sort" @@ -45,14 +46,18 @@ func ParseProfiles(fileName string) ([]*Profile, error) { return nil, err } defer pf.Close() + return ParseProfilesFromReader(pf) +} - files := make(map[string]*Profile) - buf := bufio.NewReader(pf) +// ParseProfilesFromReader parses profile data from the Reader and +// returns a Profile for each source file described therein. +func ParseProfilesFromReader(rd io.Reader) ([]*Profile, error) { // First line is "mode: foo", where foo is "set", "count", or "atomic". // Rest of file is in the format // encoding/base64/base64.go:34.44,37.40 3 1 // where the fields are: name.go:line.column,line.column numberOfStatements count - s := bufio.NewScanner(buf) + files := make(map[string]*Profile) + s := bufio.NewScanner(rd) mode := "" for s.Scan() { line := s.Text()