about summary refs log tree commit diff stats
path: root/awk/rawk/tests/test_runner.sh
blob: d0b316d041acf6a08bb65d4c7f84665e441bd169 (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
#!/bin/bash

echo "a rawking test runner"
echo "=================================="

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color

# Test counter
PASSED=0
FAILED=0
TOTAL=0

# Function to run a test
run_test() {
    local test_file="$1"
    local test_name="$2"
    
    echo -n "Testing $test_name... "
    
    # Step 1: Compile
    awk -f ../rawk.awk "$test_file" > temp_output.awk
    
    # Step 2: Run with input
    output=$(echo "test input" | awk -f temp_output.awk 2>&1)
    exit_code=$?
    
    if [ $exit_code -eq 0 ]; then
        echo -e "${GREEN}✓ PASS${NC}"
        ((PASSED++))
    else
        echo -e "${RED}✗ FAIL${NC}"
        echo "   Output: $output"
        ((FAILED++))
    fi
    
    ((TOTAL++))
    rm -f temp_output.awk
}

# Function to run an error test (should fail)
run_error_test() {
    local test_file="$1"
    local test_name="$2"
    
    echo -n "Testing $test_name (should fail)... "
    
    output=$(awk -f ../rawk.awk "$test_file" 2>&1)
    exit_code=$?
    
    if [ $exit_code -ne 0 ]; then
        echo -e "${GREEN}✓ PASS (correctly failed)${NC}"
        ((PASSED++))
    else
        echo -e "${RED}✗ FAIL (should have failed)${NC}"
        echo "   Output: $output"
        ((FAILED++))
    fi
    
    ((TOTAL++))
}

# Run all tests
echo ""
echo "Running basic functionality tests..."
run_test "test_basic.rawk" "Basic Functionality"

echo ""
echo "Running simple standard library tests..."
run_test "simple_stdlib_test.rawk" "Simple Standard Library"

echo ""
echo "Running full standard library tests..."
run_test "test_stdlib.rawk" "Full Standard Library"

echo ""
echo "Running functional programming tests..."
run_test "test_functional.rawk" "Functional Programming"

echo ""
echo "Running error handling tests..."
run_error_test "test_errors.rawk" "Error Handling"

# Summary
echo ""
echo "=================================="
echo "Test Summary:"
echo "   Total tests: $TOTAL"
echo -e "   ${GREEN}Passed: $PASSED${NC}"
echo -e "   ${RED}Failed: $FAILED${NC}"

if [ $FAILED -eq 0 ]; then
    echo -e "\n${GREEN}All tests passed!${NC}"
    exit 0
else
    echo -e "\n${RED}Some tests failed!${NC}"
    exit 1
fi