#!/bin/sh # Simple Test Validator for rawk # This script validates all test files and reports issues echo "🔍 rawk Test Validator" echo "=====================" echo "" # Counters total_files=0 valid_files=0 invalid_files=0 missing_files=0 # Function to validate a single test file validate_test_file() { category=$1 test_file=$2 full_path="$category/$test_file" echo "Validating $category: $test_file" # Check if file exists if [ ! -f "$full_path" ]; then echo " ⚠️ File not found" missing_files=$((missing_files + 1)) return 1 fi # Check for common syntax issues issues=0 # Check for single-line rawk function definitions without semicolons if grep -q '^\$[a-zA-Z_][a-zA-Z0-9_]*[ \t]*=[ \t]*([^)]*)[ \t]*->[^;{]*$' "$full_path"; then echo " ❌ Single-line function definition missing semicolon" grep -n '^\$[a-zA-Z_][a-zA-Z0-9_]*[ \t]*=[ \t]*([^)]*)[ \t]*->[^;{]*$' "$full_path" | head -3 issues=$((issues + 1)) fi # Check for standard AWK function syntax if grep -q '^function[ \t]' "$full_path"; then echo " ⚠️ Standard AWK function syntax detected" grep -n '^function[ \t]' "$full_path" | head -3 issues=$((issues + 1)) fi # Try to compile the file if awk -f ../rawk.awk "$full_path" > /dev/null 2>&1; then if [ $issues -eq 0 ]; then echo " ✓ Valid syntax" valid_files=$((valid_files + 1)) else echo " ⚠️ Compiles but has issues" valid_files=$((valid_files + 1)) fi else echo " ❌ Compilation failed" echo " Compilation output:" awk -f ../rawk.awk "$full_path" 2>&1 | head -5 | sed 's/^/ /' invalid_files=$((invalid_files + 1)) fi echo "" total_files=$((total_files + 1)) } # Core tests echo "📋 Core Language Features" echo "=========================" for test_file in test_basic.rawk test_basic_functions.rawk test_multiline.rawk test_recursive.rawk test_suite.rawk test_array_fix.rawk test_edge_cases.rawk test_failure.rawk; do validate_test_file "core" "$test_file" done echo "📚 Standard Library Tests" echo "=========================" for test_file in test_predicates.rawk test_predicates_simple.rawk test_stdlib_simple.rawk test_functional.rawk test_enhanced_utilities_simple.rawk test_phase2_utilities.rawk; do validate_test_file "stdlib" "$test_file" done echo "🌍 Real World Examples" echo "======================" for test_file in test_csv_processor.rawk test_data_processing.rawk test_log_parser.rawk test_mixed.rawk test_system_monitor.rawk; do validate_test_file "real_world" "$test_file" done # Summary echo "📊 Validation Summary" echo "====================" echo "Total Files Checked: $total_files" echo "Valid Files: $valid_files" echo "Invalid Files: $invalid_files" echo "Missing Files: $missing_files" if [ $invalid_files -eq 0 ] && [ $missing_files -eq 0 ]; then echo "" echo "🎉 All test files are valid!" exit 0 else echo "" echo "❌ Some test files have issues that need to be fixed." echo "" echo "💡 Common fixes:" echo " - Add semicolons to function definitions: \$func = (args) -> expr;" echo " - Use rawk syntax, not standard AWK: \$func = (args) -> { ... }" echo " - Ensure test files exist in correct directories" exit 1 fi