in tools/checkcov.go [69:116]
func loadCovOrDie() coverageResult {
f, err := os.Open(*coverageOutputFile)
if err != nil {
fmt.Printf("Error opening coverageOutputFile %q: %v", *coverageOutputFile, err)
os.Exit(2)
}
in, err := io.ReadAll(f)
if err != nil {
fmt.Printf("Error reading coverageOutputFile %q: %v", *coverageOutputFile, err)
os.Exit(2)
}
ret := coverageResult{}
lines := strings.Split(string(in), "\n")
for lineIndex, line := range lines {
fields := strings.Fields(line)
if len(fields) == 0 {
continue
}
packageName := fields[1]
switch fields[0] {
case "?":
ret[packageName] = 0.0
continue
case "ok":
// fallthrough to process the "ok" lines.
default:
continue
}
index := covLine.SubexpIndex("cov")
matches := covLine.FindStringSubmatch(line)
if matches == nil {
fmt.Printf("Error: could not parse line %d: (text was %q)\n", lineIndex+1, line)
os.Exit(2)
}
cov, err := strconv.ParseFloat(matches[index], 32)
if err != nil {
fmt.Printf("Error: could not parse line %d: %v (text was %q)\n", lineIndex+1, err, line)
os.Exit(2)
}
ret[packageName] = cov
}
return ret
}