From 9aec045fce0dcd17d4fb05203e77f6bda4b7f44d Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Thu, 7 Apr 2016 22:09:04 -0700 Subject: [PATCH] test, travis: integrate gosimple and unused --- .travis.yml | 2 ++ test | 55 ++++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 48 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6c26bdda5..d7b59bb66 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,6 +22,8 @@ env: before_install: - go get -v github.com/chzchzchz/goword + - go get -v honnef.co/go/simple/cmd/gosimple + - go get -v honnef.co/go/unused/cmd/unused # disable godep restore override install: diff --git a/test b/test index cae7dede5..840267c95 100755 --- a/test +++ b/test @@ -10,6 +10,10 @@ # PKG=snap ./test set -e +# TODO: 'client' pkg fails with gosimple from generated files +# TODO: 'rafttest' is failing with unused +GOSIMPLE_UNUSED_PATHS=$(go list ./... | sed -e 's/github.com\/coreos\/etcd\///g' | grep -vE 'cmd|vendor|rafttest|github.com/coreos/etcd$|client$') + # Invoke ./cover for HTML output COVER=${COVER:-"-cover"} @@ -96,15 +100,48 @@ function fmt_tests { done echo "Checking goword..." - # get all go files to process - gofiles=`find $FMT -iname '*.go' 2>/dev/null` - # ignore tests and protobuf files - gofiles=`echo ${gofiles} | sort | uniq | sed "s/ /\n/g" | egrep -v "(\\_test.go|\\.pb\\.go)"` - # only check for broken exported godocs - gowordRes=`goword -use-spell=false ${gofiles} | grep godoc-export | sort` - if [ ! -z "$gowordRes" ]; then - echo -e "goword checking failed:\n${gowordRes}" - exit 255 + if which goword >/dev/null; then + echo "goword is installed..." + # get all go files to process + gofiles=`find $FMT -iname '*.go' 2>/dev/null` + # ignore tests and protobuf files + gofiles=`echo ${gofiles} | sort | uniq | sed "s/ /\n/g" | egrep -v "(\\_test.go|\\.pb\\.go)"` + # only check for broken exported godocs + gowordRes=`goword -use-spell=false ${gofiles} | grep godoc-export | sort` + if [ ! -z "$gowordRes" ]; then + echo -e "goword checking failed:\n${gowordRes}" + exit 255 + fi + else + echo "gowrod does not exist... skipping..." + fi + + echo "Checking gosimple" + if which gosimple >/dev/null; then + echo "gosimple is installed..." + for path in $GOSIMPLE_UNUSED_PATHS; do + simplResult=$(gosimple $REPO_PATH/${path}) + if [ -n "${simplResult}" ]; then + echo -e "gosimple checking ${path} failed:\n${simplResult}" + exit 255 + fi + done + else + echo "gosimple does not exist... skipping..." + fi + + echo "Checking unused" + if which unused >/dev/null; then + echo "unused is installed..." + for path in $GOSIMPLE_UNUSED_PATHS; do + unusedResult=$(unused $REPO_PATH/${path}) + if [ -n "${unusedResult}" ]; then + echo -e "unused checking ${path} failed:\n${unusedResult}" + exit 255 + fi + done + else + echo "unused does not exist... skipping..." fi echo "Checking for license header..."