Add a simple bashfmt test

If someone ever made a bashfmt script, that would be a lovely hack!
This commit is contained in:
James Shubin
2016-02-08 12:06:46 -05:00
parent e342c5a06a
commit 72681349e5
2 changed files with 32 additions and 0 deletions

31
test/test-bashfmt.sh Executable file
View File

@@ -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