#!/bin/bash # Test runner for szecret tests # Runs all test files or specific ones passed as arguments # Each test file runs in its own isolated environment set -euo pipefail this_dir="$(cd "$(dirname "$0")" && pwd)" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' NC='\033[0m' # Find all test files (excluding common.sh and run.sh) find_test_files() { find "${this_dir}" -maxdepth 1 -name '*.sh' -type f \ | xargs -n1 basename \ | grep -Ev '^(common|run)\.sh$' \ | sort } run_test_file() { local test_file="$1" local test_path="${this_dir}/${test_file}" if [[ ! -x "${test_path}" ]]; then chmod +x "${test_path}" fi echo "--- ${test_file%.sh} ---" # Run each test file in its own subprocess with isolated environment if "${test_path}"; then return 0 else return 1 fi } main() { echo "=== szecret test suite ===" echo local test_files=() local failed=0 if [[ $# -gt 0 ]]; then # Run specific test files for arg in "$@"; do # Allow both "list" and "list.sh" local file="${arg%.sh}.sh" if [[ -f "${this_dir}/${file}" ]]; then test_files+=("${file}") else echo "Unknown test file: ${arg}" >&2 exit 1 fi done else # Run all test files while IFS= read -r file; do test_files+=("${file}") done < <(find_test_files) fi for test_file in "${test_files[@]}"; do if ! run_test_file "${test_file}"; then failed=1 fi echo done if [[ ${failed} -eq 0 ]]; then echo -e "${GREEN}=== All tests passed ===${NC}" else echo -e "${RED}=== Some tests failed ===${NC}" exit 1 fi } main "$@"