2015-01-31 05:08:53 +01:00
|
|
|
#!/bin/bash
|
|
|
|
# The script does automatic checking on a Go package and its sub-packages, including:
|
|
|
|
# 1. gofmt (http://golang.org/cmd/gofmt/)
|
2016-05-06 17:47:53 +02:00
|
|
|
# 2. golint (https://github.com/golang/lint)
|
|
|
|
# 3. go vet (http://golang.org/cmd/vet)
|
2016-11-21 16:17:32 +01:00
|
|
|
# 4. gosimple (https://github.com/dominikh/go-simple)
|
|
|
|
# 5. unconvert (https://github.com/mdempsky/unconvert)
|
|
|
|
# 6. race detector (http://blog.golang.org/race-detector)
|
|
|
|
# 7. test coverage (http://blog.golang.org/cover)
|
2016-11-02 23:36:32 +01:00
|
|
|
#
|
2016-11-21 16:17:32 +01:00
|
|
|
# gometalinter (github.com/alecthomas/gometalinter) is used to run each static
|
|
|
|
# checker.
|
2015-01-31 05:08:53 +01:00
|
|
|
|
2015-04-14 21:13:13 +02:00
|
|
|
set -ex
|
2015-01-31 05:08:53 +01:00
|
|
|
|
|
|
|
# Automatic checks
|
2016-11-02 23:36:32 +01:00
|
|
|
test -z "$(gometalinter --disable-all \
|
|
|
|
--enable=gofmt \
|
|
|
|
--enable=golint \
|
|
|
|
--enable=vet \
|
2016-11-03 05:53:07 +01:00
|
|
|
--enable=gosimple \
|
2016-11-03 06:04:28 +01:00
|
|
|
--enable=unconvert \
|
2016-11-21 16:17:32 +01:00
|
|
|
--deadline=4m $(glide novendor) | grep -v 'ALL_CAPS\|OP_' 2>&1 | tee /dev/stderr)"
|
2016-12-07 16:10:06 +01:00
|
|
|
env GORACE="halt_on_error=1" go test -race -tags rpctest $(glide novendor)
|
2015-01-31 05:08:53 +01:00
|
|
|
|
|
|
|
# Run test coverage on each subdirectories and merge the coverage profile.
|
|
|
|
|
2015-04-14 21:13:13 +02:00
|
|
|
set +x
|
2015-01-31 05:08:53 +01:00
|
|
|
echo "mode: count" > profile.cov
|
|
|
|
|
|
|
|
# Standard go tooling behavior is to ignore dirs with leading underscores.
|
2015-02-10 22:54:05 +01:00
|
|
|
for dir in $(find . -maxdepth 10 -not -path '.' -not -path './.git*' \
|
2016-05-06 17:47:53 +02:00
|
|
|
-not -path '*/_*' -not -path './cmd*' -not -path './release*' \
|
|
|
|
-not -path './vendor*' -type d)
|
2015-01-31 05:08:53 +01:00
|
|
|
do
|
|
|
|
if ls $dir/*.go &> /dev/null; then
|
|
|
|
go test -covermode=count -coverprofile=$dir/profile.tmp $dir
|
|
|
|
if [ -f $dir/profile.tmp ]; then
|
|
|
|
cat $dir/profile.tmp | tail -n +2 >> profile.cov
|
|
|
|
rm $dir/profile.tmp
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# To submit the test coverage result to coveralls.io,
|
|
|
|
# use goveralls (https://github.com/mattn/goveralls)
|
|
|
|
# goveralls -coverprofile=profile.cov -service=travis-ci
|