#!/bin/bash ################################################################################ # run-tests.sh # Test runner for ROM Organizer unit tests # # Usage: # ./run-tests.sh [test-file] # Run specific test file # ./run-tests.sh # Run all tests ################################################################################ SCRIPT_DIR="$(dirname "$(realpath "$0")")" # Determine the project root directory PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Function to run a single test file run_test_file() { local test_file="$1" local test_name=$(basename "$test_file" .sh) echo -e "\n${BLUE}Running $test_name${NC}" echo "================================================" if bash "$test_file"; then echo -e "${GREEN}$test_name PASSED${NC}" return 0 else echo -e "${RED}$test_name FAILED${NC}" return 1 fi } # Main execution main() { cd "$SCRIPT_DIR" local failed_tests=0 local total_tests=0 if [ $# -eq 1 ]; then # Run specific test file local test_file="$1" if [ ! -f "$test_file" ]; then echo -e "${RED}Error: Test file '$test_file' not found${NC}" exit 1 fi run_test_file "$test_file" exit $? else # Run all test files echo -e "${YELLOW}ROM Organizer Test Suite${NC}" echo "================================================" # Find all test files local test_files=$(find . -name "test-*.sh" -type f | sort) if [ -z "$test_files" ]; then echo -e "${YELLOW}No test files found${NC}" exit 0 fi # Run each test file for test_file in $test_files; do total_tests=$((total_tests + 1)) if ! run_test_file "$test_file"; then failed_tests=$((failed_tests + 1)) fi done # Print final summary echo "" echo "================================================" if [ $failed_tests -eq 0 ]; then echo -e "${GREEN}All test suites passed!${NC} ($total_tests/$total_tests)" else echo -e "${RED}$failed_tests test suite(s) failed.${NC} Passed: $((total_tests - failed_tests))/$total_tests" fi # Exit with failure if any tests failed [ $failed_tests -eq 0 ] fi } main "$@"