github.com/tcnksm/gcli@v0.2.4-0.20170129033839-7eb950507e5a/test.sh (about) 1 #!/bin/bash 2 # This script runs test (`gofmt`, `golint`, `go vet` & `go test`) 3 # If `gofmt` & `golint` has output (means something wrong), 4 # it will exit with non-zero status 5 6 TARGET=$(find . -name "*.go" | grep -v "bindata.go" | grep -v "doc.go") 7 echo -e "----> Run gofmt" 8 FMT_RES=$(gofmt -l ${TARGET}) 9 if [ -n "${FMT_RES}" ]; then 10 echo -e "gofmt failed: \n${FMT_RES}" 11 exit 255 12 fi 13 14 echo -e "----> Run go vet" 15 go list -f '{{.Dir}}' ./... | xargs go tool vet 16 if [ $? -ne 0 ]; then 17 echo -e "go vet failed" 18 exit 255 19 fi 20 21 # TODO, better way to exclude some lint warning. 22 echo -e "----> Run golint" 23 LINT_RES=$(golint ./... | \ 24 grep -v "bindata.go" | \ 25 grep -v "doc.go" | \ 26 grep -v "type name will be used as command.CommandFlag by other packages" | \ 27 grep -v "Framework_go_cmd" | \ 28 grep -v "Framework_codegangsta_cli" | \ 29 grep -v "Framework_mitchellh_cli" | \ 30 grep -v "Framework_flag" \ 31 ) 32 if [ -n "${LINT_RES}" ]; then 33 echo -e "golint failed: \n${LINT_RES}" 34 fi 35 36 echo -e "----> Run go test" 37 go test -v ./...