cover 638 B

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/env bash
  2. #
  3. # Generate coverage HTML for a package
  4. # e.g. PKG=./unit ./cover
  5. #
  6. set -e
  7. if [ -z "$PKG" ]; then
  8. echo "cover only works with a single package, sorry"
  9. exit 255
  10. fi
  11. COVEROUT="coverage"
  12. if ! [ -d "$COVEROUT" ]; then
  13. mkdir "$COVEROUT"
  14. fi
  15. # strip leading dot/slash and trailing slash and sanitize other slashes
  16. # e.g. ./etcdserver/etcdhttp/ ==> etcdserver_etcdhttp
  17. COVERPKG=${PKG/#./}
  18. COVERPKG=${COVERPKG/#\//}
  19. COVERPKG=${COVERPKG/%\//}
  20. COVERPKG=${COVERPKG//\//_}
  21. # generate arg for "go test"
  22. export COVER="-coverprofile ${COVEROUT}/${COVERPKG}.out"
  23. source ./test
  24. go tool cover -html=${COVEROUT}/${COVERPKG}.out