...
 
Commits (2)
# Example of sourced file.
# shellcheck disable=SC2148
export CONF_LOGFILE='/tmp/shellscripts.log'
......
# Example of a sourced file.
# shellcheck disable=SC2148
debug() {
echo "DEBUG: $1" |
......
#!/bin/sh
# ShellCheck and, if present, unit test all executable examples.
OLDPWD=$(pwd)
dir="$(dirname "$(readlink -f "$0")")/.."
RV=0
at_exit() {
if ! cd "$OLDPWD" ; then
echo "Warning: at_exit(): \"cd $OLDPWD\" failed."
fi
if test "$RV" = "0" ; then
echo "Info: at_exit(): All test sucessful."
else
echo "Warning: at_exit(): One or more tests failed."
fi
}
trap at_exit EXIT
if ! cd "$dir" ; then
echo "Error: \"cd $dir\" failed.." >&2
exit 1
fi
for script in [0-9]*/[0-9]*sh ; do
if grep -q "^# syntastic=off$" "$script" ; then
echo "Warning: Skipping Shellcheck of \"$script\"." >&2
elif ! shellcheck "$script" ; then
echo "Error: ShellCheck of \"$script\" failed." >&2
RV=1
fi
case "$script" in
*.inc.*)
echo "Info: Skipping include file \"$script\"." >&2
;;
*.bash|*.sh)
if ! test -x "$script" ; then
echo "Info: Skipping non-executable \"$script\"." >&2
fi
testscript="tests/$script.t.sh"
if test -f "$testscript" && test -x "$testscript" ; then
if ! "$testscript" "$script" ; then
echo "Error: Unit test of \"$script\" failed." >&2
RV=1
fi
fi
;;
esac
done
exit $RV