coverage.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/bash
  2. set -e
  3. workdir=.cover
  4. profile="$workdir/cover.out"
  5. mode=set
  6. end2endtest="google.golang.org/grpc/test"
  7. generate_cover_data() {
  8. rm -rf "$workdir"
  9. mkdir "$workdir"
  10. for pkg in "$@"; do
  11. if [ $pkg == "google.golang.org/grpc" -o $pkg == "google.golang.org/grpc/transport" -o $pkg == "google.golang.org/grpc/metadata" -o $pkg == "google.golang.org/grpc/credentials" ]
  12. then
  13. f="$workdir/$(echo $pkg | tr / -)"
  14. go test -covermode="$mode" -coverprofile="$f.cover" "$pkg"
  15. go test -covermode="$mode" -coverpkg "$pkg" -coverprofile="$f.e2e.cover" "$end2endtest"
  16. fi
  17. done
  18. echo "mode: $mode" >"$profile"
  19. grep -h -v "^mode:" "$workdir"/*.cover >>"$profile"
  20. }
  21. show_cover_report() {
  22. go tool cover -${1}="$profile"
  23. }
  24. push_to_coveralls() {
  25. goveralls -coverprofile="$profile"
  26. }
  27. generate_cover_data $(go list ./...)
  28. show_cover_report func
  29. case "$1" in
  30. "")
  31. ;;
  32. --html)
  33. show_cover_report html ;;
  34. --coveralls)
  35. push_to_coveralls ;;
  36. *)
  37. echo >&2 "error: invalid option: $1" ;;
  38. esac
  39. rm -rf "$workdir"