···
3
+
# Test script with configurable timeout support
4
+
# Usage: ./test.sh [timeout_seconds]
5
+
# Example: ./test.sh 5 (uses 5 second timeout)
6
+
# Default: 1 second timeout
···
18
+
test_timeout=${1:-1}
···
total_tests=$((total_tests + 1))
if [ "$result" = "PASS" ]; then
echo -e "${GREEN}[PASS]${NC} $test_name: $message"
passed_tests=$((passed_tests + 1))
43
+
elif [ "$result" = "TIMEOUT" ]; then
44
+
echo -e "${YELLOW}[TIMEOUT]${NC} $test_name: $message"
echo -e "${RED}[FAIL]${NC} $test_name: $message"
···
# Test with known valid verse
basic_input="Genesis\n1\n1"
72
-
resp=$(echo -e "$basic_input" | "$program" 2>&1)
80
+
resp=$(timeout "$test_timeout" bash -c "echo -e '$basic_input' | '$program'" 2>&1)
···
83
-
if [ $exit_code -ne 0 ]; then
91
+
if [ $exit_code -eq 124 ]; then
92
+
print_result "Basic Execution" "TIMEOUT" "Program timed out after ${test_timeout}s"
94
+
elif [ $exit_code -ne 0 ]; then
print_result "Basic Execution" "FAIL" "Program exited with code $exit_code"
···
local expected_pattern="$5"
local should_create_file="$6"
input="$book\n$chapter\n$verse"
147
-
output=$(echo -e "$input" | "$program" 2>&1)
158
+
output=$(timeout "$test_timeout" bash -c "echo -e '$input' | '$program'" 2>&1)
150
-
if [ $exit_code -ne 0 ]; then
161
+
if [ $exit_code -eq 124 ]; then
162
+
print_result "$test_name" "TIMEOUT" "Program timed out after ${test_timeout}s"
164
+
elif [ $exit_code -ne 0 ]; then
print_result "$test_name" "FAIL" "Program crashed (exit code $exit_code)"
# Check if expected pattern is found in output
if [[ "$output" == *"$expected_pattern"* ]]; then
# For tests expecting specific output, pattern must be found
if [ -n "$expected_pattern" ] && [ "$pattern_found" = "false" ]; then
print_result "$test_name" "FAIL" "Expected '$expected_pattern' not found in output"
# Check file creation expectations
if [ "$should_create_file" = "true" ]; then
if [ -f "verses.txt" ] && [ "$pattern_found" = "true" ]; then
···
local expected_pattern="$3"
local should_succeed="$4"
# Provide verse lookup input for file path tests
if [ -n "$file_path" ]; then
236
-
output=$(echo -e "$input" | "$program" "$file_path" 2>&1)
250
+
output=$(timeout "$test_timeout" bash -c "echo -e '$input' | '$program' '$file_path'" 2>&1)
238
-
output=$(echo -e "$input" | "$program" 2>&1)
252
+
output=$(timeout "$test_timeout" bash -c "echo -e '$input' | '$program'" 2>&1)
256
+
if [ $exit_code -eq 124 ]; then
257
+
print_result "$test_name" "TIMEOUT" "Program timed out after ${test_timeout}s"
if [ "$should_succeed" = "true" ]; then
if [ $exit_code -eq 0 ]; then
print_result "$test_name" "PASS" "Program accepted file path successfully"
···
echo -e "${RED}Some tests failed!${NC}"