about summary refs log tree commit diff stats
path: root/awk/rawk/scratch/tests_old/simple_validator.sh
blob: ab6bf2180402dc5b193f658332b74928a5050fa2 (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
#!/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