|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Comprehensive script to: |
| 4 | +# 1. Run inline assertion tests with proper logging |
| 5 | +# 2. Detect and fail on assertion errors |
| 6 | +# 3. Verify test case parity with Jest tests |
| 7 | + |
| 8 | +set -e |
| 9 | + |
| 10 | +IMPLEMENT_DIR="Sprint-3/1-implement-and-rewrite-tests/implement" |
| 11 | +JEST_DIR="Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest" |
| 12 | + |
| 13 | +PASSED=0 |
| 14 | +FAILED=0 |
| 15 | +TOTAL=0 |
| 16 | +PARITY_ISSUES=false |
| 17 | + |
| 18 | +echo "🧪 Running Inline Assertion Tests" |
| 19 | +echo "==========================================" |
| 20 | +echo "" |
| 21 | + |
| 22 | +# Run each implementation file |
| 23 | +for file in "$IMPLEMENT_DIR"/*.js; do |
| 24 | + filename=$(basename "$file") |
| 25 | + echo "Testing: $filename" |
| 26 | + echo "------------------------------------------" |
| 27 | + |
| 28 | + TOTAL=$((TOTAL + 1)) |
| 29 | + |
| 30 | + # Run the file and capture output |
| 31 | + OUTPUT=$(node "$file" 2>&1) || true |
| 32 | + |
| 33 | + # Check if output contains "Assertion failed" |
| 34 | + if echo "$OUTPUT" | grep -q "Assertion failed"; then |
| 35 | + echo "❌ FAILED" |
| 36 | + echo "$OUTPUT" |
| 37 | + FAILED=$((FAILED + 1)) |
| 38 | + else |
| 39 | + echo "✅ PASSED" |
| 40 | + if [ ! -z "$OUTPUT" ]; then |
| 41 | + echo "$OUTPUT" |
| 42 | + fi |
| 43 | + PASSED=$((PASSED + 1)) |
| 44 | + fi |
| 45 | + |
| 46 | + echo "" |
| 47 | +done |
| 48 | + |
| 49 | +echo "==========================================" |
| 50 | +echo "📊 Test Execution Summary" |
| 51 | +echo "==========================================" |
| 52 | +echo "Total Files: $TOTAL" |
| 53 | +echo "Passed: $PASSED" |
| 54 | +echo "Failed: $FAILED" |
| 55 | +echo "" |
| 56 | + |
| 57 | +# Now check test parity |
| 58 | +echo "==========================================" |
| 59 | +echo "🔍 Verifying Test Case Parity with Jest" |
| 60 | +echo "==========================================" |
| 61 | +echo "" |
| 62 | + |
| 63 | +for impl_file in "$IMPLEMENT_DIR"/*.js; do |
| 64 | + filename=$(basename "$impl_file") |
| 65 | + base_name="${filename%.js}" |
| 66 | + jest_file="$JEST_DIR/${base_name}.test.js" |
| 67 | + |
| 68 | + echo "Comparing: $filename" |
| 69 | + echo "------------------------------------------" |
| 70 | + |
| 71 | + if [ ! -f "$jest_file" ]; then |
| 72 | + echo "⚠️ No corresponding Jest test file found" |
| 73 | + PARITY_ISSUES=true |
| 74 | + echo "" |
| 75 | + continue |
| 76 | + fi |
| 77 | + |
| 78 | + # Count assertions |
| 79 | + inline_count=$(grep -c "assertEquals(" "$impl_file" || echo "0") |
| 80 | + jest_count=$(grep -c "expect(" "$jest_file" || echo "0") |
| 81 | + |
| 82 | + echo " Inline assertions: $inline_count" |
| 83 | + echo " Jest assertions: $jest_count" |
| 84 | + |
| 85 | + if [ "$inline_count" -eq "$jest_count" ]; then |
| 86 | + echo " ✅ Test counts match" |
| 87 | + else |
| 88 | + echo " ⚠️ MISMATCH DETECTED" |
| 89 | + if [ $inline_count -gt $jest_count ]; then |
| 90 | + diff=$((inline_count - jest_count)) |
| 91 | + echo " → Inline tests have $diff MORE assertion(s) than Jest" |
| 92 | + echo " → Jest tests may be missing $diff test case(s)" |
| 93 | + else |
| 94 | + diff=$((jest_count - inline_count)) |
| 95 | + echo " → Jest tests have $diff MORE assertion(s) than Inline" |
| 96 | + echo " → Inline tests may be missing $diff test case(s)" |
| 97 | + fi |
| 98 | + PARITY_ISSUES=true |
| 99 | + fi |
| 100 | + |
| 101 | + echo "" |
| 102 | +done |
| 103 | + |
| 104 | +# Final summary |
| 105 | +echo "==========================================" |
| 106 | +echo "🎯 Final Summary" |
| 107 | +echo "==========================================" |
| 108 | +echo "" |
| 109 | + |
| 110 | +if [ $FAILED -gt 0 ]; then |
| 111 | + echo "❌ TEST FAILURES" |
| 112 | + echo " → $FAILED inline test file(s) have failing assertions" |
| 113 | + echo " → Fix the failing assertions before proceeding" |
| 114 | + echo "" |
| 115 | +fi |
| 116 | + |
| 117 | +if [ "$PARITY_ISSUES" = true ]; then |
| 118 | + echo "⚠️ TEST PARITY ISSUES" |
| 119 | + echo " → The number of test cases differs between inline and Jest tests" |
| 120 | + echo " → Both test suites should cover the same use cases" |
| 121 | + echo " → Review the comparison above and sync the test cases" |
| 122 | + echo "" |
| 123 | +fi |
| 124 | + |
| 125 | +if [ $FAILED -eq 0 ] && [ "$PARITY_ISSUES" = false ]; then |
| 126 | + echo "✅ All inline tests passed!" |
| 127 | + echo "✅ Test parity verified - test counts match!" |
| 128 | + echo "" |
| 129 | + echo "🎉 Everything looks good!" |
| 130 | + exit 0 |
| 131 | +else |
| 132 | + if [ $FAILED -gt 0 ]; then |
| 133 | + echo "❌ Exiting with failure due to test failures" |
| 134 | + exit 1 |
| 135 | + else |
| 136 | + # Parity issues are warnings, not failures (tests still passed) |
| 137 | + echo "⚠️ Tests passed but parity issues detected" |
| 138 | + echo " Please sync test cases between inline and Jest tests" |
| 139 | + exit 0 |
| 140 | + fi |
| 141 | +fi |
0 commit comments