-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathrun_tests.sh
More file actions
executable file
·141 lines (122 loc) · 3.59 KB
/
run_tests.sh
File metadata and controls
executable file
·141 lines (122 loc) · 3.59 KB
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
#!/bin/bash
# Perry Test Runner
# Runs all test files in test-files/ directory
# Don't exit on first error - we want to run all tests
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
TEST_DIR="$SCRIPT_DIR/test-files"
OUTPUT_DIR="/tmp/perry_tests"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Counters
PASSED=0
FAILED=0
SKIPPED=0
# Create output directory
mkdir -p "$OUTPUT_DIR"
# Tests to skip (known issues or special handling needed)
SKIP_TESTS=(
# Add any tests that need special handling here
)
# Function to check if test should be skipped
should_skip() {
local test_name=$1
for skip in "${SKIP_TESTS[@]}"; do
if [[ "$test_name" == "$skip" ]]; then
return 0
fi
done
return 1
}
echo "========================================"
echo " Perry Test Runner"
echo "========================================"
echo ""
# Build the compiler first
echo "Building compiler..."
cargo build --quiet 2>/dev/null || {
echo -e "${RED}Failed to build compiler${NC}"
exit 1
}
echo -e "${GREEN}Compiler built successfully${NC}"
echo ""
# Track failed tests for summary
declare -a FAILED_TESTS=()
# Run each test
for test_file in "$TEST_DIR"/*.ts; do
test_name=$(basename "$test_file" .ts)
output_file="$OUTPUT_DIR/$test_name"
# Check if test should be skipped
if should_skip "$test_name"; then
echo -e "${YELLOW}SKIP${NC} $test_name"
((SKIPPED++))
continue
fi
# Compile the test (suppress warnings)
if ! cargo run --quiet -- "$test_file" -o "$output_file" 2>/dev/null; then
# Try again to get error message
compile_output=$(cargo run --quiet -- "$test_file" -o "$output_file" 2>&1 | grep -i "error" | head -3)
echo -e "${RED}FAIL${NC} $test_name (compile error)"
if [[ -n "$compile_output" ]]; then
echo " $compile_output"
fi
((FAILED++))
FAILED_TESTS+=("$test_name (compile)")
continue
fi
# Run the test
run_output=$("$output_file" 2>&1)
run_status=$?
if [[ $run_status -ne 0 ]]; then
echo -e "${RED}FAIL${NC} $test_name (runtime error: $run_status)"
echo " Output: $run_output" | head -3
((FAILED++))
FAILED_TESTS+=("$test_name (runtime)")
else
echo -e "${GREEN}PASS${NC} $test_name"
((PASSED++))
fi
done
# Summary
echo ""
echo "========================================"
echo " Test Summary"
echo "========================================"
echo -e "${GREEN}Passed:${NC} $PASSED"
echo -e "${RED}Failed:${NC} $FAILED"
echo -e "${YELLOW}Skipped:${NC} $SKIPPED"
echo "Total: $((PASSED + FAILED + SKIPPED))"
echo ""
# List failed tests
if [[ ${#FAILED_TESTS[@]} -gt 0 ]]; then
echo "Failed tests:"
for failed in "${FAILED_TESTS[@]}"; do
echo " - $failed"
done
fi
# Run regression tests from tests/ directory
echo ""
echo "========================================"
echo " Regression Tests"
echo "========================================"
for test_script in "$SCRIPT_DIR"/tests/test_*.sh; do
[ -f "$test_script" ] || continue
test_name=$(basename "$test_script" .sh)
script_output=$(bash "$test_script" 2>&1)
script_status=$?
if [[ $script_status -eq 0 ]]; then
echo -e "${GREEN}PASS${NC} $test_name"
((PASSED++))
else
echo -e "${RED}FAIL${NC} $test_name"
echo " $script_output" | head -3
((FAILED++))
FAILED_TESTS+=("$test_name (regression)")
fi
done
# Exit with error if any tests failed
if [[ $FAILED -gt 0 ]]; then
exit 1
fi