1
0
mirror of https://github.com/gluster/glusterd2.git synced 2026-02-05 12:45:38 +01:00
Files
glusterd2/test/020-test-shellscripts.sh
Michael Adam cf9ce745f8 test: don't use '-x' in shellcheck for now, so that centos-ci can pass
Apparently the centos version of shellcheck is too old to know '-x'.

Signed-off-by: Michael Adam <obnox@redhat.com>
2018-04-24 10:43:47 +02:00

54 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
# Check for shell syntax & style.
test_syntax() {
bash -n "${1}"
}
test_shellcheck() {
if [[ "${SHELLCHECK}" ]]; then
# only look for the "flag" on comment lines
# without this we can match our own code :-)
if grep -q '^#.*HEKETI-SKIP-SHELLCHECK' "${1}"; then
return 0
fi
# Note: Older shellcheck versions do not know '-x'.
# Removing the use of -x for now.
shellcheck -e SC2181,SC2029,SC1091,SC1090,SC2012 "${1}"
else
return 0
fi
}
SHELLCHECK="$(which shellcheck 2>/dev/null)"
SCRIPT_DIR="$(cd "$(dirname "${0}")" && pwd)"
BASE_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
if [[ -z "${SHELLCHECK}" ]]; then
echo "warning: could not find shellcheck ... will skip checks" >&2
fi
cd "${BASE_DIR}" || exit 2
SCRIPTS=$(find . \( -path ./vendor -o -path ./.git -o -path ./build \) -prune \
-o -name '*.sh' -print | sort)
failed=0
for script in ${SCRIPTS}; do
err=0
test_syntax "${script}"
[[ $? -ne 0 ]] && err=1
test_shellcheck "${script}"
[[ $? -ne 0 ]] && err=1
((failed+=err))
if [[ ${err} -ne 0 && ${HEKETI_TEST_EXITFIRST} = "yes" ]]; then
echo "detected issues in ${script}" >&2
exit ${failed}
elif [[ ${err} -ne 0 ]]; then
echo "detected issues in ${script}" >&2
fi
done
exit ${failed}