cover 626 B

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