#!/bin/bash ################################################################################ # test-integration.sh # Integration workflow test for ROM Groomer # Tests the complete end-to-end workflow ################################################################################ # Get the directory of the current script SCRIPT_DIR="$(dirname "$(realpath "$0")")" # Determine the project root directory PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" # Source the test framework source "${SCRIPT_DIR}/test-framework.sh" # Source the script utilities we need for testing source "${PROJECT_ROOT}/core/config.sh" source "${PROJECT_ROOT}/core/logger.sh" source "${PROJECT_ROOT}/core/utils.sh" # Setup test environment setup_test() { TEST_EMU_DIR="$TEST_TEMP_DIR/mock_emu" TEST_SOURCE_DIR="$TEST_EMU_DIR/source/myrient.erista.me/files/No-Intro/Nintendo - Nintendo Entertainment System (Headered)" TEST_FILTER_DIR="$TEST_EMU_DIR/filter" TEST_ORG_DIR="$TEST_EMU_DIR/org" TEST_STAGE_DIR="$TEST_EMU_DIR/stage" TEST_SHARE_DIR="$TEST_EMU_DIR/share" TEST_LISTS_DIR="$TEST_EMU_DIR/lists" TEST_EXTRA_DIR="$TEST_EMU_DIR/source/extra/nes" TEST_ROMORG_DIR="$TEST_EMU_DIR/rom-organizer" TEST_SYSTEMS_DIR="$TEST_ROMORG_DIR/systems" # Create directory structure create_test_dir "$TEST_SOURCE_DIR" create_test_dir "$TEST_FILTER_DIR" create_test_dir "$TEST_ORG_DIR" create_test_dir "$TEST_STAGE_DIR" create_test_dir "$TEST_SHARE_DIR" create_test_dir "$TEST_LISTS_DIR" create_test_dir "$TEST_EXTRA_DIR" create_test_dir "$TEST_SYSTEMS_DIR" # Configure test environment export EMUBASEDIR="$TEST_EMU_DIR" export SOURCEDIR="$TEST_EMU_DIR/source" export FILTERDIR="$TEST_FILTER_DIR" export ORGDIR="$TEST_ORG_DIR" export STAGEDIR="$TEST_STAGE_DIR" export SHAREDIR="$TEST_SHARE_DIR" export LISTSDIR="$TEST_LISTS_DIR" export RETOOL_DAT_DIR="$TEST_TEMP_DIR/retool" export RETOOL_FILTER_DIR="$TEST_TEMP_DIR/retool-filter" export ROMORGANIZER_DIR="$TEST_ROMORG_DIR" export DELETE=false export LINK=false export ORGANIZATION_METHOD="region" export LOG_LEVEL="ERROR" # Create test content create_test_content } # Create test content create_test_content() { # Create sample ROM files create_test_file "$TEST_SOURCE_DIR/Super Mario Bros (USA).nes" create_test_file "$TEST_SOURCE_DIR/The Legend of Zelda (USA).nes" create_test_file "$TEST_SOURCE_DIR/Bad ROM (Europe).nes" create_test_file "$TEST_SOURCE_DIR/Problematic Game (USA).nes" # Create extra content create_test_file "$TEST_EXTRA_DIR/Homebrew Game.nes" # Create lists cat > "$TEST_LISTS_DIR/nes+best-games" << EOF Legend of Zelda (USA).nes EOF cat > "$TEST_LISTS_DIR/nes.homebrew-games" << EOF Homebrew Game.nes EOF cat > "$TEST_LISTS_DIR/nes-problematic-games" << EOF Problematic Game (USA).nes EOF # Create custom system configuration cat > "$TEST_SYSTEMS_DIR/custom-nes.sh" << 'EOF' #!/bin/bash # Custom NES system configuration for testing organize_roms_by_region() { local source_dir="$1" local dest_dir="$2" mkdir -p "$dest_dir/By Region/USA" find "$source_dir" -name "*.nes" | grep "(USA)" | while read -r file; do cp "$file" "$dest_dir/By Region/USA/" done } organize_roms_by_region "$@" EOF chmod +x "$TEST_SYSTEMS_DIR/custom-nes.sh" } # Test complete workflow test_complete_workflow() { echo "Running complete workflow test..." # Step 1: Build script execution simulation local build_dir="$TEST_EMU_DIR/build" create_test_dir "$build_dir" # Copy source files to build directory copy_files "$TEST_SOURCE_DIR" "$build_dir" # Step 2: Filter step simulation local filter_dir="$TEST_FILTER_DIR/usa.1g1r/nes" create_test_dir "$filter_dir" # Copy USA ROMs only find "$build_dir" -name "*.nes" | grep "(USA)" | while read -r file; do cp "$file" "$filter_dir/" done # Step 3: Organization step local org_dir="$TEST_ORG_DIR/usa.1g1r/nes" create_test_dir "$org_dir" # Run organization copy_files "$filter_dir" "$org_dir" # Step 4: Add extra content local extra_dest="$org_dir/By Region/USA" create_test_dir "$extra_dest" # Copy extra games find "$TEST_EXTRA_DIR" -name "*.nes" | while read -r file; do cp "$file" "$org_dir/Homebrew Games/" done # Step 5: Apply lists local best_games_dir="$org_dir/Best Games" create_test_dir "$best_games_dir" # Copy best games if [ -f "$TEST_LISTS_DIR/nes+best-games" ]; then while read -r game; do find "$org_dir" -name "$game" | while read -r file; do cp "$file" "$best_games_dir/" done done < "$TEST_LISTS_DIR/nes+best-games" fi # Step 6: Remove problematic games if [ -f "$TEST_LISTS_DIR/nes-problematic-games" ]; then while read -r game; do find "$org_dir" -name "$game" -delete done < "$TEST_LISTS_DIR/nes-problematic-games" fi # Step 7: Stage step local stage_dir="$TEST_STAGE_DIR/usa.1g1r/nes" create_test_dir "$stage_dir" copy_files "$org_dir" "$stage_dir" # Step 8: Share step local share_dir="$TEST_SHARE_DIR/usa.1g1r/nes" create_test_dir "$share_dir" copy_files "$stage_dir" "$share_dir" # Verify final result assert_file_exists "$share_dir/Super Mario Bros (USA).nes" "Super Mario Bros should exist in final result" assert_file_exists "$share_dir/The Legend of Zelda (USA).nes" "Legend of Zelda should exist in final result" assert_file_not_exists "$share_dir/Bad ROM (Europe).nes" "European ROM should be filtered out" assert_file_not_exists "$share_dir/Problematic Game (USA).nes" "Problematic game should be removed" } # Main test runner main() { echo "Running integration tests..." run_tests } # Run tests if this script is executed directly if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then main "$@" fi