-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_tests.sh
More file actions
270 lines (229 loc) Β· 8.42 KB
/
run_tests.sh
File metadata and controls
270 lines (229 loc) Β· 8.42 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#!/bin/bash
# CoupleScript Test Runner Script
# Runs comprehensive tests for the CoupleScript language
# Colors for romantic output
RED='\033[31m'
GREEN='\033[32m'
YELLOW='\033[33m'
PINK='\033[95m'
CYAN='\033[96m'
RESET='\033[0m'
# Test counters
TOTAL_TESTS=0
PASSED_TESTS=0
FAILED_TESTS=0
SKIPPED_TESTS=0
echo -e "${PINK}π CoupleScript Comprehensive Test Suite π${RESET}"
echo -e "${PINK}=======================================${RESET}"
echo ""
# Function to run a single test
run_test() {
local test_name="$1"
local test_file="$2"
local expected_result="$3" # "pass" or "fail"
TOTAL_TESTS=$((TOTAL_TESTS + 1))
echo -e "π§ͺ Testing: ${CYAN}$test_name${RESET}"
# Check if test file exists
if [[ ! -f "$test_file" ]]; then
echo -e " β οΈ ${YELLOW}SKIPPED${RESET} - Test file not found: $test_file"
SKIPPED_TESTS=$((SKIPPED_TESTS + 1))
return
fi
# Run the test using the CoupleScript interpreter
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then
# Windows
timeout 30 ./couplescript.bat "$test_file" > /dev/null 2>&1
else
# Linux/macOS
timeout 30 ./couplescript "$test_file" > /dev/null 2>&1
fi
local exit_code=$?
# Evaluate result based on expectation
if [[ "$expected_result" == "pass" && $exit_code -eq 0 ]]; then
echo -e " β
${GREEN}PASSED${RESET}"
PASSED_TESTS=$((PASSED_TESTS + 1))
elif [[ "$expected_result" == "fail" && $exit_code -ne 0 ]]; then
echo -e " β
${GREEN}PASSED${RESET} (Expected failure detected)"
PASSED_TESTS=$((PASSED_TESTS + 1))
else
echo -e " β ${RED}FAILED${RESET}"
FAILED_TESTS=$((FAILED_TESTS + 1))
# Show detailed error for debugging
if [[ "$expected_result" == "pass" ]]; then
echo -e " Expected: Success, Got: Failure (exit code $exit_code)"
else
echo -e " Expected: Failure, Got: Success"
fi
fi
echo ""
}
# Function to run compilation tests
test_compilation() {
echo -e "${PINK}π¨ Compilation Tests${RESET}"
echo "Testing if programs compile successfully..."
echo ""
# Test basic examples
run_test "Hello World" "examples/hello.couple" "pass"
run_test "Functions Example" "examples/functions.couple" "pass"
run_test "Calculator Example" "examples/calculator.couple" "pass"
run_test "Loops Example" "examples/loops.couple" "pass"
run_test "Love Story Example" "examples/love_story.couple" "pass"
# Test our comprehensive test files
run_test "Unit Tests" "tests/unit/language_features_test.couple" "pass"
run_test "Integration Tests" "tests/integration/compiler_vm_test.couple" "pass"
}
# Function to test error handling
test_error_handling() {
echo -e "${PINK}π Error Handling Tests${RESET}"
echo "Testing that invalid programs are properly rejected..."
echo ""
# Create temporary error test files
mkdir -p tests/temp
# Syntax error test
echo 'marry incomplete_statement' > tests/temp/syntax_error.couple
run_test "Syntax Error Detection" "tests/temp/syntax_error.couple" "fail"
# Undefined variable test
echo 'remember undefined_variable' > tests/temp/undefined_var.couple
run_test "Undefined Variable Detection" "tests/temp/undefined_var.couple" "fail"
# Invalid function call test
echo 'marry result accept nonexistent_function(5)' > tests/temp/invalid_call.couple
run_test "Invalid Function Call Detection" "tests/temp/invalid_call.couple" "fail"
# Clean up temporary files
rm -rf tests/temp
}
# Function to test performance
test_performance() {
echo -e "${PINK}β‘ Performance Tests${RESET}"
echo "Testing performance with larger programs..."
echo ""
# Create a performance test
mkdir -p tests/temp
cat > tests/temp/performance_test.couple << 'EOF'
# Performance test - calculating many fibonacci numbers
propose fibonacci(n):
argue n <= 1:
promise n
makeup:
promise accept fibonacci(n-1) + accept fibonacci(n-2)
remember "Starting performance test..."
marry i 1
anniversary i <= 20:
marry result accept fibonacci(i)
remember "fibonacci(" + i + ") = " + result
marry i i + 1
remember "Performance test completed!"
EOF
echo "πββοΈ Running performance test (Fibonacci sequence)..."
# Time the execution
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then
# Windows
start_time=$(date +%s)
timeout 60 ./couplescript.bat tests/temp/performance_test.couple > /dev/null 2>&1
exit_code=$?
end_time=$(date +%s)
else
# Linux/macOS
start_time=$(date +%s)
timeout 60 ./couplescript tests/temp/performance_test.couple > /dev/null 2>&1
exit_code=$?
end_time=$(date +%s)
fi
duration=$((end_time - start_time))
if [[ $exit_code -eq 0 ]]; then
echo -e " β
${GREEN}PASSED${RESET} (Completed in ${duration}s)"
PASSED_TESTS=$((PASSED_TESTS + 1))
elif [[ $exit_code -eq 124 ]]; then
echo -e " β° ${YELLOW}TIMEOUT${RESET} (Exceeded 60s limit)"
FAILED_TESTS=$((FAILED_TESTS + 1))
else
echo -e " β ${RED}FAILED${RESET} (Error during execution)"
FAILED_TESTS=$((FAILED_TESTS + 1))
fi
TOTAL_TESTS=$((TOTAL_TESTS + 1))
echo ""
# Clean up
rm -rf tests/temp
}
# Function to test cross-platform compatibility
test_cross_platform() {
echo -e "${PINK}π Cross-Platform Tests${RESET}"
echo "Testing platform-specific functionality..."
echo ""
# Test that the interpreter exists and is executable
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then
if [[ -f "couplescript.bat" ]]; then
echo -e " β
${GREEN}PASSED${RESET} - Windows batch interpreter found"
PASSED_TESTS=$((PASSED_TESTS + 1))
else
echo -e " β ${RED}FAILED${RESET} - Windows batch interpreter not found"
FAILED_TESTS=$((FAILED_TESTS + 1))
fi
else
if [[ -x "couplescript" ]]; then
echo -e " β
${GREEN}PASSED${RESET} - Unix interpreter found and executable"
PASSED_TESTS=$((PASSED_TESTS + 1))
else
echo -e " β ${RED}FAILED${RESET} - Unix interpreter not found or not executable"
FAILED_TESTS=$((FAILED_TESTS + 1))
fi
fi
TOTAL_TESTS=$((TOTAL_TESTS + 1))
echo ""
}
# Function to show final results
show_results() {
echo -e "${PINK}π Test Results Summary π${RESET}"
echo -e "${PINK}=========================${RESET}"
echo ""
echo "Total tests run: $TOTAL_TESTS"
echo -e "${GREEN}Passed: $PASSED_TESTS${RESET}"
echo -e "${RED}Failed: $FAILED_TESTS${RESET}"
echo -e "${YELLOW}Skipped: $SKIPPED_TESTS${RESET}"
echo ""
if [[ $TOTAL_TESTS -gt 0 ]]; then
SUCCESS_RATE=$(( (PASSED_TESTS * 100) / TOTAL_TESTS ))
echo "Success rate: $SUCCESS_RATE%"
echo ""
fi
if [[ $FAILED_TESTS -eq 0 ]]; then
echo -e "${GREEN}π All tests passed! Love is in the air! π${RESET}"
exit 0
else
echo -e "${RED}π Some tests failed. Every relationship needs work!${RESET}"
echo ""
echo "Tips for fixing issues:"
echo "1. Check that CoupleScript is properly built (run 'make all')"
echo "2. Verify all dependencies are installed"
echo "3. Check the detailed error messages above"
echo "4. Try running individual test files manually"
exit 1
fi
}
# Main test execution
main() {
# Check if we're in the right directory
if [[ ! -f "Makefile" || ! -d "examples" ]]; then
echo -e "${RED}β Error: Please run this script from the CoupleScript root directory${RESET}"
exit 1
fi
# Check if CoupleScript is built
echo "π§ Checking CoupleScript build status..."
if ! make -q all 2>/dev/null; then
echo "β οΈ CoupleScript not built or out of date. Building now..."
if ! make all; then
echo -e "${RED}β Build failed. Cannot run tests.${RESET}"
exit 1
fi
fi
echo -e "${GREEN}β
CoupleScript is built and ready${RESET}"
echo ""
# Run all test suites
test_compilation
test_error_handling
test_performance
test_cross_platform
# Show final results
show_results
}
# Run main function
main "$@"