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. gosimple (https://github.com/dominikh/go-simple) 8# 6. unconvert (https://github.com/mdempsky/unconvert) 9# 7. race detector (http://blog.golang.org/race-detector) 10# 8. test coverage (http://blog.golang.org/cover) 11# 12# gometalint (github.com/alecthomas/gometalinter) is used to run each each 13# static checker. 14 15set -ex 16 17# Automatic checks 18test -z "$(gometalinter --disable-all \ 19--enable=gofmt \ 20--enable=goimports \ 21--enable=golint \ 22--enable=vet \ 23--enable=gosimple \ 24--enable=unconvert \ 25--deadline=120s ./... | grep -v 'ExampleNew' 2>&1 | tee /dev/stderr)" 26env GORACE="halt_on_error=1" go test -race ./... 27 28# Run test coverage on each subdirectories and merge the coverage profile. 29 30echo "mode: count" > profile.cov 31 32# Standard go tooling behavior is to ignore dirs with leading underscores. 33for dir in $(find . -maxdepth 10 -not -path './.git*' -not -path '*/_*' -type d); 34do 35if ls $dir/*.go &> /dev/null; then 36 go test -covermode=count -coverprofile=$dir/profile.tmp $dir 37 if [ -f $dir/profile.tmp ]; then 38 cat $dir/profile.tmp | tail -n +2 >> profile.cov 39 rm $dir/profile.tmp 40 fi 41fi 42done 43 44go tool cover -func profile.cov 45 46# To submit the test coverage result to coveralls.io, 47# use goveralls (https://github.com/mattn/goveralls) 48# goveralls -coverprofile=profile.cov -service=travis-ci 49