-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathtest.sh
More file actions
97 lines (86 loc) · 2.9 KB
/
test.sh
File metadata and controls
97 lines (86 loc) · 2.9 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
# Check for flags
xdebug_enabled=false
xdebug_coverage=false
xdebug_server_name=""
rerun_failed=false
args=()
for arg in "$@"; do
if [[ "$arg" == --xdebug=* ]]; then
xdebug_enabled=true
xdebug_server_name="${arg#--xdebug=}"
elif [[ "$arg" == "--xdebug" ]]; then
xdebug_enabled=true
elif [[ "$arg" == "--xdebug-coverage" ]]; then
xdebug_enabled=true
xdebug_coverage=true
elif [[ "$arg" == "--rerun" ]] || [[ "$arg" == "--retry" ]]; then
rerun_failed=true
else
args+=("$arg")
fi
done
if [ "$xdebug_enabled" = true ]; then
if [ "$xdebug_coverage" = true ]; then
export XDEBUG_MODE="coverage"
else
export XDEBUG_MODE="debug"
fi
export XDEBUG_SESSION="1"
if [ -n "$xdebug_server_name" ]; then
export PHP_IDE_CONFIG="serverName=$xdebug_server_name"
fi
# This file was replicated from the PowerShell test.ps1 file.
# However, we assume this file will be ran within a Docker shell,
# so the line below isn't needed.
#export XDEBUG_CONFIG="client_host=127.0.0.1 client_port=9005"
else
unset XDEBUG_MODE
unset XDEBUG_SESSION
unset XDEBUG_CONFIG
fi
# Function to extract failing test names from TeamCity output
extract_failing_tests() {
if [ ! -f ".phpunit.result.teamcity.txt" ]; then
echo "Error: .phpunit.result.teamcity.txt not found. Run tests first to generate the TeamCity report."
exit 1
fi
failing_tests=$(python3 -c "
import re
with open('.phpunit.result.teamcity.txt') as f:
lines = f.readlines()
for i, line in enumerate(lines):
if 'testFailed' in line and i > 0 and 'testStarted' in lines[i-1]:
match = re.search(r'locationHint=.*?::\\\\([^:]+::[^\']+)', lines[i-1])
if match:
print(match.group(1))
")
if [ -z "$failing_tests" ]; then
echo "No failing tests found in .phpunit.result.teamcity.txt"
exit 0
fi
echo "Rerunning failing tests:"
echo "$failing_tests"
return 0
}
# Build phpunit command with coverage if needed
coverage_args=""
if [ "$xdebug_coverage" = true ]; then
coverage_args="--coverage-xml .phpunit-coverage"
fi
# Run tests
if [ "$rerun_failed" = true ]; then
extract_failing_tests
# Build pipe-separated filter pattern with escaped backslashes
filter_pattern=$(printf '%s\n' $failing_tests | \
sed 's/\\/\\\\/g' | \
paste -sd '|')
if [ -n "$filter_pattern" ]; then
./backend/vendor/bin/phpunit --stop-on-failure -c phpunit.xml.dist --display-warnings $coverage_args --filter "$filter_pattern" backend/src
fi
elif [ ${#args[@]} -eq 0 ]; then
./backend/vendor/bin/phpunit --stop-on-failure -c phpunit.xml.dist --display-warnings $coverage_args backend/src
else
filter="${args[0]}"
./backend/vendor/bin/phpunit --stop-on-failure -c phpunit.xml.dist --display-warnings $coverage_args --filter "$filter" backend/src
fi