Files
mgmt/test/test-bashfmt.sh
Karpfen 7e8ced534f misc: Use /usr/bin/env for a more generic shebang
Use path based SHELL in Makefiles. It was suggested that this is a
better solution for make for cases when there is no /usr/bin/env.

See: https://github.com/purpleidea/mgmt/pull/694#discussion_r1015596204
2025-03-22 14:53:21 -04:00

41 lines
867 B
Bash
Executable File

#!/usr/bin/env bash
# check for any bash files that aren't properly formatted
# TODO: this is hardly exhaustive
echo running "$0"
set -o errexit
#set -o nounset
set -o pipefail
#ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )" # dir!
ROOT=$(dirname "${BASH_SOURCE}")/..
cd "${ROOT}"
. test/util.sh
M="Makefile"
find_files() {
git ls-files | grep -e '\.sh$' -e '\.bash$' | grep -v 'misc/delta-cpu.sh'
}
bad_files=$(
if grep -q '^ ' "$M"; then
echo "$M"
fi
for i in $(find_files); do
# search for at least one leading space, to ensure we use tabs
if grep -q '^ ' "$i"; then
echo "$i"
fi
# search for files with weird semicolon, then pattern
if grep -q ';''then' "$i"; then
echo "$i"
fi
done
)
if [[ -n "${bad_files}" ]]; then
fail_test "The following bash files are not properly formatted: ${bad_files}"
fi
echo 'PASS'