#!/usr/bin/env bash ############################################################################### # Test Script: Language Symlink Organization ############################################################################### # Tests the language symlink feature in organize-roms.sh # # Test Scenarios: # 1. English build (USA/World excluded from language folders) # 2. All languages build (no exclusions) # 3. Multi-language ROMs get multiple symlinks # 4. Symlinks are relative and portable # 5. On-demand folder creation (no empty language folders) ############################################################################### set -euo pipefail # Get script directory SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" EMUBASEDIR="$(cd "$SCRIPT_DIR/.." && pwd)" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Test counters TESTS_RUN=0 TESTS_PASSED=0 TESTS_FAILED=0 # Test result tracking print_test_result() { local test_name="$1" local result="$2" TESTS_RUN=$((TESTS_RUN + 1)) if [[ "$result" == "PASS" ]]; then echo -e "${GREEN}✓ PASS${NC}: $test_name" TESTS_PASSED=$((TESTS_PASSED + 1)) else echo -e "${RED}✗ FAIL${NC}: $test_name" TESTS_FAILED=$((TESTS_FAILED + 1)) fi } # Setup test environment setup_test_env() { local test_dir="$1" # Clean and create test directory rm -rf "$test_dir" mkdir -p "$test_dir" # Create test ROM files with various region/language combinations cd "$test_dir" # USA games (should stay in root for English builds) touch "Super Mario Bros (USA).nes" touch "The Legend of Zelda (USA) (En).nes" touch "Metroid (USA) (En,Fr).nes" # World games touch "Tetris (World).nes" # Japan games with English touch "Final Fantasy (Japan) (En).nes" touch "Dragon Quest (Japan) (En,Ja).nes" # Europe multi-language games touch "Secret of Mana (Europe) (En,Fr,De,Es).nes" touch "Terranigma (Europe) (En,Fr,De).nes" touch "Suikoden (Europe) (En).nes" # France exclusive touch "Asterix (France) (Fr).nes" # Germany exclusive touch "Das Schwarze Auge (Germany) (De).nes" # Japan exclusive (no English) touch "Mother 3 (Japan) (Ja).nes" # Korea exclusive touch "Starcraft (Korea) (Ko).nes" } # Test 1: English build with USA/World excluded test_english_build_usa_excluded() { echo "" echo -e "${YELLOW}Test 1: English Build (USA/World excluded from language folders)${NC}" echo "========================================================================" local test_dir="/tmp/rom-test-eng-usa-excluded" setup_test_env "$test_dir" # Run organization export KEEP_IN_ROOT_REGIONS="USA,World" export KEEP_IN_ROOT_KINDS="" export ORGANIZE_LANGUAGES_BY_SYMLINK="true" export LANGUAGE_EXCLUDE_REGIONS="USA,World" "$EMUBASEDIR/organizers/organize-roms.sh" "$test_dir" >/dev/null 2>&1 cd "$test_dir" # Check USA games stayed in root [[ -f "Super Mario Bros (USA).nes" ]] && print_test_result "USA game stays in root" "PASS" || print_test_result "USA game stays in root" "FAIL" [[ -f "The Legend of Zelda (USA) (En).nes" ]] && print_test_result "USA English game stays in root" "PASS" || print_test_result "USA English game stays in root" "FAIL" # Check World games stayed in root [[ -f "Tetris (World).nes" ]] && print_test_result "World game stays in root" "PASS" || print_test_result "World game stays in root" "FAIL" # Check USA games NOT in English folder [[ ! -L "By Language/English/Super Mario Bros (USA).nes" ]] && print_test_result "USA game excluded from English folder" "PASS" || print_test_result "USA game excluded from English folder" "FAIL" [[ ! -L "By Language/English/The Legend of Zelda (USA) (En).nes" ]] && print_test_result "USA English game excluded from English folder" "PASS" || print_test_result "USA English game excluded from English folder" "FAIL" # Check Japan games moved to region folder [[ -f "By Region/Japan/Final Fantasy (Japan) (En).nes" ]] && print_test_result "Japan game moved to region folder" "PASS" || print_test_result "Japan game moved to region folder" "FAIL" # Check Japan English games have English symlinks [[ -L "By Language/English/Final Fantasy (Japan) (En).nes" ]] && print_test_result "Japan English game has English symlink" "PASS" || print_test_result "Japan English game has English symlink" "FAIL" # Check Europe multi-language game has multiple symlinks [[ -L "By Language/English/Secret of Mana (Europe) (En,Fr,De,Es).nes" ]] && print_test_result "Europe game has English symlink" "PASS" || print_test_result "Europe game has English symlink" "FAIL" [[ -L "By Language/French/Secret of Mana (Europe) (En,Fr,De,Es).nes" ]] && print_test_result "Europe game has French symlink" "PASS" || print_test_result "Europe game has French symlink" "FAIL" [[ -L "By Language/German/Secret of Mana (Europe) (En,Fr,De,Es).nes" ]] && print_test_result "Europe game has German symlink" "PASS" || print_test_result "Europe game has German symlink" "FAIL" [[ -L "By Language/Spanish/Secret of Mana (Europe) (En,Fr,De,Es).nes" ]] && print_test_result "Europe game has Spanish symlink" "PASS" || print_test_result "Europe game has Spanish symlink" "FAIL" # Check symlinks are relative local symlink_target=$(readlink "By Language/English/Final Fantasy (Japan) (En).nes") [[ "$symlink_target" == ../../* ]] && print_test_result "Symlinks are relative" "PASS" || print_test_result "Symlinks are relative" "FAIL" # Check Japanese and Korean folders were created (from Japan/Korea region games) [[ -d "By Language/Japanese" ]] && print_test_result "Japanese folder created (from Japan region)" "PASS" || print_test_result "Japanese folder created (from Japan region)" "FAIL" [[ -L "By Language/Japanese/Dragon Quest (Japan) (En,Ja).nes" ]] && print_test_result "Japan multi-language game has Japanese symlink" "PASS" || print_test_result "Japan multi-language game has Japanese symlink" "FAIL" [[ -d "By Language/Korean" ]] && print_test_result "Korean folder created (from Korea region)" "PASS" || print_test_result "Korean folder created (from Korea region)" "FAIL" } # Test 2: All languages build (no exclusions) test_all_languages_build() { echo "" echo -e "${YELLOW}Test 2: All Languages Build (no exclusions)${NC}" echo "========================================================================" local test_dir="/tmp/rom-test-all-languages" setup_test_env "$test_dir" # Run organization export KEEP_IN_ROOT_REGIONS="USA,World" export KEEP_IN_ROOT_KINDS="" export ORGANIZE_LANGUAGES_BY_SYMLINK="true" export LANGUAGE_EXCLUDE_REGIONS="" "$EMUBASEDIR/organizers/organize-roms.sh" "$test_dir" >/dev/null 2>&1 cd "$test_dir" # Check USA English games ARE in English folder [[ -L "By Language/English/The Legend of Zelda (USA) (En).nes" ]] && print_test_result "USA English game included in English folder" "PASS" || print_test_result "USA English game included in English folder" "FAIL" # Check USA multi-language game has multiple symlinks [[ -L "By Language/English/Metroid (USA) (En,Fr).nes" ]] && print_test_result "USA game has English symlink" "PASS" || print_test_result "USA game has English symlink" "FAIL" [[ -L "By Language/French/Metroid (USA) (En,Fr).nes" ]] && print_test_result "USA game has French symlink" "PASS" || print_test_result "USA game has French symlink" "FAIL" # Check Japanese folder was created [[ -d "By Language/Japanese" ]] && print_test_result "Japanese folder created" "PASS" || print_test_result "Japanese folder created" "FAIL" [[ -L "By Language/Japanese/Dragon Quest (Japan) (En,Ja).nes" ]] && print_test_result "Japan game has Japanese symlink" "PASS" || print_test_result "Japan game has Japanese symlink" "FAIL" # Check Korean folder was created [[ -d "By Language/Korean" ]] && print_test_result "Korean folder created" "PASS" || print_test_result "Korean folder created" "FAIL" [[ -L "By Language/Korean/Starcraft (Korea) (Ko).nes" ]] && print_test_result "Korea game has Korean symlink" "PASS" || print_test_result "Korea game has Korean symlink" "FAIL" } # Test 3: Language symlinks disabled test_language_symlinks_disabled() { echo "" echo -e "${YELLOW}Test 3: Language Symlinks Disabled${NC}" echo "========================================================================" local test_dir="/tmp/rom-test-no-lang-symlinks" setup_test_env "$test_dir" # Run organization export KEEP_IN_ROOT_REGIONS="USA,World" export KEEP_IN_ROOT_KINDS="" export ORGANIZE_LANGUAGES_BY_SYMLINK="false" export LANGUAGE_EXCLUDE_REGIONS="" "$EMUBASEDIR/organizers/organize-roms.sh" "$test_dir" >/dev/null 2>&1 cd "$test_dir" # Check no language folders were created [[ ! -d "By Language" ]] && print_test_result "No language folders created" "PASS" || print_test_result "No language folders created" "FAIL" # Check region organization still works [[ -f "By Region/Japan/Final Fantasy (Japan) (En).nes" ]] && print_test_result "Region organization works without language symlinks" "PASS" || print_test_result "Region organization works without language symlinks" "FAIL" } # Test 4: On-demand folder creation (no empty language folders) test_ondemand_language_folders() { echo "" echo -e "${YELLOW}Test 4: On-Demand Language Folder Creation${NC}" echo "========================================================================" local test_dir="/tmp/rom-test-ondemand-lang" rm -rf "$test_dir" mkdir -p "$test_dir" cd "$test_dir" # Create only English and French games touch "Game1 (USA) (En).nes" touch "Game2 (Europe) (Fr).nes" # Run organization export KEEP_IN_ROOT_REGIONS="USA" export KEEP_IN_ROOT_KINDS="" export ORGANIZE_LANGUAGES_BY_SYMLINK="true" export LANGUAGE_EXCLUDE_REGIONS="USA" "$EMUBASEDIR/organizers/organize-roms.sh" "$test_dir" >/dev/null 2>&1 cd "$test_dir" # Check only French folder was created (English excluded due to USA) [[ -d "By Language/French" ]] && print_test_result "French folder created" "PASS" || print_test_result "French folder created" "FAIL" [[ ! -d "By Language/German" ]] && print_test_result "German folder NOT created (no German ROMs)" "PASS" || print_test_result "German folder NOT created (no German ROMs)" "FAIL" [[ ! -d "By Language/Spanish" ]] && print_test_result "Spanish folder NOT created (no Spanish ROMs)" "PASS" || print_test_result "Spanish folder NOT created (no Spanish ROMs)" "FAIL" [[ ! -d "By Language/Japanese" ]] && print_test_result "Japanese folder NOT created (no Japanese ROMs)" "PASS" || print_test_result "Japanese folder NOT created (no Japanese ROMs)" "FAIL" } # Test 5: Symlink validation (files are accessible through symlinks) test_symlink_accessibility() { echo "" echo -e "${YELLOW}Test 5: Symlink Accessibility${NC}" echo "========================================================================" local test_dir="/tmp/rom-test-symlink-access" setup_test_env "$test_dir" # Run organization export KEEP_IN_ROOT_REGIONS="USA,World" export KEEP_IN_ROOT_KINDS="" export ORGANIZE_LANGUAGES_BY_SYMLINK="true" export LANGUAGE_EXCLUDE_REGIONS="USA,World" "$EMUBASEDIR/organizers/organize-roms.sh" "$test_dir" >/dev/null 2>&1 cd "$test_dir" # Check symlinks are readable [[ -r "By Language/English/Final Fantasy (Japan) (En).nes" ]] && print_test_result "English symlink is readable" "PASS" || print_test_result "English symlink is readable" "FAIL" [[ -r "By Language/French/Secret of Mana (Europe) (En,Fr,De,Es).nes" ]] && print_test_result "French symlink is readable" "PASS" || print_test_result "French symlink is readable" "FAIL" # Check symlink targets exist local english_target=$(readlink "By Language/English/Final Fantasy (Japan) (En).nes") [[ -f "By Language/English/$english_target" ]] && print_test_result "Symlink target exists" "PASS" || print_test_result "Symlink target exists" "FAIL" } # Main test execution main() { echo "" echo "###############################################################################" echo "# Language Symlink Organization Test Suite" echo "###############################################################################" echo "" # Run all tests test_english_build_usa_excluded test_all_languages_build test_language_symlinks_disabled test_ondemand_language_folders test_symlink_accessibility # Print summary echo "" echo "###############################################################################" echo "# Test Summary" echo "###############################################################################" echo -e "Tests Run: ${TESTS_RUN}" echo -e "Tests Passed: ${GREEN}${TESTS_PASSED}${NC}" echo -e "Tests Failed: ${RED}${TESTS_FAILED}${NC}" echo "" if [[ $TESTS_FAILED -eq 0 ]]; then echo -e "${GREEN}✓ All tests passed!${NC}" exit 0 else echo -e "${RED}✗ Some tests failed${NC}" exit 1 fi } # Run tests main "$@"