merge-coverprofile.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright © 2016 Couchbase, Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // +build ignore
  15. package main
  16. import (
  17. "bufio"
  18. "fmt"
  19. "os"
  20. "strconv"
  21. "strings"
  22. )
  23. func main() {
  24. modeline := ""
  25. blocks := map[string]int{}
  26. scanner := bufio.NewScanner(os.Stdin)
  27. for scanner.Scan() {
  28. line := scanner.Text()
  29. if !strings.HasPrefix(line, "mode:") {
  30. lastSpace := strings.LastIndex(line, " ")
  31. prefix := line[0:lastSpace]
  32. suffix := line[lastSpace+1:]
  33. count, err := strconv.Atoi(suffix)
  34. if err != nil {
  35. fmt.Printf("error parsing count: %v", err)
  36. continue
  37. }
  38. existingCount, exists := blocks[prefix]
  39. if exists {
  40. blocks[prefix] = existingCount + count
  41. } else {
  42. blocks[prefix] = count
  43. }
  44. } else if modeline == "" {
  45. modeline = line
  46. }
  47. }
  48. if err := scanner.Err(); err != nil {
  49. fmt.Fprintln(os.Stderr, "reading standard input:", err)
  50. }
  51. fmt.Println(modeline)
  52. for k, v := range blocks {
  53. fmt.Printf("%s %d\n", k, v)
  54. }
  55. }