#!/bin/bash set -e echo "Running rawk Test Suite" echo "==================================" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' 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... " output=$(echo "test input" | awk -f ../rawk.awk "$test_file" | awk -f - 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++)) } # 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)... " if awk -f ../rawk.awk "$test_file" > /dev/null 2>&1; then echo -e "${RED}✗ FAIL (should have failed)${NC}" ((FAILED++)) else echo -e "${GREEN}✓ PASS (correctly failed)${NC}" ((PASSED++)) fi ((TOTAL++)) } # Run all tests echo "" echo "Running basic functionality tests..." run_test "test_basic.rawk" "Basic Functionality" echo "" echo "Running standard library tests..." run_test "test_stdlib.rawk" "Standard Library" echo "" echo "Running functional programming tests..." run_test "test_functional.rawk" "Functional Programming" echo "" echo "Running smart standard library tests..." run_test "test_smart_stdlib.rawk" "Smart Standard Library" 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