/hack/collate.awk

https://github.com/openSUSE/umoci · AWK · 47 lines · 17 code · 4 blank · 26 comment · 5 complexity · 41da769978500a9b9787a814fc51da59 MD5 · raw file

  1. #!/usr/bin/awk -f
  2. # Copyright (C) 2016-2019 SUSE LLC.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. # collate.awk allows you to collate a bunch of Go coverprofiles for a given
  16. # binary (generated with -test.coverprofile), so that the statistics actually
  17. # make sense. The input to this function is just the concatenated versions of
  18. # the coverage reports, and the output is the combined coverage report.
  19. #
  20. # NOTE: This will _only_ work on coverage binaries compiles with
  21. # -covermode=count. The other modes aren't supported.
  22. {
  23. # Every coverage file in the set will start with a "mode:" header. Just make
  24. # sure they're all set to "count".
  25. if ($1 == "mode:") {
  26. if ($0 != "mode: count") {
  27. print "Invalid coverage mode", $2 > "/dev/stderr"
  28. exit 1
  29. }
  30. next
  31. }
  32. # The format of all other lines is as follows.
  33. # <file>:<startline>.<startcol>,<endline>.<endcol> <numstmt> <count>
  34. # We only care about the first field and the count.
  35. statements[$1] = $2
  36. counts[$1] += $3
  37. }
  38. END {
  39. print "mode: count"
  40. for (block in statements) {
  41. print block, statements[block], counts[block]
  42. }
  43. }