···
+
# Test script with configurable timeout support
+
# Usage: ./test.sh [timeout_seconds]
+
# Example: ./test.sh 5 (uses 5 second timeout)
+
# Default: 1 second timeout
···
···
total_tests=$((total_tests + 1))
if [ "$result" = "PASS" ]; then
echo -e "${GREEN}[PASS]${NC} $test_name: $message"
passed_tests=$((passed_tests + 1))
+
elif [ "$result" = "TIMEOUT" ]; then
+
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"
+
resp=$(timeout "$test_timeout" bash -c "echo -e '$basic_input' | '$program'" 2>&1)
···
+
if [ $exit_code -eq 124 ]; then
+
print_result "Basic Execution" "TIMEOUT" "Program timed out after ${test_timeout}s"
+
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"
+
output=$(timeout "$test_timeout" bash -c "echo -e '$input' | '$program'" 2>&1)
+
if [ $exit_code -eq 124 ]; then
+
print_result "$test_name" "TIMEOUT" "Program timed out after ${test_timeout}s"
+
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
+
output=$(timeout "$test_timeout" bash -c "echo -e '$input' | '$program' '$file_path'" 2>&1)
+
output=$(timeout "$test_timeout" bash -c "echo -e '$input' | '$program'" 2>&1)
+
if [ $exit_code -eq 124 ]; then
+
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}"