-
Notifications
You must be signed in to change notification settings - Fork 556
Expand file tree
/
Copy pathrun_and_debug.sh
More file actions
97 lines (82 loc) · 3.22 KB
/
Copy pathrun_and_debug.sh
File metadata and controls
97 lines (82 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/bash
# ============================================================
# run_and_debug.sh — Run a Behat scenario AND show debug info
#
# Usage:
# ./run_and_debug.sh <feature_file> [line_number]
#
# Examples:
# ./run_and_debug.sh features/SpecialCase1.feature 10
# ./run_and_debug.sh features/debugTest.feature
#
# After execution:
# - If the test PASSES: shows "ALL PASSED"
# - If the test FAILS: shows meta + form_summary automatically
# ============================================================
BEHAT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_DIR="$(cd "$BEHAT_DIR/../.." && pwd)"
DEBUG_DIR="$BEHAT_DIR/behat_debug"
# wsl_output.txt is the Windows-readable bridge file: WSL writes here (/mnt/c/...)
# and Windows (IDE, Claude Code) reads from C:\wamp64\www\chamilo2\tests\behat\wsl_output.txt.
OUTPUT_FILE="/mnt/c/wamp64/www/chamilo2/tests/behat/wsl_output.txt"
FEATURE_FILE="$1"
LINE="$2"
if [ -z "$FEATURE_FILE" ]; then
echo "Usage: $0 <feature_file> [line_number]"
echo "Example: $0 features/SpecialCase1.feature 10"
exit 1
fi
# Clean previous debug files
rm -f "$DEBUG_DIR"/*_full.html "$DEBUG_DIR"/*_form_summary.txt "$DEBUG_DIR"/*_meta.txt 2>/dev/null
# Build the behat command
if [ -n "$LINE" ]; then
BEHAT_TARGET="${BEHAT_DIR}/${FEATURE_FILE}:${LINE}"
else
BEHAT_TARGET="${BEHAT_DIR}/${FEATURE_FILE}"
fi
echo "=================================================="
echo "Running: vendor/bin/behat $BEHAT_TARGET"
echo "=================================================="
cd "$PROJECT_DIR"
vendor/bin/behat "$BEHAT_TARGET" --config "${BEHAT_DIR}/behat.yml" 2>&1
BEHAT_EXIT=$?
echo ""
echo "=================================================="
if [ $BEHAT_EXIT -eq 0 ]; then
echo "ALL PASSED"
echo "=================================================="
# Write to output file for Windows reading
echo "ALL PASSED" > "$OUTPUT_FILE"
else
echo "FAILED — Reading debug dumps..."
echo "=================================================="
echo ""
# Collect all output into the Windows-readable file
> "$OUTPUT_FILE"
# Find the latest meta file
LATEST_META=$(ls -t "$DEBUG_DIR"/*_meta.txt 2>/dev/null | head -1)
if [ -n "$LATEST_META" ]; then
echo "=== META ===" | tee -a "$OUTPUT_FILE"
cat "$LATEST_META" | tee -a "$OUTPUT_FILE"
echo "" | tee -a "$OUTPUT_FILE"
fi
# Find the latest form summary
LATEST_SUMMARY=$(ls -t "$DEBUG_DIR"/*_form_summary.txt 2>/dev/null | head -1)
if [ -n "$LATEST_SUMMARY" ]; then
echo "=== FORM SUMMARY ===" | tee -a "$OUTPUT_FILE"
cat "$LATEST_SUMMARY" | tee -a "$OUTPUT_FILE"
echo "" | tee -a "$OUTPUT_FILE"
fi
# Also add first 200 lines of full HTML for deep analysis
LATEST_FULL=$(ls -t "$DEBUG_DIR"/*_full.html 2>/dev/null | head -1)
if [ -n "$LATEST_FULL" ]; then
echo "=== FULL HTML (first 200 lines) ===" >> "$OUTPUT_FILE"
head -200 "$LATEST_FULL" >> "$OUTPUT_FILE"
echo "" >> "$OUTPUT_FILE"
echo "(Full HTML available in: $LATEST_FULL)" | tee -a "$OUTPUT_FILE"
fi
echo ""
echo "Debug output also written to: $OUTPUT_FILE"
echo "(readable from Windows at C:\\wamp64\\www\\chamilo2\\tests\\behat\\wsl_output.txt)"
fi
exit $BEHAT_EXIT