#!/bin/bash # Baba Yaga C Implementation - Comprehensive Test Runner # This script runs the same test suite used by the JavaScript implementation set -e # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Configuration BABA_YAGA_BIN="./bin/baba-yaga" TESTS_DIR="./tests" TEMP_DIR="./temp_test_output" RESULTS_FILE="./test_results.txt" # Test categories (matching JavaScript implementation) UNIT_TESTS=( "01_lexer_basic.txt" "02_arithmetic_operations.txt" "03_comparison_operators.txt" "04_logical_operators.txt" "05_io_operations.txt" "06_function_definitions.txt" "07_case_expressions.txt" "08_first_class_functions.txt" "09_tables.txt" "10_standard_library.txt" "11_edge_cases.txt" "12_advanced_tables.txt" "13_standard_library_complete.txt" "14_error_handling.txt" "15_performance_stress.txt" "16_function_composition.txt" "17_table_enhancements.txt" "18_each_combinator.txt" "19_embedded_functions.txt" "20_via_operator.txt" "21_enhanced_case_statements.txt" "22_parser_limitations.txt" "23_minus_operator_spacing.txt" ) INTEGRATION_TESTS=( "integration_01_basic_features.txt" "integration_02_pattern_matching.txt" "integration_03_functional_programming.txt" "integration_04_mini_case_multi_param.txt" ) # Statistics total_tests=0 passed_tests=0 failed_tests=0 skipped_tests=0 # Function to print header print_header() { echo -e "${BLUE}========================================${NC}" echo -e "${BLUE} Baba Yaga C Implementation Test Suite${NC}" echo -e "${BLUE}========================================${NC}" echo "" } # Function to print section header print_section() { echo -e "${YELLOW}$1${NC}" echo -e "${YELLOW}$(printf '=%.0s' {1..${#1}})${NC}" echo "" } # Function to run a single test run_test() { local test_file="$1" local test_name="${test_file%.txt}" local test_path="$TESTS_DIR/$test_file" local output_file="$TEMP_DIR/${test_name}.out" local error_file="$TEMP_DIR/${test_name}.err" total_tests=$((total_tests + 1)) echo -n "Testing $test_name... " # Check if test file exists if [ ! -f "$test_path" ]; then echo -e "${RED}SKIP (file not found)${NC}" skipped_tests=$((skipped_tests + 1)) return fi # Run the test if $BABA_YAGA_BIN "$test_path" > "$output_file" 2> "$error_file"; then # Check if there were any errors in stderr if [ -s "$error_file" ]; then echo -e "${RED}FAIL (runtime errors)${NC}" echo " Error output:" cat "$error_file" | sed 's/^/ /' failed_tests=$((failed_tests + 1)) else echo -e "${GREEN}PASS${NC}" passed_tests=$((passed_tests + 1)) fi else echo -e "${RED}FAIL (execution failed)${NC}" if [ -s "$error_file" ]; then echo " Error output:" cat "$error_file" | sed 's/^/ /' fi failed_tests=$((failed_tests + 1)) fi } # Function to run test category run_test_category() { local category_name="$1" shift local tests=("$@") print_section "$category_name" for test_file in "${tests[@]}"; do run_test "$test_file" done echo "" } # Function to print summary print_summary() { echo -e "${BLUE}========================================${NC}" echo -e "${BLUE} Test Summary${NC}" echo -e "${BLUE}========================================${NC}" echo "" echo -e "Total tests: $total_tests" echo -e "${GREEN}Passed: $passed_tests${NC}" echo -e "${RED}Failed: $failed_tests${NC}" if [ $skipped_tests -gt 0 ]; then echo -e "${YELLOW}Skipped: $skipped_tests${NC}" fi if [ $failed_tests -eq 0 ]; then echo -e "${GREEN}All tests passed! 🎉${NC}" exit 0 else echo -e "${RED}Some tests failed.${NC}" exit 1 fi } # Function to cleanup cleanup() { if [ -d "$TEMP_DIR" ]; then rm -rf "$TEMP_DIR" fi } # Main execution main() { # Setup print_header # Check if baba-yaga binary exists if [ ! -f "$BABA_YAGA_BIN" ]; then echo -e "${RED}Error: $BABA_YAGA_BIN not found. Please build the project first.${NC}" exit 1 fi # Check if tests directory exists if [ ! -d "$TESTS_DIR" ]; then echo -e "${RED}Error: Tests directory $TESTS_DIR not found.${NC}" exit 1 fi # Create temp directory mkdir -p "$TEMP_DIR" # Run tests run_test_category "Unit Tests" "${UNIT_TESTS[@]}" run_test_category "Integration Tests" "${INTEGRATION_TESTS[@]}" # Print summary print_summary } # Set up cleanup on exit trap cleanup EXIT # Run main function main "$@"