forked from bitrise-steplib/steps-xcode-test
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain_test.go
More file actions
485 lines (437 loc) · 15.3 KB
/
Copy pathmain_test.go
File metadata and controls
485 lines (437 loc) · 15.3 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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
package main
import (
"io/ioutil"
"testing"
shellquote "github.com/kballard/go-shellquote"
)
func TestParseCommandLineOptions(t *testing.T) {
t.Log("Parse complicated command")
{
expectedWords := []string{"/bin/sh", "-c", `echo "my complicated command" | tee log | cat > log2`}
words, err := shellquote.Split("/bin/sh -c 'echo \"my complicated command\" | tee log | cat > log2'")
if err != nil {
t.Fatalf("Expected (no error), actual(%v)", err)
}
if len(words) != len(expectedWords) {
t.Fatalf("Expected (%d), actual(%d)", len(expectedWords), len(words))
}
for i := 0; i < len(expectedWords); i++ {
exceptedWord := expectedWords[i]
word := words[i]
if word != exceptedWord {
t.Fatalf("Expected (%s), actual(%s)", exceptedWord, word)
}
}
}
t.Log("Parse invalid command")
{
_, err := shellquote.Split("/bin/sh -c 'echo")
if err == nil {
t.Fatalf("Expected (error), actual(%v)", err)
}
}
}
func Test_isStringFoundInOutput(t *testing.T) {
t.Log("Should NOT find")
{
searchPattern := "something"
isShouldFind := false
for _, anOutStr := range []string{
"",
"a",
"1",
"somethin",
"somethinx",
"TEST FAILED",
} {
if isFound := isStringFoundInOutput(searchPattern, anOutStr); isFound != isShouldFind {
t.Logf("Search pattern was: %s", searchPattern)
t.Logf("Input string to search in was: %s", anOutStr)
t.Fatalf("Expected (%v), actual (%v)", isShouldFind, isFound)
}
}
}
t.Log("Should find")
{
searchPattern := "search for this"
isShouldFind := true
for _, anOutStr := range []string{
"search for this",
"-search for this",
"search for this-",
"-search for this-",
} {
if isFound := isStringFoundInOutput(searchPattern, anOutStr); isFound != isShouldFind {
t.Logf("Search pattern was: %s", searchPattern)
t.Logf("Input string to search in was: %s", anOutStr)
t.Fatalf("Expected (%v), actual (%v)", isShouldFind, isFound)
}
}
}
t.Log("Should find - empty pattern - always yes")
{
searchPattern := ""
isShouldFind := true
for _, anOutStr := range []string{
"",
"a",
"1",
"TEST FAILED",
} {
if isFound := isStringFoundInOutput(searchPattern, anOutStr); isFound != isShouldFind {
t.Logf("Search pattern was: %s", searchPattern)
t.Logf("Input string to search in was: %s", anOutStr)
t.Fatalf("Expected (%v), actual (%v)", isShouldFind, isFound)
}
}
}
}
func TestIsStringFoundInOutput_timedOutRegisteringForTestingEvent(t *testing.T) {
t.Log("load sample logs")
{
}
sampleTestRunnerLog, err := loadFileContent("./_samples/xcodebuild-timed-out-registering-for-testing-event.txt")
if err != nil {
t.Fatalf("Failed to load error sample log : %s", err)
}
sampleOKBuildLog, err := loadFileContent("./_samples/xcodebuild-ok.txt")
if err != nil {
t.Fatalf("Failed to load xcodebuild-ok.txt : %s", err)
}
t.Log("Should find")
{
for _, anOutStr := range []string{
"Timed out registering for testing event accessibility notifications",
".timed out registering for testing event accessibility notifications.",
"(Timed out registering for testing event accessibility notifications)",
"aaaTimed out registering for testing event accessibility notifications... test test test",
"aaa timed out registering for testing event accessibility notificationstest",
sampleTestRunnerLog,
} {
timedOutRegisteringForTestingEventWith(t, anOutStr, true)
}
}
t.Log("Should NOT find")
{
for _, anOutStr := range []string{
"",
"accessibility",
"timed out",
sampleOKBuildLog,
} {
timedOutRegisteringForTestingEventWith(t, anOutStr, false)
}
}
}
func TestIsStringFoundInOutput_testRunnerFailedToInitializeForUITesting(t *testing.T) {
t.Log("load sample logs")
{
}
sampleTestRunnerLog, err := loadFileContent("./_samples/xcodebuild-test-runner-failed-to-initialize-for-ui-testing.txt")
if err != nil {
t.Fatalf("Failed to load error sample log : %s", err)
}
sampleOKBuildLog, err := loadFileContent("./_samples/xcodebuild-ok.txt")
if err != nil {
t.Fatalf("Failed to load xcodebuild-ok.txt : %s", err)
}
t.Log("Should find")
{
for _, anOutStr := range []string{
"test runner failed to initialize for ui testing",
"Test runner failed to initialize for ui testing.",
"Test runner failed to initialize for UI testing, test test test",
"aaaTest runner failed to initialize for UI testing... test test test",
"aaa Test runner failed to initialize for UI testingtest",
sampleTestRunnerLog,
} {
testRunnerFailedToInitializeForUITestingWith(t, anOutStr, true)
}
}
t.Log("Should NOT find")
{
for _, anOutStr := range []string{
"",
"UI testing:",
"test runner failed",
sampleOKBuildLog,
} {
testRunnerFailedToInitializeForUITestingWith(t, anOutStr, false)
}
}
}
func TestIsStringFoundInOutput_timeOutMessageIPhoneSimulator(t *testing.T) {
t.Log("load sample logs")
{
}
sampleIPhoneSimulatorLog, err := loadFileContent("./_samples/xcodebuild-iPhoneSimulator-timeout.txt")
if err != nil {
t.Fatalf("Failed to load error sample log : %s", err)
}
sampleOKBuildLog, err := loadFileContent("./_samples/xcodebuild-ok.txt")
if err != nil {
t.Fatalf("Failed to load xcodebuild-ok.txt : %s", err)
}
t.Log("Should find")
{
for _, anOutStr := range []string{
"iPhoneSimulator: Timed out waiting",
"iphoneSimulator: timed out waiting",
"iphoneSimulator: timed out waiting, test test test",
"aaaiphoneSimulator: timed out waiting, test test test",
"aaa iphoneSimulator: timed out waiting, test test test",
sampleIPhoneSimulatorLog,
} {
testIPhoneSimulatorTimeoutWith(t, anOutStr, true)
}
}
t.Log("Should NOT find")
{
for _, anOutStr := range []string{
"",
"iphoneSimulator:",
sampleOKBuildLog,
} {
testIPhoneSimulatorTimeoutWith(t, anOutStr, false)
}
}
}
func TestIsStringFoundInOutput_timeOutMessageUITest(t *testing.T) {
// load sample logs
sampleUITestTimeoutLog, err := loadFileContent("./_samples/xcodebuild-UITest-timeout.txt")
if err != nil {
t.Fatalf("Failed to load error sample log : %s", err)
}
sampleOKBuildLog, err := loadFileContent("./_samples/xcodebuild-ok.txt")
if err != nil {
t.Fatalf("Failed to load xcodebuild-ok.txt : %s", err)
}
t.Log("Should find")
{
for _, anOutStr := range []string{
"Terminating app due to uncaught exception '_XCTestCaseInterruptionException'",
"terminating app due to uncaught exception '_XCTestCaseInterruptionException'",
"aaTerminating app due to uncaught exception '_XCTestCaseInterruptionException'aa",
"aa Terminating app due to uncaught exception '_XCTestCaseInterruptionException' aa",
sampleUITestTimeoutLog,
} {
testTimeOutMessageUITestWith(t, anOutStr, true)
}
}
t.Log("Should NOT find")
{
for _, anOutStr := range []string{
"",
"Terminating app due to uncaught exception",
"_XCTestCaseInterruptionException",
sampleOKBuildLog,
} {
testTimeOutMessageUITestWith(t, anOutStr, false)
}
}
}
func TestIsStringFoundInOutput_earlyUnexpectedExit(t *testing.T) {
// load sample logs
sampleUITestEarlyUnexpectedExit1, err := loadFileContent("./_samples/xcodebuild-early-unexpected-exit_1.txt")
if err != nil {
t.Fatalf("Failed to load error sample log : %s", err)
}
sampleUITestEarlyUnexpectedExit2, err := loadFileContent("./_samples/xcodebuild-early-unexpected-exit_2.txt")
if err != nil {
t.Fatalf("Failed to load error sample log : %s", err)
}
sampleOKBuildLog, err := loadFileContent("./_samples/xcodebuild-ok.txt")
if err != nil {
t.Fatalf("Failed to load xcodebuild-ok.txt : %s", err)
}
t.Log("Should find")
{
for _, anOutStr := range []string{
"Early unexpected exit, operation never finished bootstrapping - no restart will be attempted",
"Test target ios-xcode-8.0UITests encountered an error (Early unexpected exit, operation never finished bootstrapping - no restart will be attempted)",
"aaEarly unexpected exit, operation never finished bootstrapping - no restart will be attemptedaa",
"aa Early unexpected exit, operation never finished bootstrapping - no restart will be attempted aa",
sampleUITestEarlyUnexpectedExit1,
sampleUITestEarlyUnexpectedExit2,
} {
testEarlyUnexpectedExitMessageUITestWith(t, anOutStr, true)
}
}
t.Log("Should NOT find")
{
for _, anOutStr := range []string{
"",
"Early unexpected exit, operation never finished bootstrapping",
"no restart will be attempted",
sampleOKBuildLog,
} {
testEarlyUnexpectedExitMessageUITestWith(t, anOutStr, false)
}
}
}
func TestIsStringFoundInOutput_failureAttemptingToLaunch(t *testing.T) {
// load sample logs
sampleUITestFailureAttemptingToLaunch, err := loadFileContent("./_samples/xcodebuild-failure-attempting-tolaunch.txt")
if err != nil {
t.Fatalf("Failed to load error sample log : %s", err)
}
sampleOKBuildLog, err := loadFileContent("./_samples/xcodebuild-ok.txt")
if err != nil {
t.Fatalf("Failed to load xcodebuild-ok.txt : %s", err)
}
t.Log("Should find")
{
for _, anOutStr := range []string{
"Assertion Failure: <unknown>:0: UI Testing Failure - Failure attempting to launch <XCUIApplicationImpl:",
"t = 46.77s Assertion Failure: <unknown>:0: UI Testing Failure - Failure attempting to launch <XCUIApplicationImpl: 0x608000423da0 io.bitrise.ios-xcode-8-0 at ",
"aaAssertion Failure: <unknown>:0: UI Testing Failure - Failure attempting to launch <XCUIApplicationImpl:aa",
"aa Assertion Failure: <unknown>:0: UI Testing Failure - Failure attempting to launch <XCUIApplicationImpl: aa",
sampleUITestFailureAttemptingToLaunch,
} {
testFailureAttemptingToLaunch(t, anOutStr, true)
}
}
t.Log("Should NOT find")
{
for _, anOutStr := range []string{
"",
"Assertion Failure:",
"Failure attempting to launch <XCUIApplicationImpl:",
sampleOKBuildLog,
} {
testFailureAttemptingToLaunch(t, anOutStr, false)
}
}
}
func TestIsStringFoundInOutput_failedToBackgroundTestRunner(t *testing.T) {
// load sample logs
sampleUITestFailedToBackgroundTestRunner, err := loadFileContent("./_samples/xcodebuild-failed-to-background-test-runner.txt")
if err != nil {
t.Fatalf("Failed to load error sample log : %s", err)
}
sampleOKBuildLog, err := loadFileContent("./_samples/xcodebuild-ok.txt")
if err != nil {
t.Fatalf("Failed to load xcodebuild-ok.txt : %s", err)
}
t.Log("Should find")
{
for _, anOutStr := range []string{
`Error Domain=IDETestOperationsObserverErrorDomain Code=12 "Failed to background test runner.`,
`2016-09-26 01:14:08.896 xcodebuild[1299:5953] Error Domain=IDETestOperationsObserverErrorDomain Code=12 "Failed to background test runner. If you believe this error represents a bug, please attach the log file at`,
`aaError Domain=IDETestOperationsObserverErrorDomain Code=12 "Failed to background test runner.aa`,
`aa Error Domain=IDETestOperationsObserverErrorDomain Code=12 "Failed to background test runner. aa`,
sampleUITestFailedToBackgroundTestRunner,
} {
testfailedToBackgroundTestRunner(t, anOutStr, true)
}
}
t.Log("Should NOT find")
{
for _, anOutStr := range []string{
"",
"Assertion Failure:",
"Failure attempting to launch <XCUIApplicationImpl:",
sampleOKBuildLog,
} {
testFailureAttemptingToLaunch(t, anOutStr, false)
}
}
}
func TestIsStringFoundInOutput_appStateIsStillNotRunning(t *testing.T) {
// load sample logs
sampleOKBuildLog, err := loadFileContent("./_samples/xcodebuild-ok.txt")
if err != nil {
t.Fatalf("Failed to load xcodebuild-ok.txt : %s", err)
}
t.Log("Should find")
{
for _, anOutStr := range []string{
`App state is still not running active, state = XCApplicationStateNotRunning`,
`---App state is still not running active, state = XCApplicationStateNotRunning---`,
`Asdf.SchemeUITests
testThis, UI Testing Failure - '<XCUIApplicationImpl: 0x600000433440 com.this.Scheme.Target at /Users/vagrant/Library/Developer/Xcode/DerivedData/App-bfkuwgxmaiprwncotahtjjhoigbm/Build/Products/Debug-iphonesimulator/TheApp.app>' App state is still not running active, state = XCApplicationStateNotRunning
MyAppUITests.swift:32`,
} {
testIsFoundWith(t, appStateIsStillNotRunning, anOutStr, true)
}
}
t.Log("Should NOT find")
{
for _, anOutStr := range []string{
"",
`App state is still not running active, state = XCApplicationStateXXX`,
sampleOKBuildLog,
} {
testIsFoundWith(t, appStateIsStillNotRunning, anOutStr, false)
}
}
}
func TestIsStringFoundInOutput_appAccessibilityIsNotLoaded(t *testing.T) {
// load sample logs
sampleOKBuildLog, err := loadFileContent("./_samples/xcodebuild-ok.txt")
if err != nil {
t.Fatalf("Failed to load xcodebuild-ok.txt : %s", err)
}
t.Log("Should find")
{
for _, anOutStr := range []string{
`UI Testing Failure - App accessibility isn't loaded`,
`---UI Testing Failure - App accessibility isn't loaded---`,
` t = 65.80s Assertion Failure: LivescoreAppUITests.swift:23: UI Testing Failure - App accessibility isn't loaded`,
` t = 0.02s Launch com.tapdm.LiveScore.WhatsTheScore
t = 5.06s Waiting for accessibility to load
t = 65.80s Assertion Failure: LivescoreAppUITests.swift:23: UI Testing Failure - App accessibility isn't loaded
t = 65.81s Tear Down`,
} {
testIsFoundWith(t, appAccessibilityIsNotLoaded, anOutStr, true)
}
}
t.Log("Should NOT find")
{
for _, anOutStr := range []string{
"",
`UI Testing Failure`,
`App accessibility isn't loaded`,
sampleOKBuildLog,
} {
testIsFoundWith(t, appAccessibilityIsNotLoaded, anOutStr, false)
}
}
}
//
// TESTING UTILITY FUNCS
func testIsFoundWith(t *testing.T, searchPattern, outputToSearchIn string, isShouldFind bool) {
if isFound := isStringFoundInOutput(searchPattern, outputToSearchIn); isFound != isShouldFind {
t.Logf("Search pattern was: %s", searchPattern)
t.Logf("Input string to search in was: %s", outputToSearchIn)
t.Fatalf("Expected (%v), actual (%v)", isShouldFind, isFound)
}
}
func testRunnerFailedToInitializeForUITestingWith(t *testing.T, outputToSearchIn string, isShouldFind bool) {
testIsFoundWith(t, testRunnerFailedToInitializeForUITesting, outputToSearchIn, isShouldFind)
}
func timedOutRegisteringForTestingEventWith(t *testing.T, outputToSearchIn string, isShouldFind bool) {
testIsFoundWith(t, timedOutRegisteringForTestingEvent, outputToSearchIn, isShouldFind)
}
func testIPhoneSimulatorTimeoutWith(t *testing.T, outputToSearchIn string, isShouldFind bool) {
testIsFoundWith(t, timeOutMessageIPhoneSimulator, outputToSearchIn, isShouldFind)
}
func testTimeOutMessageUITestWith(t *testing.T, outputToSearchIn string, isShouldFind bool) {
testIsFoundWith(t, timeOutMessageUITest, outputToSearchIn, isShouldFind)
}
func testEarlyUnexpectedExitMessageUITestWith(t *testing.T, outputToSearchIn string, isShouldFind bool) {
testIsFoundWith(t, earlyUnexpectedExit, outputToSearchIn, isShouldFind)
}
func testFailureAttemptingToLaunch(t *testing.T, outputToSearchIn string, isShouldFind bool) {
testIsFoundWith(t, failureAttemptingToLaunch, outputToSearchIn, isShouldFind)
}
func testfailedToBackgroundTestRunner(t *testing.T, outputToSearchIn string, isShouldFind bool) {
testIsFoundWith(t, failedToBackgroundTestRunner, outputToSearchIn, isShouldFind)
}
func loadFileContent(filePth string) (string, error) {
fileBytes, err := ioutil.ReadFile(filePth)
if err != nil {
return "", err
}
return string(fileBytes), nil
}