|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Simple categorized test runner with real-time output and summary |
| 4 | +# Usage: ./run_mcp_only.sh [path_to_q_binary] [--quiet] |
| 5 | + |
| 6 | +# ============================================================================ |
| 7 | +# CATEGORY CONFIGURATION - Set to true/false to enable/disable categories |
| 8 | +# ============================================================================ |
| 9 | +RUN_CORE_SESSION=false |
| 10 | +RUN_AGENT=false |
| 11 | +RUN_CONTEXT=false |
| 12 | +RUN_SAVE_LOAD=false |
| 13 | +RUN_MODEL=false |
| 14 | +RUN_SESSION_MGMT=false |
| 15 | +RUN_INTEGRATION=false |
| 16 | +RUN_MCP=true |
| 17 | +RUN_AI_PROMPTS=false |
| 18 | +RUN_ISSUE_REPORTING=false |
| 19 | +RUN_TOOLS=false |
| 20 | +# ============================================================================ |
| 21 | + |
| 22 | +Q_BINARY="q" |
| 23 | +QUIET_MODE=false |
| 24 | + |
| 25 | +# Parse arguments properly |
| 26 | +while [[ $# -gt 0 ]]; do |
| 27 | + case $1 in |
| 28 | + --quiet|-q) |
| 29 | + QUIET_MODE=false |
| 30 | + shift |
| 31 | + ;; |
| 32 | + *) |
| 33 | + if [ "$Q_BINARY" = "q" ]; then |
| 34 | + Q_BINARY="$1" |
| 35 | + fi |
| 36 | + shift |
| 37 | + ;; |
| 38 | + esac |
| 39 | +done |
| 40 | + |
| 41 | +if [ "$Q_BINARY" != "q" ]; then |
| 42 | + export Q_CLI_PATH="$Q_BINARY" |
| 43 | +fi |
| 44 | + |
| 45 | +echo "🚀 Running Q CLI E2E tests by category" |
| 46 | +echo "======================================" |
| 47 | + |
| 48 | +# Initialize counters |
| 49 | +total_passed=0 |
| 50 | +total_failed=0 |
| 51 | +failed_categories="" |
| 52 | + |
| 53 | +run_category() { |
| 54 | + local category=$1 |
| 55 | + local name=$2 |
| 56 | + |
| 57 | + echo "" |
| 58 | + echo "🧪 $name" |
| 59 | + echo "$(printf '%*s' ${#name} '' | tr ' ' '-')" |
| 60 | + |
| 61 | + # Show which tests will run in this category |
| 62 | + echo "📋 Tests in this category:" |
| 63 | + test_count=0 |
| 64 | + for file in tests/*.rs; do |
| 65 | + if grep -q "cfg(feature = \"$category\")" "$file" 2>/dev/null; then |
| 66 | + # Extract actual test function names from the file |
| 67 | + grep -n "fn test_" "$file" | while read -r line; do |
| 68 | + test_name=$(echo "$line" | sed 's/.*fn \(test_[^(]*\).*/\1/') |
| 69 | + echo " • $test_name" |
| 70 | + ((test_count++)) |
| 71 | + done |
| 72 | + fi |
| 73 | + done |
| 74 | + if [ $test_count -eq 0 ]; then |
| 75 | + echo " • No tests found for this category" |
| 76 | + fi |
| 77 | + echo "" |
| 78 | + |
| 79 | + echo "🔄 Running tests..." |
| 80 | + |
| 81 | + if [ "$QUIET_MODE" = true ]; then |
| 82 | + # Quiet mode - show individual test results in real-time |
| 83 | + cargo test --tests --features "$category" -- --test-threads=1 2>&1 | while IFS= read -r line; do |
| 84 | + if echo "$line" | grep -q "test .* \.\.\. ok$"; then |
| 85 | + test_name=$(echo "$line" | sed 's/test \(.*\) \.\.\. ok/\1/') |
| 86 | + echo " ✅ $test_name" |
| 87 | + elif echo "$line" | grep -q "test .* \.\.\. FAILED$"; then |
| 88 | + test_name=$(echo "$line" | sed 's/test \(.*\) \.\.\. FAILED/\1/') |
| 89 | + echo " ❌ $test_name" |
| 90 | + fi |
| 91 | + done |
| 92 | + |
| 93 | + # Check the exit status of cargo test |
| 94 | + if [ ${PIPESTATUS[0]} -eq 0 ]; then |
| 95 | + echo "✅ $name completed successfully" |
| 96 | + return 0 |
| 97 | + else |
| 98 | + echo "❌ $name had failures" |
| 99 | + if [ -n "$failed_categories" ]; then |
| 100 | + failed_categories="$failed_categories\n$name" |
| 101 | + else |
| 102 | + failed_categories="$name" |
| 103 | + fi |
| 104 | + return 1 |
| 105 | + fi |
| 106 | + else |
| 107 | + # Verbose mode - show full output with real-time test results |
| 108 | + cargo test --tests --features "$category" -- --nocapture --test-threads=1 2>&1 | while IFS= read -r line; do |
| 109 | + echo "$line" |
| 110 | + if echo "$line" | grep -q "test .* \.\.\. ok$"; then |
| 111 | + test_name=$(echo "$line" | sed 's/test \(.*\) \.\.\. ok/\1/') |
| 112 | + echo " ✅ $test_name PASSED" |
| 113 | + elif echo "$line" | grep -q "test .* \.\.\. FAILED$"; then |
| 114 | + test_name=$(echo "$line" | sed 's/test \(.*\) \.\.\. FAILED/\1/') |
| 115 | + echo " ❌ $test_name FAILED" |
| 116 | + fi |
| 117 | + done |
| 118 | + |
| 119 | + # Check the exit status of cargo test |
| 120 | + if [ ${PIPESTATUS[0]} -eq 0 ]; then |
| 121 | + echo "" |
| 122 | + echo "✅ $name completed successfully" |
| 123 | + return 0 |
| 124 | + else |
| 125 | + echo "" |
| 126 | + echo "❌ $name had failures" |
| 127 | + if [ -n "$failed_categories" ]; then |
| 128 | + failed_categories="$failed_categories\n$name" |
| 129 | + else |
| 130 | + failed_categories="$name" |
| 131 | + fi |
| 132 | + return 1 |
| 133 | + fi |
| 134 | + fi |
| 135 | +} |
| 136 | + |
| 137 | +# Run each category and track results |
| 138 | +if [ "$RUN_CORE_SESSION" = true ]; then |
| 139 | + if run_category "core_session" "Core Session Commands"; then |
| 140 | + ((total_passed++)) |
| 141 | + else |
| 142 | + ((total_failed++)) |
| 143 | + fi |
| 144 | +fi |
| 145 | + |
| 146 | +if [ "$RUN_AGENT" = true ]; then |
| 147 | + if run_category "agent" "Agent Commands"; then |
| 148 | + ((total_passed++)) |
| 149 | + else |
| 150 | + ((total_failed++)) |
| 151 | + fi |
| 152 | +fi |
| 153 | + |
| 154 | +if [ "$RUN_CONTEXT" = true ]; then |
| 155 | + if run_category "context" "Context Commands"; then |
| 156 | + ((total_passed++)) |
| 157 | + else |
| 158 | + ((total_failed++)) |
| 159 | + fi |
| 160 | +fi |
| 161 | + |
| 162 | +if [ "$RUN_SAVE_LOAD" = true ]; then |
| 163 | + if run_category "save_load" "Save/Load Commands"; then |
| 164 | + ((total_passed++)) |
| 165 | + else |
| 166 | + ((total_failed++)) |
| 167 | + fi |
| 168 | +fi |
| 169 | + |
| 170 | +if [ "$RUN_MODEL" = true ]; then |
| 171 | + if run_category "model" "Model Commands"; then |
| 172 | + ((total_passed++)) |
| 173 | + else |
| 174 | + ((total_failed++)) |
| 175 | + fi |
| 176 | +fi |
| 177 | + |
| 178 | +if [ "$RUN_SESSION_MGMT" = true ]; then |
| 179 | + if run_category "session_mgmt" "Session Management Commands"; then |
| 180 | + ((total_passed++)) |
| 181 | + else |
| 182 | + ((total_failed++)) |
| 183 | + fi |
| 184 | +fi |
| 185 | + |
| 186 | +if [ "$RUN_INTEGRATION" = true ]; then |
| 187 | + if run_category "integration" "Integration Commands"; then |
| 188 | + ((total_passed++)) |
| 189 | + else |
| 190 | + ((total_failed++)) |
| 191 | + fi |
| 192 | +fi |
| 193 | + |
| 194 | +if [ "$RUN_MCP" = true ]; then |
| 195 | + if run_category "mcp" "MCP Commands"; then |
| 196 | + ((total_passed++)) |
| 197 | + else |
| 198 | + ((total_failed++)) |
| 199 | + fi |
| 200 | +fi |
| 201 | + |
| 202 | +if [ "$RUN_AI_PROMPTS" = true ]; then |
| 203 | + if run_category "ai_prompts" "AI Prompts"; then |
| 204 | + ((total_passed++)) |
| 205 | + else |
| 206 | + ((total_failed++)) |
| 207 | + fi |
| 208 | +fi |
| 209 | + |
| 210 | +if [ "$RUN_ISSUE_REPORTING" = true ]; then |
| 211 | + if run_category "issue_reporting" "ISSUE REPORTING"; then |
| 212 | + ((total_passed++)) |
| 213 | + else |
| 214 | + ((total_failed++)) |
| 215 | + fi |
| 216 | +fi |
| 217 | + |
| 218 | +if [ "$RUN_TOOLS" = true ]; then |
| 219 | + if run_category "tools" "TOOLS"; then |
| 220 | + ((total_passed++)) |
| 221 | + else |
| 222 | + ((total_failed++)) |
| 223 | + fi |
| 224 | +fi |
| 225 | + |
| 226 | +# Final summary |
| 227 | +echo "" |
| 228 | +echo "🎯 FINAL SUMMARY" |
| 229 | +echo "================================" |
| 230 | +echo "✅ Categories Passed: $total_passed" |
| 231 | +echo "❌ Categories Failed: $total_failed" |
| 232 | +echo "📊 Total Categories: $((total_passed + total_failed))" |
| 233 | + |
| 234 | +if [ -n "$failed_categories" ]; then |
| 235 | + echo "" |
| 236 | + echo "❌ Failed Categories:" |
| 237 | + echo -e "$failed_categories" | while read -r category; do |
| 238 | + if [ -n "$category" ]; then |
| 239 | + echo " • $category" |
| 240 | + fi |
| 241 | + done |
| 242 | + echo "" |
| 243 | + echo "💥 Some tests failed!" |
| 244 | + exit 1 |
| 245 | +else |
| 246 | + echo "" |
| 247 | + echo "🎉 All categories passed!" |
| 248 | + exit 0 |
| 249 | +fi |
0 commit comments