#!/bin/bash # Main test runner for ai-unix tools # Runs all test suites and provides comprehensive test results set -e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" TOOLS_DIR="$SCRIPT_DIR/../" # Source common constants source "$TOOLS_DIR/ai-common" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Test results tracking TOTAL_FAILED=0 SUITE_RESULTS=() run_test_suite() { local suite_name="$1" local test_script="$2" echo -e "${YELLOW}Running $suite_name...${NC}" echo "=========================================" if "$test_script"; then echo -e "${GREEN}$suite_name PASSED${NC}" SUITE_RESULTS+=("✓ $suite_name") echo else echo -e "${RED}$suite_name FAILED${NC}" SUITE_RESULTS+=("✗ $suite_name") ((TOTAL_FAILED++)) echo return 1 fi } show_usage() { echo "Usage: $0 [OPTIONS]" echo "Run test suites for ai-unix tools" echo "" echo "Options:" echo " --basic Run only basic deterministic tests" echo " --format Run only format validation tests" echo " --semantic Run only semantic tests (requires Claude access)" echo " --no-semantic Skip semantic tests (run basic + format only)" echo " --help Show this help message" echo "" echo "By default, runs all test suites." } # Check if tools exist check_prerequisites() { local missing_tools=() for tool in ai-grep ai-cut ai-class ai-tr ai-test; do if [ ! -x "$TOOLS_DIR/$tool" ]; then missing_tools+=("$tool") fi done if [ ${#missing_tools[@]} -gt 0 ]; then echo -e "${RED}Missing tools: ${missing_tools[*]}${NC}" echo "Please ensure all ai-unix tools are built and executable." exit $EXIT_USAGE_ERROR fi # Check if python3 is available for JSON validation if ! command -v python3 >/dev/null 2>&1; then echo -e "${YELLOW}Warning: python3 not found. JSON format tests may fail.${NC}" fi # Check if claude is available for semantic tests if ! command -v claude >/dev/null 2>&1; then echo -e "${YELLOW}Warning: claude command not found. Semantic tests will be skipped.${NC}" SKIP_SEMANTIC=true fi } # Option configuration lookup declare -A option_configs=( ["--basic"]="true false false" ["--format"]="false true false" ["--semantic"]="false false true" ) set_test_config() { local config="$1" read -r RUN_BASIC RUN_FORMAT RUN_SEMANTIC <<< "$config" } handle_option() { local option="$1" case "$option" in --no-semantic) RUN_SEMANTIC=false return 0 ;; --help) show_usage exit $EXIT_SUCCESS ;; --basic|--format|--semantic) set_test_config "${option_configs[$option]}" return 0 ;; *) echo "Unknown option: $option" show_usage exit $EXIT_USAGE_ERROR ;; esac } # Parse command line options RUN_BASIC=true RUN_FORMAT=true RUN_SEMANTIC=true SKIP_SEMANTIC=false while [[ $# -gt 0 ]]; do handle_option "$1" shift done echo "AI-Unix Tools Test Suite" echo "========================" echo # Check prerequisites check_prerequisites # Run test suites based on options if [ "$RUN_BASIC" = true ]; then run_test_suite "Basic Tests" "$SCRIPT_DIR/unit/test-basic.sh" || true fi if [ "$RUN_FORMAT" = true ]; then run_test_suite "Format Tests" "$SCRIPT_DIR/unit/test-formats.sh" || true fi if [ "$RUN_SEMANTIC" = true ] && [ "$SKIP_SEMANTIC" = false ]; then run_test_suite "Semantic Tests" "$SCRIPT_DIR/integration/test-semantic.sh" || true elif [ "$RUN_SEMANTIC" = true ] && [ "$SKIP_SEMANTIC" = true ]; then echo -e "${YELLOW}Skipping semantic tests (claude command not available)${NC}" SUITE_RESULTS+=("⚠ Semantic Tests (skipped)") fi # Final results echo "=========================================" echo -e "${YELLOW}TEST SUITE SUMMARY${NC}" echo "=========================================" for result in "${SUITE_RESULTS[@]}"; do if [[ "$result" == ✓* ]]; then echo -e "${GREEN}$result${NC}" elif [[ "$result" == ✗* ]]; then echo -e "${RED}$result${NC}" else echo -e "${YELLOW}$result${NC}" fi done echo if [ "$TOTAL_FAILED" -eq 0 ]; then echo -e "${GREEN}All test suites completed successfully!${NC}" exit $EXIT_SUCCESS else echo -e "${RED}$TOTAL_FAILED test suite(s) failed.${NC}" exit 1 fi