about summary refs log tree commit diff stats
path: root/awk/rawk/scratch/tests_old/validate_tests.rawk
blob: cbccd2d3c074b9ea4b5439562497f5d2b2febcb8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# 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"
    }
}