From 72681349e5246e44bdfeb02ef817083947bcad2a Mon Sep 17 00:00:00 2001 From: James Shubin Date: Mon, 8 Feb 2016 12:06:46 -0500 Subject: [PATCH] Add a simple bashfmt test If someone ever made a bashfmt script, that would be a lovely hack! --- test.sh | 1 + test/test-bashfmt.sh | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100755 test/test-bashfmt.sh diff --git a/test.sh b/test.sh index 45e9773a..2ec70a70 100755 --- a/test.sh +++ b/test.sh @@ -14,6 +14,7 @@ diff <(tail -n +$start AUTHORS | sort) <(tail -n +$start AUTHORS) ./test/test-gofmt.sh ./test/test-yamlfmt.sh +./test/test-bashfmt.sh go test echo running go vet # since it doesn't output an ok message on pass go vet && echo PASS diff --git a/test/test-bashfmt.sh b/test/test-bashfmt.sh new file mode 100755 index 00000000..85528f84 --- /dev/null +++ b/test/test-bashfmt.sh @@ -0,0 +1,31 @@ +#!/bin/bash +# check for any bash files that aren't properly formatted +# TODO: this is hardly exhaustive + +set -o errexit +set -o nounset +set -o pipefail + +ROOT=$(dirname "${BASH_SOURCE}")/.. + +cd "${ROOT}" + +find_files() { + git ls-files | grep -e '\.sh$' -e '\.bash$' +} + +bad_files=$( + for i in $(find_files); do + # search for more than one leading space, to ensure we use tabs + if grep -q '^ ' "$i"; then + echo "$i" + fi + done +) + +if [[ -n "${bad_files}" ]]; then + echo 'FAIL' + echo 'The following bash files are not properly formatted:' + echo "${bad_files}" + exit 1 +fi