#!/usr/bin/env bash set -u -o pipefail TEST_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" declare -a shell_files=() declare -a test_files=() failures=0 required_command='' if (( BASH_VERSINFO[0] < 4 || (BASH_VERSINFO[0] == 4 && BASH_VERSINFO[1] < 3) )); then printf 'TA-ProxMenu tests require Bash 4.3 or newer; found %s.\n' \ "$BASH_VERSION" >&2 exit 1 fi for required_command in git python3; do if ! command -v "$required_command" >/dev/null 2>&1; then printf 'TA-ProxMenu tests require %s.\n' "$required_command" >&2 exit 1 fi done while IFS= read -r -d '' file; do shell_files+=("$file") done < <( find "$TEST_ROOT" -type f \( -name '*.sh' -o -name '*.inc' \) \ -not -path '*/.git/*' -print0 | sort -z ) printf 'Bash syntax\n' for file in "${shell_files[@]}"; do if ! bash -n "$file"; then (( failures += 1 )) fi done (( failures == 0 )) && printf ' PASS: %d files\n' "${#shell_files[@]}" printf '\nGit whitespace\n' if git -C "$TEST_ROOT" diff --check && git -C "$TEST_ROOT" diff --cached --check; then printf ' PASS\n' else (( failures += 1 )) fi printf '\nShellCheck\n' if command -v shellcheck >/dev/null 2>&1; then # These rules cannot follow TAPM's runtime-sourced defaults/colors or # functions invoked indirectly through traps and menu dispatch. if shellcheck -x -e SC1091,SC2034,SC2154,SC2317 "${shell_files[@]}"; then printf ' PASS\n' else (( failures += 1 )) fi else printf ' SKIP: shellcheck is not installed\n' fi while IFS= read -r -d '' file; do test_files+=("$file") done < <( find "${TEST_ROOT}/tests" -maxdepth 1 -type f -name 'test-*.sh' \ -print0 | sort -z ) printf '\nBehavior tests\n' for file in "${test_files[@]}"; do printf ' %-30s ' "${file##*/}" if bash "$file"; then : else (( failures += 1 )) fi done printf '\n' if (( failures > 0 )); then printf 'FAILED: %d check group(s) failed.\n' "$failures" >&2 exit 1 fi printf 'All TA-ProxMenu checks passed.\n'