Add tests/syntax_check.sh
This commit is contained in:
@@ -0,0 +1,26 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# Validate Bash syntax for all shell scripts in this repository.
|
||||||
|
#
|
||||||
|
# Usage:
|
||||||
|
# bash tests/syntax_check.sh
|
||||||
|
|
||||||
|
set -Eeuo pipefail
|
||||||
|
|
||||||
|
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||||
|
|
||||||
|
status=0
|
||||||
|
|
||||||
|
while IFS= read -r -d '' script; do
|
||||||
|
printf 'Checking %s\n' "${script#"$ROOT_DIR/"}"
|
||||||
|
if ! bash -n "$script"; then
|
||||||
|
status=1
|
||||||
|
fi
|
||||||
|
done < <(find "$ROOT_DIR" -type f -name '*.sh' -print0 | sort -z)
|
||||||
|
|
||||||
|
if [[ "$status" -eq 0 ]]; then
|
||||||
|
printf 'All Bash files passed syntax validation.\n'
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit "$status"
|
||||||
|
|
||||||
Reference in New Issue
Block a user