#!/bin/bash echo "a rawking test runner" echo "==================================" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' 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... " # Step 1: Compile awk -f ../rawk.awk "$test_file" > temp_output.awk # Step 2: Run with input output=$(echo "test input" | awk -f temp_output.awk 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++)) rm -f temp_output.awk } # 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)... " output=$(awk -f ../rawk.awk "$test_file" 2>&1) exit_code=$? if [ $exit_code -ne 0 ]; then echo -e "${GREEN}✓ PASS (correctly failed)${NC}" ((PASSED++)) else echo -e "${RED}✗ FAIL (should have failed)${NC}" echo " Output: $output" ((FAILED++)) fi ((TOTAL++)) } # Run all tests echo "" echo "Running basic functionality tests..." run_test "test_basic.rawk" "Basic Functionality" echo "" echo "Running simple standard library tests..." run_test "simple_stdlib_test.rawk" "Simple Standard Library" echo "" echo "Running full standard library tests..." run_test "test_stdlib.rawk" "Full Standard Library" echo "" echo "Running functional programming tests..." run_test "test_functional.rawk" "Functional Programming" 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