#!/bin/bash # Test Runner for rawk # Usage: ./run_tests.sh set -e # Exit on any error # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Test counters TOTAL_TESTS=0 PASSED_TESTS=0 FAILED_TESTS=0 SKIPPED_TESTS=0 echo -e "${BLUE}๐Ÿงช rawk Test Suite Runner${NC}" echo "==========================" echo "" # Function to run a test and capture results run_test() { local test_file="$1" local category="$2" local test_name=$(basename "$test_file" .rawk) echo -e "${BLUE}Testing ${category}: ${test_name}${NC}" echo "----------------------------------------" # Check if test file exists if [ ! -f "$test_file" ]; then echo -e "${YELLOW}SKIP: Test file not found${NC}" ((SKIPPED_TESTS++)) echo "" return 0 fi # Run the test if output=$(awk -f ../rawk.awk "$test_file" 2>&1 | awk -f - 2>&1); then echo "$output" # Count test results local pass_count=$(echo "$output" | grep -c "โœ“" || true) local fail_count=$(echo "$output" | grep -c "โŒ" || true) local warn_count=$(echo "$output" | grep -c "โš ๏ธ" || true) if [ "$fail_count" -gt 0 ]; then echo -e "${RED}FAIL: ${fail_count} test(s) failed${NC}" ((FAILED_TESTS++)) elif [ "$pass_count" -gt 0 ]; then echo -e "${GREEN}PASS: ${pass_count} test(s) passed${NC}" ((PASSED_TESTS++)) else echo -e "${YELLOW}UNKNOWN: No clear test results${NC}" ((PASSED_TESTS++)) # Assume success if no clear failure fi else echo -e "${RED}ERROR: Test execution failed${NC}" echo "Error output:" awk -f ../rawk.awk "$test_file" 2>&1 | awk -f - 2>&1 | head -5 | sed 's/^/ /' ((FAILED_TESTS++)) fi ((TOTAL_TESTS++)) echo "" } # Function to run tests in a directory run_test_category() { local category="$1" local test_files="$2" echo -e "${BLUE}๐Ÿ“‹ ${category}${NC}" echo "=========================" for test_file in $test_files; do run_test "$test_file" "$category" done } # Core language feature tests run_test_category "Core Language Features" " core/test_basic.rawk core/test_basic_functions.rawk core/test_multiline.rawk core/test_recursive.rawk core/test_suite.rawk core/test_array_fix.rawk core/test_edge_cases.rawk core/test_failure.rawk " # Standard library tests run_test_category "Standard Library" " stdlib/test_predicates.rawk stdlib/test_predicates_simple.rawk stdlib/test_stdlib_simple.rawk stdlib/test_functional.rawk stdlib/test_enhanced_utilities_simple.rawk stdlib/test_phase2_utilities.rawk " # Real world example tests run_test_category "Real World Examples" " real_world/test_csv_processor.rawk real_world/test_data_processing.rawk real_world/test_log_parser.rawk real_world/test_mixed.rawk real_world/test_system_monitor.rawk " # Summary echo -e "${BLUE}๐Ÿ“Š Test Summary${NC}" echo "===============" echo "Total Tests Run: $TOTAL_TESTS" echo -e "Passed: ${GREEN}$PASSED_TESTS${NC}" echo -e "Failed: ${RED}$FAILED_TESTS${NC}" echo -e "Skipped: ${YELLOW}$SKIPPED_TESTS${NC}" if [ "$FAILED_TESTS" -eq 0 ]; then echo "" echo -e "${GREEN}๐ŸŽ‰ All tests passed! rawk is working correctly.${NC}" exit 0 else echo "" echo -e "${RED}โŒ Some tests failed. Please check the output above.${NC}" exit 1 fi