coverage.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/bin/bash
  2. # $Id: coverage.sh 5539 2008-03-30 09:05:39Z wiemann $
  3. # Author: Lea Wiemann <LeWiemann@gmail.com>
  4. # Copyright: This script has been placed in the public domain.
  5. # Usage: ./coverage.sh [project, [module]]
  6. set -e
  7. # Resolve all symlinks in current path.
  8. cd -P .
  9. proj="${PWD##*/}"
  10. if test "$proj" == test; then
  11. cd ..
  12. proj="${PWD##*/}"
  13. fi
  14. if test "$1"; then
  15. proj="$1"
  16. fi
  17. module="${2:-alltests.py}"
  18. module="${module#test/}"
  19. echo "Performing code coverage test for project \"$proj\", test module \"$module\"..."
  20. echo
  21. echo "Please be patient; coverage tracking slows test execution down by more"
  22. echo "than factor 10."
  23. echo
  24. cd test
  25. rm -rf cover
  26. mkdir -p cover
  27. python -u -m trace --count --coverdir=cover --missing "$module"
  28. cd ..
  29. echo
  30. echo
  31. echo Uncovered lines
  32. echo ===============
  33. echo
  34. (
  35. find "$proj/" -name \*.py | while read i; do
  36. i="${i%.py}"
  37. test -f test/cover/"${i//\//.}".cover -o "${i##*/}" == Template || echo "${i//\//.}" "`cat "$i.py" | wc -l`"
  38. done
  39. cd test/cover
  40. find . \( -name . -o ! -name "$proj".\* -exec rm {} \; \)
  41. for i in *.cover; do
  42. sed 's/^>>>>>> \(.*"""\)/ \1/' < "$i" > "${i%.cover}"
  43. rm "$i"
  44. done
  45. for i in *; do echo -n "$i "; grep -c '^>>>>>> ' "$i" || true; done
  46. ) | grep -v ' 0$' | sort -nk 2