From 64632e29f8713cb68e7236a93f6b266d0b640f3f Mon Sep 17 00:00:00 2001 From: Andy Goldstein Date: Thu, 26 Oct 2017 17:21:06 -0400 Subject: [PATCH] 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 --- hack/test.sh | 29 +---------------------------- hack/update-fmt.sh | 4 ++-- hack/verify-fmt.sh | 31 +++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 30 deletions(-) create mode 100755 hack/verify-fmt.sh diff --git a/hack/test.sh b/hack/test.sh index a990faad5..7651487cf 100755 --- a/hack/test.sh +++ b/hack/test.sh @@ -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!" diff --git a/hack/update-fmt.sh b/hack/update-fmt.sh index 87fde57a0..3ca053c53 100755 --- a/hack/update-fmt.sh +++ b/hack/update-fmt.sh @@ -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!" diff --git a/hack/verify-fmt.sh b/hack/verify-fmt.sh new file mode 100755 index 000000000..7ae92dbf9 --- /dev/null +++ b/hack/verify-fmt.sh @@ -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!" +