#!/bin/bash # Shared Test Runner for Baba Yaga Language # Works with both JS and C implementations # Usage: ./run_shared_tests.sh [test_category] echo "=== Baba Yaga Shared Test Suite ===" echo "" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Check implementation argument if [ $# -lt 1 ]; then echo "Usage: $0 [unit|integration|turing|all]" echo " js - Run tests with JavaScript implementation" echo " c - Run tests with C implementation" echo " Categories: unit, integration, turing, all (default: all)" exit 1 fi IMPL=$1 CATEGORY=${2:-all} # Set up execution command based on implementation case $IMPL in "js") if [ ! -f "js/lang.js" ]; then echo -e "${RED}Error: JavaScript implementation not found at js/lang.js${NC}" exit 1 fi EXEC_CMD="bun js/lang.js" echo "Using JavaScript implementation (bun js/lang.js)" ;; "c") if [ ! -f "c/bin/baba-yaga" ]; then echo -e "${RED}Error: C implementation not found at c/bin/baba-yaga${NC}" echo "Please build the C implementation first: cd c && make" exit 1 fi EXEC_CMD="c/bin/baba-yaga" echo "Using C implementation (c/bin/baba-yaga)" ;; *) echo -e "${RED}Error: Invalid implementation '$IMPL'. Use 'js' or 'c'${NC}" exit 1 ;; esac echo "" # Function to run a test file run_test() { local test_file=$1 local test_name=$2 echo -n "Running $test_name... " # Execute the test and capture output local output local exit_code if [ "$IMPL" = "js" ]; then output=$(DEBUG="$DEBUG" $EXEC_CMD "$test_file" 2>&1) else # For C implementation, we need to run the file content output=$($EXEC_CMD -f "$test_file" 2>&1) fi exit_code=$? if [ $exit_code -eq 0 ]; then echo -e "${GREEN}PASS${NC}" # Show debug output if DEBUG is set if [ -n "$DEBUG" ]; then echo "$output" fi return 0 else echo -e "${RED}FAIL${NC}" echo -e "${RED}Error:${NC} $output" return 1 fi } # Counters total_tests=0 passed_tests=0 failed_tests=0 # Run unit tests if [ "$CATEGORY" = "unit" ] || [ "$CATEGORY" = "all" ]; then echo "Running Unit Tests..." echo "====================" # Core unit tests (in order) unit_tests=( "tests/unit/01_lexer_basic.txt:Basic Lexer" "tests/unit/02_arithmetic_operations.txt:Arithmetic Operations" "tests/unit/03_comparison_operators.txt:Comparison Operators" "tests/unit/04_logical_operators.txt:Logical Operators" "tests/unit/05_io_operations.txt:IO Operations" "tests/unit/06_function_definitions.txt:Function Definitions" "tests/unit/07_case_expressions.txt:Case Expressions" "tests/unit/08_first_class_functions.txt:First-Class Functions" "tests/unit/09_tables.txt:Tables" "tests/unit/10_standard_library.txt:Standard Library" "tests/unit/11_edge_cases.txt:Edge Cases" "tests/unit/12_advanced_tables.txt:Advanced Tables" "tests/unit/13_standard_library_complete.txt:Complete Standard Library" "tests/unit/14_error_handling.txt:Error Handling" "tests/unit/15_performance_stress.txt:Performance and Stress" "tests/unit/16_function_composition.txt:Advanced Functional Programming" "tests/unit/17_table_enhancements.txt:Table Enhancements" "tests/unit/18_new_table_operations.txt:New Table Operations" "tests/unit/18_each_combinator.txt:Each Combinator" "tests/unit/19_embedded_functions.txt:Embedded Functions" "tests/unit/20_via_operator.txt:Via Operator" "tests/unit/21_enhanced_case_statements.txt:Enhanced Case Statements" "tests/unit/22_parser_limitations.txt:Parser Limitations" "tests/unit/23_minus_operator_spacing.txt:Minus Operator Spacing" ) for test in "${unit_tests[@]}"; do IFS=':' read -r file name <<< "$test" if [ -f "$file" ]; then total_tests=$((total_tests + 1)) if run_test "$file" "$name"; then passed_tests=$((passed_tests + 1)) else failed_tests=$((failed_tests + 1)) fi fi done echo "" fi # Run integration tests if [ "$CATEGORY" = "integration" ] || [ "$CATEGORY" = "all" ]; then echo "Running Integration Tests..." echo "===========================" integration_tests=( "tests/integration/integration_01_basic_features.txt:Basic Features Integration" "tests/integration/integration_02_pattern_matching.txt:Pattern Matching Integration" "tests/integration/integration_03_functional_programming.txt:Functional Programming Integration" "tests/integration/integration_04_mini_case_multi_param.txt:Multi-parameter Case Expression" ) for test in "${integration_tests[@]}"; do IFS=':' read -r file name <<< "$test" if [ -f "$file" ]; then total_tests=$((total_tests + 1)) if run_test "$file" "$name"; then passed_tests=$((passed_tests + 1)) else failed_tests=$((failed_tests + 1)) fi fi done echo "" fi # Run Turing completeness tests if [ "$CATEGORY" = "turing" ] || [ "$CATEGORY" = "all" ]; then echo "Running Turing Completeness Tests..." echo "===================================" turing_tests=( "tests/turing-completeness/01_basic_proof.txt:Basic Turing Completeness Proof" "tests/turing-completeness/02_recursion_demo.txt:Recursion Demonstrations" "tests/turing-completeness/03_data_demo.txt:Data Structure Demonstrations" "tests/turing-completeness/04_simple_functions.txt:Function Demonstrations" "tests/turing-completeness/05_loops_and_state.txt:Loops and State Management" "tests/turing-completeness/06_lambda_calculus.txt:Lambda Calculus Foundations" "tests/turing-completeness/07_complex_algorithms.txt:Complex Algorithms" ) for test in "${turing_tests[@]}"; do IFS=':' read -r file name <<< "$test" if [ -f "$file" ]; then total_tests=$((total_tests + 1)) if run_test "$file" "$name"; then passed_tests=$((passed_tests + 1)) else failed_tests=$((failed_tests + 1)) fi fi done echo "" fi # Summary echo "=== Test Summary ===" echo "Implementation: $IMPL" echo "Category: $CATEGORY" echo "Total tests: $total_tests" echo -e "Passed: ${GREEN}$passed_tests${NC}" echo -e "Failed: ${RED}$failed_tests${NC}" if [ $failed_tests -eq 0 ]; then echo -e "${GREEN}All tests passed!${NC}" echo -e "${BLUE}✅ Both implementations are consistent!${NC}" exit 0 else echo -e "${RED}Some tests failed.${NC}" echo -e "${YELLOW}This indicates differences between implementations.${NC}" exit 1 fi