test.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #!/bin/bash
  2. # The script does automatic checking on a Go package and its sub-packages, including:
  3. # 1. gofmt (http://golang.org/cmd/gofmt/)
  4. # 2. goimports (https://github.com/bradfitz/goimports)
  5. # 3. golint (https://github.com/golang/lint)
  6. # 4. go vet (http://golang.org/cmd/vet)
  7. # 5. race detector (http://blog.golang.org/race-detector)
  8. # 6. test coverage (http://blog.golang.org/cover)
  9. set -e
  10. # Automatic checks
  11. # test -z "$(gofmt -s -l . | grep -v Godeps/_workspace/src/ | tee /dev/stderr)"
  12. # go vet ./pkg/...
  13. # godep go test -v -race ./pkg/...
  14. echo "mode: count" > profile.cov
  15. # Standard go tooling behavior is to ignore dirs with leading underscors
  16. for dir in $(find ./pkg/ -maxdepth 4 -type d);
  17. do
  18. if ls $dir/*.go &> /dev/null; then
  19. godep go test -covermode=count -coverprofile=$dir/profile.tmp $dir
  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
  27. go tool cover -func profile.cov
  28. # To submit the test coverage result to coveralls.io,
  29. # use goveralls (https://github.com/mattn/goveralls)
  30. # goveralls -coverprofile=profile.cov -service=travis-ci