gocoverage.sh 959 B

1234567891011121314151617181920212223242526272829303132
  1. #!/bin/bash
  2. # The script does automatic checking on a Go package and its sub-packages, including:
  3. # 6. test coverage (http://blog.golang.org/cover)
  4. set -e
  5. # Run test coverage on each subdirectories and merge the coverage profile.
  6. echo "mode: count" > profile.cov
  7. # Standard go tooling behavior is to ignore dirs with leading underscors
  8. for dir in $(find . -maxdepth 10 -not -path './.git*' -not -path '*/_*' -type d);
  9. do
  10. if ls $dir/*.go &> /dev/null; then
  11. # echo $dir
  12. if [[ $dir != "./tests/vm" ]]
  13. then
  14. go test -covermode=count -coverprofile=$dir/profile.tmp $dir
  15. fi
  16. if [ -f $dir/profile.tmp ]
  17. then
  18. cat $dir/profile.tmp | tail -n +2 >> profile.cov
  19. rm $dir/profile.tmp
  20. fi
  21. fi
  22. done
  23. go tool cover -func profile.cov
  24. # To submit the test coverage result to coveralls.io,
  25. # use goveralls (https://github.com/mattn/goveralls)
  26. goveralls -coverprofile=profile.cov -service=travis-ci -repotoken $COVERALLS_TOKEN