3 # Main test runner for ai-unix tools
4 # Runs all test suites and provides comprehensive test results
8 SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9 TOOLS_DIR="$SCRIPT_DIR/../"
11 # Source common constants
12 source "$TOOLS_DIR/ai-common"
18 NC='\033[0m' # No Color
20 # Test results tracking
26 local test_script="$2"
28 echo -e "${YELLOW}Running $suite_name...${NC}"
29 echo "========================================="
31 if "$test_script"; then
32 echo -e "${GREEN}$suite_name PASSED${NC}"
33 SUITE_RESULTS+=("✓ $suite_name")
36 echo -e "${RED}$suite_name FAILED${NC}"
37 SUITE_RESULTS+=("✗ $suite_name")
45 echo "Usage: $0 [OPTIONS]"
46 echo "Run test suites for ai-unix tools"
49 echo " --basic Run only basic deterministic tests"
50 echo " --format Run only format validation tests"
51 echo " --semantic Run only semantic tests (requires Claude access)"
52 echo " --no-semantic Skip semantic tests (run basic + format only)"
53 echo " --help Show this help message"
55 echo "By default, runs all test suites."
58 # Check if tools exist
59 check_prerequisites() {
60 local missing_tools=()
62 for tool in ai-grep ai-cut ai-class ai-tr ai-test; do
63 if [ ! -x "$TOOLS_DIR/$tool" ]; then
64 missing_tools+=("$tool")
68 if [ ${#missing_tools[@]} -gt 0 ]; then
69 echo -e "${RED}Missing tools: ${missing_tools[*]}${NC}"
70 echo "Please ensure all ai-unix tools are built and executable."
71 exit $EXIT_USAGE_ERROR
74 # Check if python3 is available for JSON validation
75 if ! command -v python3 >/dev/null 2>&1; then
76 echo -e "${YELLOW}Warning: python3 not found. JSON format tests may fail.${NC}"
79 # Check if claude is available for semantic tests
80 if ! command -v claude >/dev/null 2>&1; then
81 echo -e "${YELLOW}Warning: claude command not found. Semantic tests will be skipped.${NC}"
86 # Option configuration lookup
87 declare -A option_configs=(
88 ["--basic"]="true false false"
89 ["--format"]="false true false"
90 ["--semantic"]="false false true"
95 read -r RUN_BASIC RUN_FORMAT RUN_SEMANTIC <<< "$config"
110 --basic|--format|--semantic)
111 set_test_config "${option_configs[$option]}"
115 echo "Unknown option: $option"
117 exit $EXIT_USAGE_ERROR
122 # Parse command line options
128 while [[ $# -gt 0 ]]; do
133 echo "AI-Unix Tools Test Suite"
134 echo "========================"
137 # Check prerequisites
140 # Run test suites based on options
141 if [ "$RUN_BASIC" = true ]; then
142 run_test_suite "Basic Tests" "$SCRIPT_DIR/unit/test-basic.sh" || true
145 if [ "$RUN_FORMAT" = true ]; then
146 run_test_suite "Format Tests" "$SCRIPT_DIR/unit/test-formats.sh" || true
149 if [ "$RUN_SEMANTIC" = true ] && [ "$SKIP_SEMANTIC" = false ]; then
150 run_test_suite "Semantic Tests" "$SCRIPT_DIR/integration/test-semantic.sh" || true
151 elif [ "$RUN_SEMANTIC" = true ] && [ "$SKIP_SEMANTIC" = true ]; then
152 echo -e "${YELLOW}Skipping semantic tests (claude command not available)${NC}"
153 SUITE_RESULTS+=("⚠ Semantic Tests (skipped)")
157 echo "========================================="
158 echo -e "${YELLOW}TEST SUITE SUMMARY${NC}"
159 echo "========================================="
161 for result in "${SUITE_RESULTS[@]}"; do
162 if [[ "$result" == ✓* ]]; then
163 echo -e "${GREEN}$result${NC}"
164 elif [[ "$result" == ✗* ]]; then
165 echo -e "${RED}$result${NC}"
167 echo -e "${YELLOW}$result${NC}"
172 if [ "$TOTAL_FAILED" -eq 0 ]; then
173 echo -e "${GREEN}All test suites completed successfully!${NC}"
176 echo -e "${RED}$TOTAL_FAILED test suite(s) failed.${NC}"