diff options
| author | Li Jin <dragon-fly@qq.com> | 2026-02-06 06:28:34 +0000 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2026-02-06 06:28:34 +0000 |
| commit | b018d86d32f0160006aaf9930d8d61b7eacefda4 (patch) | |
| tree | d2fd14eb977c70fd4a0d6c70ed032c483fff2444 /spec | |
| parent | aacf6dd9ebdb4d55b432ea1d4213093fe35e0ad1 (diff) | |
| download | yuescript-b018d86d32f0160006aaf9930d8d61b7eacefda4.tar.gz yuescript-b018d86d32f0160006aaf9930d8d61b7eacefda4.tar.bz2 yuescript-b018d86d32f0160006aaf9930d8d61b7eacefda4.zip | |
test: enhance CLI test summary with detailed statistics
Improve test results display with:
- Per-suite test case breakdown table
- Overall statistics panel showing suite and case counts
- Pass rate percentage calculation
- Formatted borders and color-coded status indicators
- Clear final verdict summary
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'spec')
| -rwxr-xr-x | spec/cli/run_all_tests.sh | 119 |
1 files changed, 110 insertions, 9 deletions
diff --git a/spec/cli/run_all_tests.sh b/spec/cli/run_all_tests.sh index 0067bba..a095796 100755 --- a/spec/cli/run_all_tests.sh +++ b/spec/cli/run_all_tests.sh | |||
| @@ -9,6 +9,7 @@ RED='\033[0;31m' | |||
| 9 | GREEN='\033[0;32m' | 9 | GREEN='\033[0;32m' |
| 10 | YELLOW='\033[1;33m' | 10 | YELLOW='\033[1;33m' |
| 11 | BLUE='\033[0;34m' | 11 | BLUE='\033[0;34m' |
| 12 | CYAN='\033[0;36m' | ||
| 12 | NC='\033[0m' # No Color | 13 | NC='\033[0m' # No Color |
| 13 | 14 | ||
| 14 | echo -e "${BLUE}======================================" | 15 | echo -e "${BLUE}======================================" |
| @@ -31,6 +32,17 @@ TOTAL_SUITES=0 | |||
| 31 | PASSED_SUITES=0 | 32 | PASSED_SUITES=0 |
| 32 | FAILED_SUITES=0 | 33 | FAILED_SUITES=0 |
| 33 | 34 | ||
| 35 | # Track test case statistics | ||
| 36 | TOTAL_TESTS=0 | ||
| 37 | TOTAL_PASSED=0 | ||
| 38 | TOTAL_FAILED=0 | ||
| 39 | |||
| 40 | # Array to store suite results | ||
| 41 | declare -a SUITE_NAMES | ||
| 42 | declare -a SUITE_PASSED | ||
| 43 | declare -a SUITE_FAILED | ||
| 44 | declare -a SUITE_STATUS | ||
| 45 | |||
| 34 | # Function to run a test suite | 46 | # Function to run a test suite |
| 35 | run_test_suite() { | 47 | run_test_suite() { |
| 36 | local suite_name="$1" | 48 | local suite_name="$1" |
| @@ -41,13 +53,51 @@ run_test_suite() { | |||
| 41 | echo -e "${BLUE}Running: $suite_name${NC}" | 53 | echo -e "${BLUE}Running: $suite_name${NC}" |
| 42 | echo "======================================" | 54 | echo "======================================" |
| 43 | 55 | ||
| 44 | if bash "$suite_file"; then | 56 | # Run the test suite and capture output |
| 57 | local output | ||
| 58 | output=$(bash "$suite_file" 2>&1) | ||
| 59 | local exit_code=$? | ||
| 60 | |||
| 61 | # Echo the output | ||
| 62 | echo "$output" | ||
| 63 | |||
| 64 | # Parse test statistics from output using awk | ||
| 65 | # Look for lines like "Total tests: 7", "Passed: 7", "Failed: 0" | ||
| 66 | # Remove ANSI color codes before parsing | ||
| 67 | local clean_output=$(echo "$output" | sed 's/\x1b\[[0-9;]*m//g') | ||
| 68 | local suite_total=$(echo "$clean_output" | grep -E "Total tests:" | tail -1 | awk '{print $NF}') | ||
| 69 | local suite_passed=$(echo "$clean_output" | grep -E "Passed:" | tail -1 | awk '{print $NF}') | ||
| 70 | local suite_failed=$(echo "$clean_output" | grep -E "Failed:" | tail -1 | awk '{print $NF}') | ||
| 71 | |||
| 72 | # Default to 0 if not found | ||
| 73 | suite_total=${suite_total:-0} | ||
| 74 | suite_passed=${suite_passed:-0} | ||
| 75 | suite_failed=${suite_failed:-0} | ||
| 76 | |||
| 77 | # Validate that they are numbers | ||
| 78 | [[ ! "$suite_total" =~ ^[0-9]+$ ]] && suite_total=0 | ||
| 79 | [[ ! "$suite_passed" =~ ^[0-9]+$ ]] && suite_passed=0 | ||
| 80 | [[ ! "$suite_failed" =~ ^[0-9]+$ ]] && suite_failed=0 | ||
| 81 | |||
| 82 | # Store results | ||
| 83 | SUITE_NAMES+=("$suite_name") | ||
| 84 | SUITE_PASSED+=($suite_passed) | ||
| 85 | SUITE_FAILED+=($suite_failed) | ||
| 86 | |||
| 87 | # Update totals | ||
| 88 | TOTAL_TESTS=$((TOTAL_TESTS + suite_total)) | ||
| 89 | TOTAL_PASSED=$((TOTAL_PASSED + suite_passed)) | ||
| 90 | TOTAL_FAILED=$((TOTAL_FAILED + suite_failed)) | ||
| 91 | |||
| 92 | if [ $exit_code -eq 0 ]; then | ||
| 45 | echo -e "${GREEN}✓ $suite_name PASSED${NC}" | 93 | echo -e "${GREEN}✓ $suite_name PASSED${NC}" |
| 46 | PASSED_SUITES=$((PASSED_SUITES + 1)) | 94 | PASSED_SUITES=$((PASSED_SUITES + 1)) |
| 95 | SUITE_STATUS+=("PASS") | ||
| 47 | return 0 | 96 | return 0 |
| 48 | else | 97 | else |
| 49 | echo -e "${RED}✗ $suite_name FAILED${NC}" | 98 | echo -e "${RED}✗ $suite_name FAILED${NC}" |
| 50 | FAILED_SUITES=$((FAILED_SUITES + 1)) | 99 | FAILED_SUITES=$((FAILED_SUITES + 1)) |
| 100 | SUITE_STATUS+=("FAIL") | ||
| 51 | return 1 | 101 | return 1 |
| 52 | fi | 102 | fi |
| 53 | } | 103 | } |
| @@ -58,20 +108,71 @@ run_test_suite "Compilation Test" "$SCRIPT_DIR/test_compilation.sh" | |||
| 58 | run_test_suite "Error Handling Test" "$SCRIPT_DIR/test_error_handling.sh" | 108 | run_test_suite "Error Handling Test" "$SCRIPT_DIR/test_error_handling.sh" |
| 59 | run_test_suite "Execution Test" "$SCRIPT_DIR/test_execution.sh" | 109 | run_test_suite "Execution Test" "$SCRIPT_DIR/test_execution.sh" |
| 60 | 110 | ||
| 61 | # Print final summary | 111 | # Print detailed summary |
| 112 | echo "" | ||
| 113 | echo -e "${CYAN}╔════════════════════════════════════════════════════════╗" | ||
| 114 | echo "║ YueScript CLI Test Results Summary ║" | ||
| 115 | echo "╚════════════════════════════════════════════════════════╝${NC}" | ||
| 116 | echo "" | ||
| 117 | |||
| 118 | # Print per-suite statistics | ||
| 119 | echo -e "${CYAN}Test Suite Details:${NC}" | ||
| 120 | echo "┌────────────────────────────────┬────────┬────────┬────────┬──────────┐" | ||
| 121 | echo "│ Test Suite │ Total │ Passed │ Failed │ Status │" | ||
| 122 | echo "├────────────────────────────────┼────────┼────────┼────────┼──────────┤" | ||
| 123 | |||
| 124 | for ((i=0; i<TOTAL_SUITES; i++)); do | ||
| 125 | name="${SUITE_NAMES[$i]}" | ||
| 126 | passed="${SUITE_PASSED[$i]}" | ||
| 127 | failed="${SUITE_FAILED[$i]}" | ||
| 128 | total=$((passed + failed)) | ||
| 129 | status="${SUITE_STATUS[$i]}" | ||
| 130 | |||
| 131 | # Format suite name (truncate if too long) | ||
| 132 | name_display=$(printf "%.30s" "$name") | ||
| 133 | printf "│ %-30s │ %6d │ %6d │ %6d │ " "$name_display" $total $passed $failed | ||
| 134 | |||
| 135 | if [ "$status" = "PASS" ]; then | ||
| 136 | echo -e "${GREEN}✓ PASS ${NC}│" | ||
| 137 | else | ||
| 138 | echo -e "${RED}✗ FAIL ${NC}│" | ||
| 139 | fi | ||
| 140 | done | ||
| 141 | |||
| 142 | echo "└────────────────────────────────┴────────┴────────┴────────┴──────────┘" | ||
| 62 | echo "" | 143 | echo "" |
| 144 | |||
| 145 | # Print overall statistics | ||
| 146 | echo -e "${CYAN}Overall Statistics:${NC}" | ||
| 147 | echo "┌─────────────────────────────────────────────────────────────────┐" | ||
| 148 | printf "│ Total Test Suites: %3d │\n" $TOTAL_SUITES | ||
| 149 | printf "│ Passed Test Suites: %3d │\n" $PASSED_SUITES | ||
| 150 | printf "│ Failed Test Suites: %3d │\n" $FAILED_SUITES | ||
| 151 | echo "├─────────────────────────────────────────────────────────────────┤" | ||
| 152 | printf "│ Total Test Cases: %3d │\n" $TOTAL_TESTS | ||
| 153 | printf "│ Passed Test Cases: %3d │\n" $TOTAL_PASSED | ||
| 154 | printf "│ Failed Test Cases: %3d │\n" $TOTAL_FAILED | ||
| 155 | echo "└─────────────────────────────────────────────────────────────────┘" | ||
| 156 | echo "" | ||
| 157 | |||
| 158 | # Calculate pass rate | ||
| 159 | if [ $TOTAL_TESTS -gt 0 ]; then | ||
| 160 | pass_rate=$((TOTAL_PASSED * 100 / TOTAL_TESTS)) | ||
| 161 | echo -e "Overall Pass Rate: ${CYAN}$pass_rate%%${NC}" | ||
| 162 | echo "" | ||
| 163 | fi | ||
| 164 | |||
| 165 | # Final verdict | ||
| 63 | echo -e "${BLUE}======================================" | 166 | echo -e "${BLUE}======================================" |
| 64 | echo "Final Test Suite Summary" | 167 | echo "Final Verdict" |
| 65 | echo "======================================${NC}" | 168 | echo "======================================${NC}" |
| 66 | echo "Total test suites: $TOTAL_SUITES" | ||
| 67 | echo -e "Passed: ${GREEN}$PASSED_SUITES${NC}" | ||
| 68 | echo -e "Failed: ${RED}$FAILED_SUITES${NC}" | ||
| 69 | echo "======================================" | ||
| 70 | 169 | ||
| 71 | if [ $FAILED_SUITES -eq 0 ]; then | 170 | if [ $FAILED_SUITES -eq 0 ]; then |
| 72 | echo -e "${GREEN}All test suites passed!${NC}" | 171 | echo -e "${GREEN}✓ All test suites passed!${NC}" |
| 172 | echo -e "${GREEN}✓ All $TOTAL_TESTS test cases passed!${NC}" | ||
| 73 | exit 0 | 173 | exit 0 |
| 74 | else | 174 | else |
| 75 | echo -e "${RED}Some test suites failed!${NC}" | 175 | echo -e "${RED}✗ $FAILED_SUITES test suite(s) failed${NC}" |
| 176 | echo -e "${RED}✗ $TOTAL_FAILED test case(s) failed${NC}" | ||
| 76 | exit 1 | 177 | exit 1 |
| 77 | fi | 178 | fi |
