forked from cameroncooke/AXe
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-runner.sh
More file actions
executable file
·397 lines (339 loc) · 11.2 KB
/
test-runner.sh
File metadata and controls
executable file
·397 lines (339 loc) · 11.2 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
#!/bin/bash
# AXe Test Runner Script
# Automates building AXe executable, playground app, and running tests
set -e # Exit on any error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Configuration
SIMULATOR_NAME="iPhone 17 Pro"
SIMULATOR_UDID="${SIMULATOR_UDID:-}"
PLAYGROUND_PROJECT="AxePlaygroundApp/AxePlayground.xcodeproj"
PLAYGROUND_SCHEME="AxePlayground"
BUNDLE_ID="com.cameroncooke.AxePlayground"
# Print colored messages
print_info() {
echo -e "${BLUE}ℹ️ $1${NC}"
}
print_success() {
echo -e "${GREEN}✅ $1${NC}"
}
print_warning() {
echo -e "${YELLOW}⚠️ $1${NC}"
}
print_error() {
echo -e "${RED}❌ $1${NC}"
}
print_header() {
echo -e "\n${BLUE}================================================${NC}"
echo -e "${BLUE}🎯 $1${NC}"
echo -e "${BLUE}================================================${NC}\n"
}
# Function to show usage
show_usage() {
echo "Usage: $0 [OPTIONS] [TEST_FILTER]"
echo ""
echo "Options:"
echo " -h, --help Show this help message"
echo " -b, --build-only Only build AXe and playground app (skip tests)"
echo " -t, --tests-only Only run tests (skip building)"
echo " -c, --clean Clean build before building"
echo " -s, --sequential Run suites one-by-one (single simulator-safe flow)"
echo " -v, --verbose Verbose output"
echo ""
echo "Test Filters (optional):"
echo " SwipeTests Run only swipe tests"
echo " TapTests Run only tap tests"
echo " KeyTests Run only key tests"
echo " TouchTests Run only touch tests"
echo " TypeTests Run only type tests"
echo " ButtonTests Run only button tests"
echo " GestureTests Run only gesture tests"
echo " ListSimulatorsTests Run only list simulators tests"
echo ""
echo "Examples:"
echo " $0 # Build everything and run all tests"
echo " $0 SwipeTests # Build everything and run only swipe tests"
echo " $0 -t SwipeTests # Skip building, run only swipe tests"
echo " $0 -b # Only build, skip tests"
echo " $0 -c # Clean build and run all tests"
}
# Parse command line arguments
BUILD_ONLY=false
TESTS_ONLY=false
CLEAN_BUILD=false
SEQUENTIAL=true
VERBOSE=false
TEST_FILTER=""
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
show_usage
exit 0
;;
-b|--build-only)
BUILD_ONLY=true
shift
;;
-t|--tests-only)
TESTS_ONLY=true
shift
;;
-c|--clean)
CLEAN_BUILD=true
shift
;;
-s|--sequential)
SEQUENTIAL=true
shift
;;
-v|--verbose)
VERBOSE=true
shift
;;
SwipeTests|TapTests|KeyTests|TouchTests|TypeTests|ButtonTests|GestureTests|ListSimulatorsTests)
TEST_FILTER="$1"
shift
;;
*)
print_error "Unknown option: $1"
show_usage
exit 1
;;
esac
done
# Function to check prerequisites
check_prerequisites() {
print_header "Checking Prerequisites"
# Check if we're in the right directory
if [[ ! -f "Package.swift" ]]; then
print_error "Package.swift not found. Please run this script from the AXe project root."
exit 1
fi
# Check if Xcode is available
if ! command -v xcodebuild &> /dev/null; then
print_error "xcodebuild not found. Please install Xcode."
exit 1
fi
# Check if Swift is available
if ! command -v swift &> /dev/null; then
print_error "swift not found. Please install Swift."
exit 1
fi
print_success "All prerequisites satisfied"
}
# Function to boot simulator
boot_simulator() {
print_header "Setting Up Simulator"
if [[ -z "$SIMULATOR_UDID" ]]; then
SIMULATOR_UDID=$(xcrun simctl list devices | grep "$SIMULATOR_NAME" | grep -oE '[A-F0-9-]{36}' | head -1)
fi
print_info "Checking simulator status..."
SIMULATOR_STATUS=$(xcrun simctl list devices | grep "$SIMULATOR_UDID" | grep -o "Booted\|Shutdown" || echo "NotFound")
if [[ -z "$SIMULATOR_UDID" || "$SIMULATOR_STATUS" == "NotFound" ]]; then
print_error "Simulator with UDID $SIMULATOR_UDID not found"
print_info "Available simulators:"
xcrun simctl list devices | grep "iPhone"
exit 1
fi
if [[ "$SIMULATOR_STATUS" != "Booted" ]]; then
print_info "Booting simulator $SIMULATOR_NAME..."
xcrun simctl boot "$SIMULATOR_UDID"
sleep 3
print_success "Simulator booted"
else
print_success "Simulator already booted"
fi
}
# Function to clean build
clean_build() {
if [[ "$CLEAN_BUILD" == true ]]; then
print_header "Cleaning Build"
print_info "Cleaning Swift build..."
swift package clean
print_info "Cleaning Xcode build..."
xcodebuild clean -project "$PLAYGROUND_PROJECT" -scheme "$PLAYGROUND_SCHEME" -destination "id=$SIMULATOR_UDID"
print_success "Build cleaned"
fi
}
# Function to build AXe executable
build_axe() {
print_header "Building AXe Executable"
print_info "Building AXe CLI tool..."
if [[ "$VERBOSE" == true ]]; then
swift build
else
swift build > /dev/null 2>&1
fi
local axe_bin_path
axe_bin_path="$(swift build --show-bin-path)/axe"
# Verify the executable exists
if [[ -f "$axe_bin_path" ]]; then
print_success "AXe executable built successfully"
print_info "Location: $axe_bin_path"
else
print_error "Failed to build AXe executable"
exit 1
fi
}
# Function to build and install playground app
build_playground_app() {
print_header "Building and Installing Playground App"
# Terminate existing app instance
print_info "Terminating existing app instance..."
xcrun simctl terminate "$SIMULATOR_UDID" "$BUNDLE_ID" 2>/dev/null || true
# Build the app (not build-for-testing since this is a regular app)
print_info "Building AxePlayground app..."
if [[ "$VERBOSE" == true ]]; then
xcodebuild build \
-project "$PLAYGROUND_PROJECT" \
-scheme "$PLAYGROUND_SCHEME" \
-destination "id=$SIMULATOR_UDID"
else
xcodebuild build \
-project "$PLAYGROUND_PROJECT" \
-scheme "$PLAYGROUND_SCHEME" \
-destination "id=$SIMULATOR_UDID" \
-quiet > /dev/null 2>&1
fi
# Find the built app path using TARGET_BUILD_DIR + FULL_PRODUCT_NAME (more semantically correct)
print_info "Getting app bundle path..."
BUILD_SETTINGS=$(xcodebuild -project "$PLAYGROUND_PROJECT" -scheme "$PLAYGROUND_SCHEME" -destination "id=$SIMULATOR_UDID" -showBuildSettings)
TARGET_BUILD_DIR=$(echo "$BUILD_SETTINGS" | grep "TARGET_BUILD_DIR" | head -1 | sed 's/.*= //')
FULL_PRODUCT_NAME=$(echo "$BUILD_SETTINGS" | grep "FULL_PRODUCT_NAME" | head -1 | sed 's/.*= //')
APP_PATH="$TARGET_BUILD_DIR/$FULL_PRODUCT_NAME"
if [[ -z "$APP_PATH" || ! -d "$APP_PATH" ]]; then
print_error "Built app not found at: $APP_PATH"
print_info "TARGET_BUILD_DIR: $TARGET_BUILD_DIR"
print_info "FULL_PRODUCT_NAME: $FULL_PRODUCT_NAME"
exit 1
fi
# Install the app
print_info "Installing AxePlayground app on simulator..."
if [[ "$VERBOSE" == true ]]; then
xcrun simctl install "$SIMULATOR_UDID" "$APP_PATH"
else
xcrun simctl install "$SIMULATOR_UDID" "$APP_PATH" > /dev/null 2>&1
fi
print_success "Playground app built and installed successfully"
print_info "App path: $APP_PATH"
}
# Function to run tests
run_tests() {
print_header "Running Tests"
# Set up environment
export SIMULATOR_UDID="$SIMULATOR_UDID"
export AXE_E2E=1
print_info "Environment: SIMULATOR_UDID=$SIMULATOR_UDID, AXE_E2E=$AXE_E2E"
run_swift_test() {
local filter="$1"
local cmd="swift test --filter $filter"
if [[ "$VERBOSE" == true ]]; then
cmd="$cmd --verbose"
fi
print_info "Test command: $cmd"
eval "$cmd"
}
if [[ -n "$TEST_FILTER" ]]; then
print_info "Running test filter: $TEST_FILTER"
echo ""
if run_swift_test "$TEST_FILTER"; then
print_success "Selected tests passed"
else
print_error "Selected tests failed"
exit 1
fi
return
fi
if [[ "$SEQUENTIAL" == true ]]; then
print_info "Running E2E suites one-by-one to avoid simulator contention"
local suites=(
"BatchTests"
"ButtonTests"
"DescribeUITests"
"GestureTests"
"InitTests"
"KeyComboTests"
"KeySequenceTests"
"KeyTests"
"ListSimulatorsTests"
"RecordVideoTests"
"StreamVideoDebugTests"
"StreamVideoTests"
"SwipeTests"
"TapTests"
"TouchTests"
"TypeTests"
)
echo ""
for suite in "${suites[@]}"; do
print_header "Running $suite"
if ! run_swift_test "$suite"; then
print_error "$suite failed"
exit 1
fi
done
print_success "All test suites passed"
return
fi
print_info "Running all tests"
local test_cmd="swift test"
if [[ "$VERBOSE" == true ]]; then
test_cmd="$test_cmd --verbose"
fi
print_info "Test command: $test_cmd"
echo ""
if eval "$test_cmd"; then
print_success "All tests passed"
else
print_error "Some tests failed"
exit 1
fi
}
# Function to show summary
show_summary() {
print_header "Summary"
if [[ "$BUILD_ONLY" == true ]]; then
print_success "Build completed successfully"
print_info "AXe executable: $(swift build --show-bin-path)/axe"
print_info "Playground app installed on: $SIMULATOR_NAME ($SIMULATOR_UDID)"
elif [[ "$TESTS_ONLY" == true ]]; then
if [[ -n "$TEST_FILTER" ]]; then
print_success "Test suite '$TEST_FILTER' completed successfully"
else
print_success "All test suites completed successfully"
fi
else
print_success "Build and test cycle completed successfully"
print_info "AXe executable: $(swift build --show-bin-path)/axe"
print_info "Playground app: Installed and tested on $SIMULATOR_NAME"
if [[ -n "$TEST_FILTER" ]]; then
print_info "Test suite: $TEST_FILTER"
else
print_info "Test coverage: All test suites"
fi
fi
}
# Main execution
main() {
print_header "AXe Test Runner"
print_info "Starting automated build and test cycle..."
# Always check prerequisites
check_prerequisites
# Always boot simulator (needed for both building and testing)
boot_simulator
if [[ "$TESTS_ONLY" != true ]]; then
clean_build
build_axe
build_playground_app
fi
if [[ "$BUILD_ONLY" != true ]]; then
run_tests
fi
show_summary
}
# Run main function
main "$@"