Files
My-Brain-Is-Full-Crew/tests/run.sh
2026-04-10 17:10:27 +02:00

39 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# =============================================================================
# tests/run.sh — Bash test runner
# =============================================================================
# Discovers all *.test.sh files under tests/ and runs each function whose name
# starts with "test_". Reports pass/fail counts and exits non-zero on failure.
# =============================================================================
set -uo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PASS=0
FAIL=0
FAILED_TESTS=()
while IFS= read -r test_file; do
echo "── $(basename "$test_file") ──────────────────────"
# Source the test file to get its functions
source "$test_file"
# Run every function starting with test_
for fn in $(declare -F | awk '{print $3}' | grep '^test_'); do
if (set -e; "$fn") 2>&1 | sed 's/^/ /'; then
echo "$fn"
PASS=$((PASS + 1))
else
echo "$fn"
FAIL=$((FAIL + 1))
FAILED_TESTS+=("$fn")
fi
unset -f "$fn"
done
done < <(find "$SCRIPT_DIR" -name '*.test.sh' | sort)
echo ""
echo "==========================="
echo " Passed: $PASS"
echo " Failed: $FAIL"
[[ $FAIL -gt 0 ]] && { echo " Failed tests: ${FAILED_TESTS[*]}"; exit 1; }
exit 0