| 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. test coverage (http://blog.golang.org/cover) |
| 8 |
|
| 9 |
set -e |
| 10 |
|
| 11 |
# Automatic checks |
| 12 |
cd xdr2 |
| 13 |
test -z "$(gofmt -l -w . | tee /dev/stderr)" |
| 14 |
test -z "$(goimports -l -w . | tee /dev/stderr)" |
| 15 |
test -z "$(golint . | tee /dev/stderr)" |
| 16 |
go vet ./... |
| 17 |
env GORACE="halt_on_error=1" go test -v -race ./... |
| 18 |
|
| 19 |
# Run test coverage on each subdirectories and merge the coverage profile. |
| 20 |
|
| 21 |
echo "mode: count" > profile.cov |
| 22 |
|
| 23 |
# Standard go tooling behavior is to ignore dirs with leading underscores. |
| 24 |
for dir in $(find . -maxdepth 10 -not -path './.git*' -not -path '*/_*' -type d); |
| 25 |
do |
| 26 |
if ls $dir/*.go &> /dev/null; then |
| 27 |
go test -covermode=count -coverprofile=$dir/profile.tmp $dir |
| 28 |
if [ -f $dir/profile.tmp ]; then |
| 29 |
cat $dir/profile.tmp | tail -n +2 >> profile.cov |
| 30 |
rm $dir/profile.tmp |
| 31 |
fi |
| 32 |
fi |
| 33 |
done |
| 34 |
|
| 35 |
go tool cover -func profile.cov |
| 36 |
|
| 37 |
# To submit the test coverage result to coveralls.io, |
| 38 |
# use goveralls (https://github.com/mattn/goveralls) |
| 39 |
# goveralls -coverprofile=profile.cov -service=travis-ci |