diff --git a/tests/syntax_check.sh b/tests/syntax_check.sh new file mode 100644 index 0000000..caf94c7 --- /dev/null +++ b/tests/syntax_check.sh @@ -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" +