From ed941a562b677ed87d750edfc6592cdb7c279586 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 13 Jan 2017 02:42:14 -0500 Subject: Add a tool to generate a full coverage report from the test suite. --- gocovcat.go | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100755 gocovcat.go diff --git a/gocovcat.go b/gocovcat.go new file mode 100755 index 0000000..97ece6f --- /dev/null +++ b/gocovcat.go @@ -0,0 +1,65 @@ +//usr/bin/env go run "$0" "$@"; exit $? + +package main + +import ( + "bufio" + "fmt" + "io" + "os" + "sort" + "strconv" + "strings" +) + +func handleErr(err error) { + if err != nil { + fmt.Fprintf(os.Stderr, "%v\n", err) + os.Exit(1) + } +} + +func main() { + var mode string + blocks := map[string]int{} + for _, filename := range os.Args[1:] { + file, err := os.Open(filename) + handleErr(err) + buf := bufio.NewReader(file) + err = nil + for err != io.EOF { + var line string + line, err = buf.ReadString('\n') + if err == io.EOF { + continue + } + handleErr(err) + line = strings.TrimSuffix(line, "\n") + + if strings.HasPrefix(line, "mode:") { + if mode == "" { + mode = line + } else if mode != line { + fmt.Fprintf(os.Stderr, "mixed modes: %q != %q\n", mode, line) + os.Exit(1) + } + } else { + sp := strings.LastIndexByte(line, ' ') + block := line[:sp] + cntStr := line[sp+1:] + cnt, err := strconv.Atoi(cntStr) + handleErr(err) + blocks[block] += cnt + } + } + } + keys := make([]string, 0, len(blocks)) + for key := range blocks { + keys = append(keys, key) + } + sort.Strings(keys) + fmt.Println(mode) + for _, block := range keys { + fmt.Printf("%s %d\n", block, blocks[block]) + } +} -- cgit v1.2.3-2-g168b