#!/bin/bash set -e TESTS_DIR="tests" LIB_DIR="lib" BUILD_DIR="build" # Create build directory mkdir -p "$BUILD_DIR" # Compiler settings CXX="g++" CXXFLAGS="-std=c++20 -Wall -Wextra -O3 -I$LIB_DIR" LDFLAGS="-pthread" # Available tests declare -A TESTS=( ["1"]="test_buffer" ["2"]="test_inet_address" ["3"]="test_utilities" ["4"]="test_core" ["5"]="test_socket" ["6"]="test_tcp_server" ["7"]="test_threading" ) show_menu() { echo "=== Reactor Library Test Runner ===" echo "1) Buffer Tests" echo "2) InetAddress Tests" echo "3) Utilities Tests" echo "4) Core Tests" echo "5) Socket Tests" echo "6) TCP Server Tests" echo "7) Threading Tests" echo "8) Run All Tests" echo "9) Exit" echo -n "Select test suite [1-9]: " } compile_and_run() { local test_name="$1" local source_file="$TESTS_DIR/${test_name}.cpp" local binary_file="$BUILD_DIR/$test_name" if [[ ! -f "$source_file" ]]; then echo "Error: $source_file not found" return 1 fi echo "Compiling $test_name..." if ! $CXX $CXXFLAGS "$source_file" -o "$binary_file" $LDFLAGS; then echo "Compilation failed for $test_name" return 1 fi echo "Running $test_name..." echo "----------------------------------------" if ! "$binary_file"; then echo "Test $test_name failed!" return 1 fi echo "----------------------------------------" echo "$test_name completed successfully!" echo } run_all_tests() { local failed_tests=() for i in {1..7}; do test_name="${TESTS[$i]}" echo "Running test suite $i: $test_name" if ! compile_and_run "$test_name"; then failed_tests+=("$test_name") fi done echo "=== Test Summary ===" if [[ ${#failed_tests[@]} -eq 0 ]]; then echo "All tests passed! ✓" else echo "Failed tests: ${failed_tests[*]}" return 1 fi } main() { while true; do show_menu read -r choice case $choice in [1-7]) test_name="${TESTS[$choice]}" compile_and_run "$test_name" ;; 8) run_all_tests ;; 9) echo "Exiting..." exit 0 ;; *) echo "Invalid choice. Please select 1-9." ;; esac echo -n "Press Enter to continue..." read -r clear done } # Check dependencies if ! command -v g++ &> /dev/null; then echo "Error: g++ not found. Please install g++." exit 1 fi # Check directory structure if [[ ! -d "$TESTS_DIR" ]]; then echo "Error: $TESTS_DIR directory not found" exit 1 fi if [[ ! -d "$LIB_DIR" ]]; then echo "Error: $LIB_DIR directory not found" exit 1 fi clear main