# Test Validation Script for rawk # This script validates that all test files have correct syntax # Usage: awk -f ../rawk.awk validate_tests.rawk | awk -f - BEGIN { print "🔍 rawk Test Validation Suite" print "=============================" print "" # Test categories and their files test_categories["core"] = "Core Language Features" test_files["core"] = "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" test_categories["stdlib"] = "Standard Library" test_files["stdlib"] = "test_predicates.rawk test_predicates_simple.rawk test_stdlib_simple.rawk test_functional.rawk test_enhanced_utilities_simple.rawk test_phase2_utilities.rawk" test_categories["real_world"] = "Real World Examples" test_files["real_world"] = "test_csv_processor.rawk test_data_processing.rawk test_log_parser.rawk test_mixed.rawk test_system_monitor.rawk" # Track results total_files = 0 valid_files = 0 invalid_files = 0 syntax_errors = 0 print "Starting validation..." print "" } # Function to validate a test file $validate_test_file = (category, test_file) -> { print "Validating " category ": " test_file # Check if file exists if (!system("test -f " category "/" test_file)) { # Try to compile the file cmd = "awk -f ../rawk.awk " category "/" test_file " > /dev/null 2>&1" if (system(cmd) == 0) { print " ✓ Syntax OK" return 1 } else { print " ❌ Syntax Error" return 0 } } else { print " ⚠️ File not found" return 0 } }; # Function to check for common syntax issues $check_syntax_issues = (file_path) -> { # Read the file and check for common issues while ((getline line < file_path) > 0) { # Check for rawk function definitions if (line ~ /^\$[a-zA-Z_][a-zA-Z0-9_]*[ \t]*=[ \t]*\([^)]*\)[ \t]*->/) { # Check if it ends with semicolon if (line !~ /;$/) { print " ⚠️ Function definition missing semicolon: " line } } # Check for missing function keywords if (line ~ /^function[ \t]+[a-zA-Z_][a-zA-Z0-9_]*[ \t]*\(/) { print " ⚠️ Standard AWK function syntax detected: " line } } close(file_path) return 1 }; # Main validation loop { # Validate core tests print "📋 Core Language Features" print "=========================" split(test_files["core"], core_test_array, " ") for (i in core_test_array) { if (core_test_array[i] != "") { total_files++ result = validate_test_file("core", core_test_array[i]) if (result) { valid_files++ } else { invalid_files++ } } } print "" print "📚 Standard Library Tests" print "=========================" split(test_files["stdlib"], stdlib_test_array, " ") for (i in stdlib_test_array) { if (stdlib_test_array[i] != "") { total_files++ result = validate_test_file("stdlib", stdlib_test_array[i]) if (result) { valid_files++ } else { invalid_files++ } } } print "" print "🌍 Real World Examples" print "======================" split(test_files["real_world"], real_world_test_array, " ") for (i in real_world_test_array) { if (real_world_test_array[i] != "") { total_files++ result = validate_test_file("real_world", real_world_test_array[i]) if (result) { valid_files++ } else { invalid_files++ } } } } END { print "" print "📊 Validation Summary" print "====================" print "Total Files Checked:", total_files print "Valid Files:", valid_files print "Invalid Files:", invalid_files if (invalid_files == 0) { print "" print "🎉 All test files have valid syntax!" } else { print "" print "❌ Some test files have syntax issues that need to be fixed." print "" print "💡 Common issues to check:" print " - Function definitions should end with semicolon: \$func = (args) -> expr;" print " - Multi-line functions should use braces: \$func = (args) -> { ... }" print " - Check for missing or extra braces" print " - Ensure proper AWK syntax in function bodies" } }