#!/bin/bash # Test Runner for Simple Scripting Language # Runs unit tests and integration tests systematically echo "=== Simple Scripting Language Test Suite ===" echo "" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Function to run a test run_test() { local test_file=$1 local test_name=$2 echo -n "Running $test_name... " # Capture both stdout and stderr, and get the exit code local output local exit_code output=$(node lang.js "$test_file" 2>&1) exit_code=$? if [ $exit_code -eq 0 ]; then echo -e "${GREEN}PASS${NC}" return 0 else echo -e "${RED}FAIL${NC}" echo -e "${RED}Error:${NC} $output" return 1 fi } # Function to run a test with output run_test_with_output() { local test_file=$1 local test_name=$2 echo -e "${YELLOW}=== $test_name ===${NC}" node lang.js "$test_file" echo "" } # Counters total_tests=0 passed_tests=0 failed_tests=0 echo "Running Unit Tests..." echo "====================" # Unit tests unit_tests=( "tests/01_lexer_basic.txt:Basic Lexer" "tests/02_arithmetic_operations.txt:Arithmetic Operations" "tests/03_comparison_operators.txt:Comparison Operators" "tests/04_logical_operators.txt:Logical Operators" "tests/05_io_operations.txt:IO Operations" "tests/06_function_definitions.txt:Function Definitions" "tests/07_case_expressions.txt:Case Expressions" "tests/08_first_class_functions.txt:First-Class Functions" "tests/09_tables.txt:Tables" "tests/10_standard_library.txt:Standard Library" "tests/11_edge_cases.txt:Edge Cases" "tests/12_advanced_tables.txt:Advanced Tables" "tests/13_standard_library_complete.txt:Complete Standard Library" "tests/14_error_handling.txt:Error Handling" # "tests/15_performance_stress.txt:Performance and Stress" # "tests/16_advanced_functional.txt:Advanced Functional Programming" # "tests/17_real_world_scenarios.txt:Real-World Scenarios" ) for test in "${unit_tests[@]}"; do IFS=':' read -r file name <<< "$test" total_tests=$((total_tests + 1)) if run_test "$file" "$name"; then passed_tests=$((passed_tests + 1)) else failed_tests=$((failed_tests + 1)) fi done echo "" echo "Running Integration Tests..." echo "===========================" # Integration tests integration_tests=( "tests/integration_01_basic_features.txt:Basic Features Integration" "tests/integration_02_pattern_matching.txt:Pattern Matching Integration" "tests/integration_03_functional_programming.txt:Functional Programming Integration" "tests/integration_04_mini_case_multi_param.txt:Multi-parameter case expression at top level" ) for test in "${integration_tests[@]}"; do IFS=':' read -r file name <<< "$test" total_tests=$((total_tests + 1)) if run_test "$file" "$name"; then passed_tests=$((passed_tests + 1)) else failed_tests=$((failed_tests + 1)) fi done echo "" echo "=== Test Summary ===" echo "Total tests: $total_tests" echo -e "Passed: ${GREEN}$passed_tests${NC}" echo -e "Failed: ${RED}$failed_tests${NC}" if [ $failed_tests -eq 0 ]; then echo -e "${GREEN}All tests passed!${NC}" exit 0 else echo -e "${RED}Some tests failed.${NC}" exit 1 fi