Files
mgmt/test/test-bashfmt.sh
James Shubin 32b26a09c2 test: Don't error on unbound variable
We would get this error instead of a test error:

	test/util.sh: line 32: GITHUB_ACTION: unbound variable

This would happen when run locally.
2023-12-12 00:00:19 -05:00

41 lines
861 B
Bash
Executable File

#!/bin/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 more than 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'