소스 검색

test, travis: integrate gosimple and unused

Gyu-Ho Lee 9 년 전
부모
커밋
9aec045fce
2개의 변경된 파일48개의 추가작업 그리고 9개의 파일을 삭제
  1. 2 0
      .travis.yml
  2. 46 9
      test

+ 2 - 0
.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:

+ 46 - 9
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..."