gocoverage.sh 957 B

12345678910111213141516171819202122232425262728293031
  1. #!/bin/bash
  2. set -e
  3. # Add godep workspace to GOPATH. We do it manually instead of using
  4. # 'godep go test' or 'godep restore' so godep doesn't need to be installed.
  5. GOPATH="$PWD/Godeps/_workspace:$GOPATH"
  6. # Install packages before testing. Not doing this would cause
  7. # 'go test' to recompile all package dependencies before testing each package.
  8. go install ./...
  9. # Run test coverage on each subdirectories and merge the coverage profile.
  10. echo "mode: count" > profile.cov
  11. # Standard go tooling behavior is to ignore dirs with leading underscors
  12. for dir in $(find . -maxdepth 10 -not -path './.git*' -not -path '*/_*' -type d);
  13. do
  14. if ls $dir/*.go &> /dev/null; then
  15. # echo $dir
  16. if [[ $dir != "./tests/vm" && $dir != "." ]]
  17. then
  18. go test -covermode=count -coverprofile=$dir/profile.tmp $dir
  19. fi
  20. if [ -f $dir/profile.tmp ]
  21. then
  22. cat $dir/profile.tmp | tail -n +2 >> profile.cov
  23. rm $dir/profile.tmp
  24. fi
  25. fi
  26. done