test: Improve go vet so that it is less noisy

This commit is contained in:
James Shubin
2017-02-20 17:08:48 -05:00
parent 69b0913315
commit ac142694f5
2 changed files with 27 additions and 5 deletions

View File

@@ -11,7 +11,6 @@ function run-test()
} }
ROOT=$(dirname "${BASH_SOURCE}")/.. ROOT=$(dirname "${BASH_SOURCE}")/..
cd "${ROOT}" cd "${ROOT}"
for pkg in `go list ./... | grep -v 'vendor/' | grep -v 'examples/' | grep -v 'old/' | grep -v 'tmp/'`; do for pkg in `go list ./... | grep -v 'vendor/' | grep -v 'examples/' | grep -v 'old/' | grep -v 'tmp/'`; do

View File

@@ -4,12 +4,35 @@
. test/util.sh . test/util.sh
echo running test-govet.sh echo running test-govet.sh
failures=''
function run-test()
{
$@ || failures=$( [ -n "$failures" ] && echo "$failures\\n$@" || echo "$@" )
}
ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )" # dir! ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )" # dir!
cd "${ROOT}" cd "${ROOT}"
function simplify-gocase() {
grep 'case _ = <-' "$1" && fail_test 'case _ = <- can be simplified to: case <-' # this can be simplified
}
function token-coloncheck() {
grep -Ei "[\/]+[\/]+[ ]*+(FIXME[^:]|TODO[^:]|XXX[^:])" "$1" && fail_test 'Token is missing a colon' # tokens must end with a colon
}
for file in `find . -maxdepth 3 -type f -name '*.go' -not -path './old/*' -not -path './tmp/*'`; do for file in `find . -maxdepth 3 -type f -name '*.go' -not -path './old/*' -not -path './tmp/*'`; do
go vet "$file" && echo PASS || fail_test "go vet did not pass" # since it doesn't output an ok message on pass run-test go vet "$file" || fail_test "go vet did not pass" # since it doesn't output an ok message on pass
grep 'log.' "$file" | grep '\\n"' && fail_test 'no \n needed in log.Printf()' || echo PASS # no \n needed in log.Printf() run-test grep 'log.' "$file" | grep '\\n"' && fail_test 'no newline needed in log.Printf()' # no \n needed in log.Printf()
grep 'case _ = <-' "$file" && fail_test 'case _ = <- can be simplified to: case <-' || echo PASS # this can be simplified run-test simplify-gocase "$file"
grep -Ei "[\/]+[\/]+[ ]*+(FIXME[^:]|TODO[^:]|XXX[^:])" "$file" && fail_test 'Token is missing a colon' || echo PASS # tokens must end with a colon run-test token-coloncheck "$file"
done done
if [[ -n "$failures" ]]; then
echo 'FAIL'
echo 'The following tests have failed:'
echo -e "$failures"
exit 1
fi
echo 'PASS'