forked from purpleidea/mgmt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-bashfmt.sh
executable file
·40 lines (34 loc) · 859 Bytes
/
test-bashfmt.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/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 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'