Tweak test, update-fmt, add verify-fmt

Remove verifying gofmt from hack/test.sh.
Make sure hack/update-fmt.sh ignores zz_generated files.
Enable code simplification for gofmt.
Add hack/verify-fmt.sh.

Signed-off-by: Andy Goldstein <andy.goldstein@gmail.com>
pull/157/head
Andy Goldstein 2017-10-26 17:21:06 -04:00
parent 78dc641b15
commit 64632e29f8
3 changed files with 34 additions and 30 deletions

View File

@ -25,31 +25,4 @@ TARGETS=$(for d in "$@"; do echo ./$d/...; done)
echo "Running tests:"
go test -i -installsuffix "static" ${TARGETS}
go test -installsuffix "static" -timeout 60s ${TARGETS}
echo
echo -n "Checking gofmt: "
ERRS=$(find "$@" -type f -name \*.go | xargs gofmt -l 2>&1 || true)
if [ -n "${ERRS}" ]; then
echo "FAIL - the following files need to be gofmt'ed:"
for e in ${ERRS}; do
echo " $e"
done
echo
exit 1
fi
echo "PASS"
echo
# TODO(ncdc): there are govet failures in the generated clientset and the log error location hook
# that prevent us from running vet at this time.
#
# echo -n "Checking go vet: "
# ERRS=$(go vet ${TARGETS} 2>&1 || true)
# if [ -n "${ERRS}" ]; then
# echo "FAIL"
# echo "${ERRS}"
# echo
# exit 1
# fi
# echo "PASS"
# echo
echo "Success!"

View File

@ -18,7 +18,7 @@ HACK_DIR=$(dirname "${BASH_SOURCE}")
echo "Updating formatting"
gofmt -w=true $(find . -type f -name "*.go" -not -path "./vendor/*" -not -path "./pkg/generated/*")
goimports -w=true -d $(find . -type f -name "*.go" -not -path "./vendor/*" -not -path "./pkg/generated/*")
gofmt -w -s $(find . -type f -name "*.go" -not -path "./vendor/*" -not -path "./pkg/generated/*" -not -name "zz_generated*")
goimports -w -d $(find . -type f -name "*.go" -not -path "./vendor/*" -not -path "./pkg/generated/*" -not -name "zz_generated*")
echo "Success!"

31
hack/verify-fmt.sh Executable file
View File

@ -0,0 +1,31 @@
#!/bin/bash -e
#
# Copyright 2017 the Heptio Ark contributors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
HACK_DIR=$(dirname "${BASH_SOURCE}")
echo "Verifying gofmt"
files=$(gofmt -l -s $(find . -type f -name "*.go" -not -path "./vendor/*" -not -path "./pkg/generated/*" -not -name "zz_generated*"))
if [[ -n "${files}" ]]; then
echo "The following files need gofmt updating - please run 'make update'"
echo "${files}"
exit 1
fi
echo "Success!"
echo "Verifying goimports"
goimports -l $(find . -type f -name "*.go" -not -path "./vendor/*" -not -path "./pkg/generated/*" -not -name "zz_generated*")
echo "Success!"