#!/bin/bash
# Comprehensive test runner for hyperscan-tokio

set -e

echo "====================================="
echo "hyperscan-tokio Comprehensive Testing"
echo "====================================="
echo ""

# Regular tests
echo "1. Running standard tests..."
cargo test --all-features

echo ""
echo "2. Running property-based tests..."
cargo test --test proptest_tests --all-features -- --nocapture

echo ""
echo "3. Running edge case tests..."
cargo test --test edge_case_tests --all-features -- --nocapture

echo ""
echo "4. Running stress tests (this may take a while)..."
cargo test --test stress_tests --all-features -- --nocapture --test-threads=1

# MIRI tests (if available)
if command -v cargo-miri &> /dev/null; then
    echo ""
    echo "5. Running MIRI tests..."
    cd hyperscan-tokio-sys
    cargo +nightly miri test --features miri-test
    cd ..
else
    echo ""
    echo "5. Skipping MIRI tests (cargo-miri not installed)"
fi

# Fuzzing (brief run)
if command -v cargo-fuzz &> /dev/null; then
    echo ""
    echo "6. Running fuzzers (brief test)..."
    cd fuzz
    
    # Run each fuzzer for 30 seconds
    for fuzzer in fuzz_pattern_compile fuzz_scan fuzz_database_serialization; do
        echo "   Running $fuzzer..."
        timeout 30 cargo +nightly fuzz run $fuzzer -- -max_total_time=25 || true
    done
    
    cd ..
else
    echo ""
    echo "6. Skipping fuzzing (cargo-fuzz not installed)"
fi

echo ""
echo "====================================="
echo "Test Summary"
echo "====================================="
echo "✓ Standard tests"
echo "✓ Property-based tests with proptest"
echo "✓ Edge case coverage"
echo "✓ Stress tests for performance and concurrency"
echo "✓ MIRI tests for undefined behavior (if available)"
echo "✓ Fuzzing harnesses (if available)"
echo ""
echo "All tests completed successfully!"
