#!/bin/bash # Test runner script for Readur # This script runs tests in different modes to handle dependencies echo "๐Ÿงช Readur Test Runner" echo "====================" # Function to run tests with specific configuration run_tests() { local mode="$1" local flags="$2" local description="$3" echo "" echo "๐Ÿ“‹ Running $description" echo "Command: cargo test $flags" echo "-------------------------------------------" if cargo test $flags; then echo "โœ… $description: PASSED" else echo "โŒ $description: FAILED" return 1 fi } # Check if Docker is available for integration tests check_docker() { if command -v docker &> /dev/null && docker info &> /dev/null; then echo "๐Ÿณ Docker is available - integration tests can run" return 0 else echo "โš ๏ธ Docker not available - skipping integration tests" return 1 fi } # Main test execution echo "Starting test execution..." # 1. Run unit tests without OCR dependencies (fastest) run_tests "unit" "--lib --no-default-features -- --skip database --skip integration" "Unit tests (no OCR/DB dependencies)" unit_result=$? # 2. Run unit tests with OCR dependencies (requires tesseract) if command -v tesseract &> /dev/null; then echo "๐Ÿ“ท Tesseract OCR available - running OCR tests" run_tests "ocr" "--lib --features ocr -- --skip database --skip integration" "Unit tests with OCR support" ocr_result=$? else echo "โš ๏ธ Tesseract not available - skipping OCR tests" echo " Install with: sudo apt-get install tesseract-ocr tesseract-ocr-eng" ocr_result=0 # Don't fail if tesseract isn't available fi # 3. Run integration tests (requires Docker for PostgreSQL) if check_docker; then run_tests "integration" "--lib --features ocr" "Integration tests (requires Docker/PostgreSQL)" integration_result=$? else integration_result=0 # Don't fail if Docker isn't available fi # Summary echo "" echo "๐Ÿ“Š Test Summary" echo "===============" echo "Unit tests (basic): $([ $unit_result -eq 0 ] && echo "โœ… PASSED" || echo "โŒ FAILED")" echo "Unit tests (with OCR): $([ $ocr_result -eq 0 ] && echo "โœ… PASSED" || echo "โš ๏ธ SKIPPED")" echo "Integration tests: $([ $integration_result -eq 0 ] && echo "โœ… PASSED" || echo "โš ๏ธ SKIPPED")" # Exit with appropriate code if [ $unit_result -eq 0 ]; then echo "" echo "๐ŸŽ‰ Core functionality tests passed!" echo "Your code changes are working correctly." exit 0 else echo "" echo "๐Ÿ’ฅ Some tests failed. Please check the output above." exit 1 fi