xcode_test.dart 44.3 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
import 'dart:async';

7
import 'package:flutter_tools/src/artifacts.dart';
8
import 'package:flutter_tools/src/base/io.dart' show ProcessException;
9
import 'package:flutter_tools/src/base/logger.dart';
10
import 'package:flutter_tools/src/base/platform.dart';
11
import 'package:flutter_tools/src/base/version.dart';
12
import 'package:flutter_tools/src/build_info.dart';
13
import 'package:flutter_tools/src/cache.dart';
14
import 'package:flutter_tools/src/device.dart';
15
import 'package:flutter_tools/src/ios/devices.dart';
16
import 'package:flutter_tools/src/ios/iproxy.dart';
17
import 'package:flutter_tools/src/ios/xcodeproj.dart';
18
import 'package:flutter_tools/src/macos/xcdevice.dart';
19
import 'package:flutter_tools/src/macos/xcode.dart';
20
import 'package:test/fake.dart';
21

22 23
import '../../src/common.dart';
import '../../src/context.dart';
24
import '../../src/fake_process_manager.dart';
25 26

void main() {
27
  late BufferLogger logger;
28 29

  setUp(() {
30
    logger = BufferLogger.test();
31 32
  });

33
  group('FakeProcessManager', () {
34
    late FakeProcessManager fakeProcessManager;
35

36
    setUp(() {
37
      fakeProcessManager = FakeProcessManager.empty();
38 39
    });

40
    group('Xcode', () {
41
      late FakeXcodeProjectInterpreter xcodeProjectInterpreter;
42 43

      setUp(() {
44
        xcodeProjectInterpreter = FakeXcodeProjectInterpreter();
45 46 47
      });

      testWithoutContext('isInstalledAndMeetsVersionCheck is false when not macOS', () {
48
        final Xcode xcode = Xcode.test(
49
          platform: FakePlatform(operatingSystem: 'windows'),
50
          processManager: fakeProcessManager,
51
          xcodeProjectInterpreter: xcodeProjectInterpreter,
52
        );
53

54
        expect(xcode.isInstalledAndMeetsVersionCheck, isFalse);
55 56
      });

57 58 59 60 61 62 63
      testWithoutContext('isSimctlInstalled is true when simctl list succeeds', () {
        fakeProcessManager.addCommand(
          const FakeCommand(
            command: <String>[
              'xcrun',
              'simctl',
              'list',
64 65
              'devices',
              'booted',
66 67 68
            ],
          ),
        );
69
        final Xcode xcode = Xcode.test(
70
          processManager: fakeProcessManager,
71
          xcodeProjectInterpreter: xcodeProjectInterpreter,
72 73 74
        );

        expect(xcode.isSimctlInstalled, isTrue);
75
        expect(fakeProcessManager, hasNoRemainingExpectations);
76 77 78 79 80 81 82 83 84
      });

      testWithoutContext('isSimctlInstalled is true when simctl list fails', () {
        fakeProcessManager.addCommand(
          const FakeCommand(
            command: <String>[
              'xcrun',
              'simctl',
              'list',
85 86
              'devices',
              'booted',
87 88 89 90
            ],
            exitCode: 1,
          ),
        );
91
        final Xcode xcode = Xcode.test(
92
          processManager: fakeProcessManager,
93
          xcodeProjectInterpreter: xcodeProjectInterpreter,
94 95 96
        );

        expect(xcode.isSimctlInstalled, isFalse);
97
        expect(fakeProcessManager, hasNoRemainingExpectations);
98 99
      });

100
      group('macOS', () {
101
        late Xcode xcode;
102 103

        setUp(() {
104
          xcodeProjectInterpreter = FakeXcodeProjectInterpreter();
105
          xcode = Xcode.test(
106
            processManager: fakeProcessManager,
107
            xcodeProjectInterpreter: xcodeProjectInterpreter,
108 109
          );
        });
110

111 112 113 114 115
        testWithoutContext('xcodeSelectPath returns path when xcode-select is installed', () {
          const String xcodePath = '/Applications/Xcode8.0.app/Contents/Developer';
          fakeProcessManager.addCommand(const FakeCommand(
            command: <String>['/usr/bin/xcode-select', '--print-path'],
            stdout: xcodePath,
116 117
          ),
          );
118

119
          expect(xcode.xcodeSelectPath, xcodePath);
120
          expect(fakeProcessManager, hasNoRemainingExpectations);
121
        });
122

123 124 125 126 127 128 129
        testWithoutContext('xcodeSelectPath returns null when xcode-select is not installed', () {
          fakeProcessManager.addCommand(const FakeCommand(
            command: <String>['/usr/bin/xcode-select', '--print-path'],
            exception: ProcessException('/usr/bin/xcode-select', <String>['--print-path']),
          ));

          expect(xcode.xcodeSelectPath, isNull);
130
          expect(fakeProcessManager, hasNoRemainingExpectations);
131 132 133 134 135 136 137

          fakeProcessManager.addCommand(FakeCommand(
            command: const <String>['/usr/bin/xcode-select', '--print-path'],
            exception: ArgumentError('Invalid argument(s): Cannot find executable for /usr/bin/xcode-select'),
          ));

          expect(xcode.xcodeSelectPath, isNull);
138
          expect(fakeProcessManager, hasNoRemainingExpectations);
139 140
        });

141
        testWithoutContext('version checks fail when version is less than minimum', () {
142
          xcodeProjectInterpreter.isInstalled = true;
143
          xcodeProjectInterpreter.version = Version(9, null, null);
144

145 146 147 148
          expect(xcode.isRequiredVersionSatisfactory, isFalse);
          expect(xcode.isRecommendedVersionSatisfactory, isFalse);
        });

149
        testWithoutContext('version checks fail when xcodebuild tools are not installed', () {
150
          xcodeProjectInterpreter.isInstalled = false;
151

152
          expect(xcode.isRequiredVersionSatisfactory, isFalse);
153 154 155
          expect(xcode.isRecommendedVersionSatisfactory, isFalse);
        });

156
        testWithoutContext('version checks pass when version meets minimum', () {
157
          xcodeProjectInterpreter.isInstalled = true;
158
          xcodeProjectInterpreter.version = Version(14, null, null);
159

160
          expect(xcode.isRequiredVersionSatisfactory, isTrue);
161 162 163
          expect(xcode.isRecommendedVersionSatisfactory, isTrue);
        });

164
        testWithoutContext('version checks pass when major version exceeds minimum', () {
165
          xcodeProjectInterpreter.isInstalled = true;
166
          xcodeProjectInterpreter.version = Version(15, 0, 0);
167

168
          expect(xcode.isRequiredVersionSatisfactory, isTrue);
169 170 171
          expect(xcode.isRecommendedVersionSatisfactory, isTrue);
        });

172
        testWithoutContext('version checks pass when minor version exceeds minimum', () {
173
          xcodeProjectInterpreter.isInstalled = true;
174
          xcodeProjectInterpreter.version = Version(14, 3, 0);
175

176
          expect(xcode.isRequiredVersionSatisfactory, isTrue);
177 178 179
          expect(xcode.isRecommendedVersionSatisfactory, isTrue);
        });

180
        testWithoutContext('version checks pass when patch version exceeds minimum', () {
181
          xcodeProjectInterpreter.isInstalled = true;
182
          xcodeProjectInterpreter.version = Version(14, 0, 2);
183

184
          expect(xcode.isRequiredVersionSatisfactory, isTrue);
185
          expect(xcode.isRecommendedVersionSatisfactory, isTrue);
186
        });
187

188
        testWithoutContext('isInstalledAndMeetsVersionCheck is false when not installed', () {
189
          xcodeProjectInterpreter.isInstalled = false;
190

191
          expect(xcode.isInstalledAndMeetsVersionCheck, isFalse);
192
          expect(fakeProcessManager, hasNoRemainingExpectations);
193
        });
194

195
        testWithoutContext('isInstalledAndMeetsVersionCheck is false when version not satisfied', () {
196 197
          xcodeProjectInterpreter.isInstalled = true;
          xcodeProjectInterpreter.version = Version(10, 2, 0);
198

199
          expect(xcode.isInstalledAndMeetsVersionCheck, isFalse);
200
          expect(fakeProcessManager, hasNoRemainingExpectations);
201 202
        });

203
        testWithoutContext('isInstalledAndMeetsVersionCheck is true when macOS and installed and version is satisfied', () {
204
          xcodeProjectInterpreter.isInstalled = true;
205
          xcodeProjectInterpreter.version = Version(14, null, null);
206 207

          expect(xcode.isInstalledAndMeetsVersionCheck, isTrue);
208
          expect(fakeProcessManager, hasNoRemainingExpectations);
209
        });
210

211 212 213 214 215 216 217 218 219 220 221
        testWithoutContext('eulaSigned is false when clang output indicates EULA not yet accepted', () {
          fakeProcessManager.addCommands(const <FakeCommand>[
            FakeCommand(
              command: <String>['xcrun', 'clang'],
              exitCode: 1,
              stderr:
                  'Xcode EULA has not been accepted.\nLaunch Xcode and accept the license.',
            ),
          ]);

          expect(xcode.eulaSigned, isFalse);
222
          expect(fakeProcessManager, hasNoRemainingExpectations);
223
        });
224

225 226 227 228 229 230 231 232 233 234 235
        testWithoutContext('eulaSigned is false when clang is not installed', () {
          fakeProcessManager.addCommand(
            const FakeCommand(
              command: <String>['xcrun', 'clang'],
              exception: ProcessException('xcrun', <String>['clang']),
            ),
          );

          expect(xcode.eulaSigned, isFalse);
        });

236 237 238 239 240 241 242 243 244 245 246
        testWithoutContext('eulaSigned is true when clang output indicates EULA has been accepted', () {
          fakeProcessManager.addCommands(
            const <FakeCommand>[
              FakeCommand(
                command: <String>['xcrun', 'clang'],
                exitCode: 1,
                stderr: 'clang: error: no input files',
              ),
            ],
          );
          expect(xcode.eulaSigned, isTrue);
247
          expect(fakeProcessManager, hasNoRemainingExpectations);
248 249 250
        });

        testWithoutContext('SDK name', () {
251 252
          expect(getSDKNameForIOSEnvironmentType(EnvironmentType.physical), 'iphoneos');
          expect(getSDKNameForIOSEnvironmentType(EnvironmentType.simulator), 'iphonesimulator');
253 254 255 256 257 258 259 260 261 262 263
        });

        group('SDK location', () {
          const String sdkroot = 'Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk';

          testWithoutContext('--show-sdk-path iphoneos', () async {
            fakeProcessManager.addCommand(const FakeCommand(
              command: <String>['xcrun', '--sdk', 'iphoneos', '--show-sdk-path'],
              stdout: sdkroot,
            ));

264
            expect(await xcode.sdkLocation(EnvironmentType.physical), sdkroot);
265
            expect(fakeProcessManager, hasNoRemainingExpectations);
266 267 268 269 270 271 272 273 274
          });

          testWithoutContext('--show-sdk-path fails', () async {
            fakeProcessManager.addCommand(const FakeCommand(
              command: <String>['xcrun', '--sdk', 'iphoneos', '--show-sdk-path'],
              exitCode: 1,
              stderr: 'xcrun: error:',
            ));

275
            expect(() async => xcode.sdkLocation(EnvironmentType.physical),
276
              throwsToolExit(message: 'Could not find SDK location'));
277
            expect(fakeProcessManager, hasNoRemainingExpectations);
278 279
          });
        });
280 281 282
      });
    });

283
    group('xcdevice not installed', () {
284 285
      late XCDevice xcdevice;
      late Xcode xcode;
286 287

      setUp(() {
288 289 290 291
        xcode = Xcode.test(
          processManager: FakeProcessManager.any(),
          xcodeProjectInterpreter: XcodeProjectInterpreter.test(
            processManager: FakeProcessManager.any(),
292
            version: null, // Not installed.
293 294
          ),
        );
295 296 297
        xcdevice = XCDevice(
          processManager: fakeProcessManager,
          logger: logger,
298
          xcode: xcode,
299
          platform: FakePlatform(operatingSystem: 'macos'),
300
          artifacts: Artifacts.test(),
301
          cache: Cache.test(processManager: FakeProcessManager.any()),
302
          iproxy: IProxy.test(logger: logger, processManager: fakeProcessManager),
303
        );
304 305
      });

306 307 308 309 310 311 312 313
      testWithoutContext('Xcode not installed', () async {
        expect(xcode.isInstalled, false);

        expect(xcdevice.isInstalled, false);
        expect(xcdevice.observedDeviceEvents(), isNull);
        expect(logger.traceText, contains("Xcode not found. Run 'flutter doctor' for more information."));
        expect(await xcdevice.getAvailableIOSDevices(), isEmpty);
        expect(await xcdevice.getDiagnostics(), isEmpty);
314
      });
315
    });
316

317
    group('xcdevice', () {
318 319
      late XCDevice xcdevice;
      late Xcode xcode;
320

321 322 323 324 325 326
      setUp(() {
        xcode = Xcode.test(processManager: FakeProcessManager.any());
        xcdevice = XCDevice(
          processManager: fakeProcessManager,
          logger: logger,
          xcode: xcode,
327
          platform: FakePlatform(operatingSystem: 'macos'),
328
          artifacts: Artifacts.test(),
329
          cache: Cache.test(processManager: FakeProcessManager.any()),
330 331 332
          iproxy: IProxy.test(logger: logger, processManager: fakeProcessManager),
        );
      });
333

334
      group('observe device events', () {
335 336 337 338 339 340 341 342 343 344
        testUsingContext('relays events', () async {
          fakeProcessManager.addCommand(const FakeCommand(
            command: <String>[
              'script',
              '-t',
              '0',
              '/dev/null',
              'xcrun',
              'xcdevice',
              'observe',
345 346 347
              '--usb',
            ], stdout: 'Listening for all devices, on USB.\n'
              'Attach: d83d5bc53967baa0ee18626ba87b6254b2ab5418\n'
348 349
              'Attach: 00008027-00192736010F802E\n'
              'Detach: d83d5bc53967baa0ee18626ba87b6254b2ab5418',
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
            stderr: 'Some usb error',
          ));

          fakeProcessManager.addCommand(const FakeCommand(
            command: <String>[
              'script',
              '-t',
              '0',
              '/dev/null',
              'xcrun',
              'xcdevice',
              'observe',
              '--wifi',
            ], stdout: 'Listening for all devices, on WiFi.\n'
              'Attach: 00000001-0000000000000000\n'
              'Detach: 00000001-0000000000000000',
            stderr: 'Some wifi error',
367 368
          ));

369 370 371
          final Completer<void> attach1 = Completer<void>();
          final Completer<void> attach2 = Completer<void>();
          final Completer<void> detach1 = Completer<void>();
372 373
          final Completer<void> attach3 = Completer<void>();
          final Completer<void> detach2 = Completer<void>();
374 375

          // Attach: d83d5bc53967baa0ee18626ba87b6254b2ab5418
376
          // Attach: 00008027-00192736010F802E
377
          // Detach: d83d5bc53967baa0ee18626ba87b6254b2ab5418
378 379 380
          xcdevice.observedDeviceEvents()!.listen((XCDeviceEventNotification event) {
            if (event.eventType == XCDeviceEvent.attach) {
              if (event.deviceIdentifier == 'd83d5bc53967baa0ee18626ba87b6254b2ab5418') {
381 382
                attach1.complete();
              } else
383
              if (event.deviceIdentifier == '00008027-00192736010F802E') {
384 385
                attach2.complete();
              }
386 387 388 389 390 391 392 393 394 395
              if (event.deviceIdentifier == '00000001-0000000000000000') {
                attach3.complete();
              }
            } else if (event.eventType == XCDeviceEvent.detach) {
              if (event.deviceIdentifier == 'd83d5bc53967baa0ee18626ba87b6254b2ab5418') {
                detach1.complete();
              }
              if (event.deviceIdentifier == '00000001-0000000000000000') {
                detach2.complete();
              }
396 397 398 399
            } else {
              fail('Unexpected event');
            }
          });
400 401 402
          await attach1.future;
          await attach2.future;
          await detach1.future;
403 404 405 406
          await attach3.future;
          await detach2.future;
          expect(logger.errorText, contains('xcdevice observe --usb: Some usb error'));
          expect(logger.errorText, contains('xcdevice observe --wifi: Some wifi error'));
407
        });
408 409 410 411 412 413 414 415 416 417 418

        testUsingContext('handles exit code', () async {
          fakeProcessManager.addCommand(const FakeCommand(
            command: <String>[
              'script',
              '-t',
              '0',
              '/dev/null',
              'xcrun',
              'xcdevice',
              'observe',
419 420 421 422 423 424 425 426 427 428 429 430 431
              '--usb',
            ],
          ));
          fakeProcessManager.addCommand(const FakeCommand(
            command: <String>[
              'script',
              '-t',
              '0',
              '/dev/null',
              'xcrun',
              'xcdevice',
              'observe',
              '--wifi',
432
            ],
433
            exitCode: 1,
434 435 436 437 438 439 440
          ));

          final Completer<void> doneCompleter = Completer<void>();
          xcdevice.observedDeviceEvents()!.listen(null, onDone: () {
            doneCompleter.complete();
          });
          await doneCompleter.future;
441 442
          expect(logger.traceText, contains('xcdevice observe --usb exited with code 0'));
          expect(logger.traceText, contains('xcdevice observe --wifi exited with code 0'));
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462
        });

      });

      group('wait device events', () {
        testUsingContext('relays events', () async {
          const String deviceId = '00000001-0000000000000000';

          fakeProcessManager.addCommand(const FakeCommand(
            command: <String>[
              'script',
              '-t',
              '0',
              '/dev/null',
              'xcrun',
              'xcdevice',
              'wait',
              '--usb',
              deviceId,
            ],
463
            stdout: 'Waiting for $deviceId to appear, on USB.\n',
464 465 466 467 468 469 470 471 472 473 474 475 476
          ));
          fakeProcessManager.addCommand(const FakeCommand(
            command: <String>[
              'script',
              '-t',
              '0',
              '/dev/null',
              'xcrun',
              'xcdevice',
              'wait',
              '--wifi',
              deviceId,
            ],
477 478 479
            stdout:
            'Waiting for $deviceId to appear, on WiFi.\n'
            'Attach: 00000001-0000000000000000\n',
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506
          ));

          // Attach: 00000001-0000000000000000

          final XCDeviceEventNotification? event = await xcdevice.waitForDeviceToConnect(deviceId);

          expect(event?.deviceIdentifier, deviceId);
          expect(event?.eventInterface, XCDeviceEventInterface.wifi);
          expect(event?.eventType, XCDeviceEvent.attach);
        });

        testUsingContext('handles exit code', () async {
          const String deviceId = '00000001-0000000000000000';

          fakeProcessManager.addCommand(const FakeCommand(
            command: <String>[
              'script',
              '-t',
              '0',
              '/dev/null',
              'xcrun',
              'xcdevice',
              'wait',
              '--usb',
              deviceId,
            ],
            exitCode: 1,
507
            stderr: 'Some error',
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525
          ));
          fakeProcessManager.addCommand(const FakeCommand(
            command: <String>[
              'script',
              '-t',
              '0',
              '/dev/null',
              'xcrun',
              'xcdevice',
              'wait',
              '--wifi',
              deviceId,
            ],
          ));

          final XCDeviceEventNotification? event = await xcdevice.waitForDeviceToConnect(deviceId);

          expect(event, isNull);
526
          expect(logger.errorText, contains('xcdevice wait --usb: Some error'));
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570
          expect(logger.traceText, contains('xcdevice wait --usb exited with code 0'));
          expect(logger.traceText, contains('xcdevice wait --wifi exited with code 0'));
          expect(xcdevice.waitStreamController?.isClosed, isTrue);
        });

        testUsingContext('handles cancel', () async {
          const String deviceId = '00000001-0000000000000000';

          fakeProcessManager.addCommand(const FakeCommand(
            command: <String>[
              'script',
              '-t',
              '0',
              '/dev/null',
              'xcrun',
              'xcdevice',
              'wait',
              '--usb',
              deviceId,
            ],
          ));
          fakeProcessManager.addCommand(const FakeCommand(
            command: <String>[
              'script',
              '-t',
              '0',
              '/dev/null',
              'xcrun',
              'xcdevice',
              'wait',
              '--wifi',
              deviceId,
            ],
          ));

          final Future<XCDeviceEventNotification?> futureEvent = xcdevice.waitForDeviceToConnect(deviceId);
          xcdevice.cancelWaitForDeviceToConnect();
          final XCDeviceEventNotification? event = await futureEvent;

          expect(event, isNull);
          expect(logger.traceText, contains('xcdevice wait --usb exited with code 0'));
          expect(logger.traceText, contains('xcdevice wait --wifi exited with code 0'));
          expect(xcdevice.waitStreamController?.isClosed, isTrue);
        });
571 572
      });

573 574 575 576
      group('available devices', () {
        final FakePlatform macPlatform = FakePlatform(operatingSystem: 'macos');
        testUsingContext('returns devices', () async {
          const String devicesOutput = '''
577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595
[
  {
    "simulator" : true,
    "operatingSystemVersion" : "13.3 (17K446)",
    "available" : true,
    "platform" : "com.apple.platform.appletvsimulator",
    "modelCode" : "AppleTV5,3",
    "identifier" : "CBB5E1ED-2172-446E-B4E7-F2B5823DBBA6",
    "architecture" : "x86_64",
    "modelName" : "Apple TV",
    "name" : "Apple TV"
  },
  {
    "simulator" : false,
    "operatingSystemVersion" : "13.3 (17C54)",
    "interface" : "usb",
    "available" : true,
    "platform" : "com.apple.platform.iphoneos",
    "modelCode" : "iPhone8,1",
596
    "identifier" : "00008027-00192736010F802E",
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668
    "architecture" : "arm64",
    "modelName" : "iPhone 6s",
    "name" : "An iPhone (Space Gray)"
  },
  {
    "simulator" : false,
    "operatingSystemVersion" : "10.1 (14C54)",
    "interface" : "usb",
    "available" : true,
    "platform" : "com.apple.platform.iphoneos",
    "modelCode" : "iPad11,4",
    "identifier" : "98206e7a4afd4aedaff06e687594e089dede3c44",
    "architecture" : "armv7",
    "modelName" : "iPad Air 3rd Gen",
    "name" : "iPad 1"
  },
  {
    "simulator" : false,
    "operatingSystemVersion" : "10.1 (14C54)",
    "interface" : "network",
    "available" : true,
    "platform" : "com.apple.platform.iphoneos",
    "modelCode" : "iPad11,4",
    "identifier" : "234234234234234234345445687594e089dede3c44",
    "architecture" : "arm64",
    "modelName" : "iPad Air 3rd Gen",
    "name" : "A networked iPad"
  },
  {
    "simulator" : false,
    "operatingSystemVersion" : "10.1 (14C54)",
    "interface" : "usb",
    "available" : true,
    "platform" : "com.apple.platform.iphoneos",
    "modelCode" : "iPad11,4",
    "identifier" : "f577a7903cc54959be2e34bc4f7f80b7009efcf4",
    "architecture" : "BOGUS",
    "modelName" : "iPad Air 3rd Gen",
    "name" : "iPad 2"
  },
  {
    "simulator" : true,
    "operatingSystemVersion" : "6.1.1 (17S445)",
    "available" : true,
    "platform" : "com.apple.platform.watchsimulator",
    "modelCode" : "Watch5,4",
    "identifier" : "2D74FB11-88A0-44D0-B81E-C0C142B1C94A",
    "architecture" : "i386",
    "modelName" : "Apple Watch Series 5 - 44mm",
    "name" : "Apple Watch Series 5 - 44mm"
  },
  {
    "simulator" : false,
    "operatingSystemVersion" : "13.3 (17C54)",
    "interface" : "usb",
    "available" : false,
    "platform" : "com.apple.platform.iphoneos",
    "modelCode" : "iPhone8,1",
    "identifier" : "c4ca6f7a53027d1b7e4972e28478e7a28e2faee2",
    "architecture" : "arm64",
    "modelName" : "iPhone 6s",
    "name" : "iPhone",
    "error" : {
      "code" : -9,
      "failureReason" : "",
      "description" : "iPhone is not paired with your computer.",
      "domain" : "com.apple.platform.iphoneos"
    }
  }
]
''';

669 670 671 672
          fakeProcessManager.addCommand(const FakeCommand(
            command: <String>['xcrun', 'xcdevice', 'list', '--timeout', '2'],
            stdout: devicesOutput,
          ));
673
          final List<IOSDevice> devices = await xcdevice.getAvailableIOSDevices();
674
          expect(devices, hasLength(5));
675
          expect(devices[0].id, '00008027-00192736010F802E');
676
          expect(devices[0].name, 'An iPhone (Space Gray)');
677
          expect(await devices[0].sdkNameAndVersion, 'iOS 13.3 17C54');
678
          expect(devices[0].cpuArchitecture, DarwinArch.arm64);
679
          expect(devices[0].connectionInterface, DeviceConnectionInterface.attached);
680
          expect(devices[0].isConnected, true);
681

682 683
          expect(devices[1].id, '98206e7a4afd4aedaff06e687594e089dede3c44');
          expect(devices[1].name, 'iPad 1');
684
          expect(await devices[1].sdkNameAndVersion, 'iOS 10.1 14C54');
685
          expect(devices[1].cpuArchitecture, DarwinArch.armv7);
686
          expect(devices[1].connectionInterface, DeviceConnectionInterface.attached);
687
          expect(devices[1].isConnected, true);
688

689 690
          expect(devices[2].id, '234234234234234234345445687594e089dede3c44');
          expect(devices[2].name, 'A networked iPad');
691
          expect(await devices[2].sdkNameAndVersion, 'iOS 10.1 14C54');
692
          expect(devices[2].cpuArchitecture, DarwinArch.arm64); // Defaults to arm64 for unknown architecture.
693
          expect(devices[2].connectionInterface, DeviceConnectionInterface.wireless);
694
          expect(devices[2].isConnected, true);
695

696 697 698 699
          expect(devices[3].id, 'f577a7903cc54959be2e34bc4f7f80b7009efcf4');
          expect(devices[3].name, 'iPad 2');
          expect(await devices[3].sdkNameAndVersion, 'iOS 10.1 14C54');
          expect(devices[3].cpuArchitecture, DarwinArch.arm64); // Defaults to arm64 for unknown architecture.
700
          expect(devices[3].connectionInterface, DeviceConnectionInterface.attached);
701 702 703 704 705 706 707 708
          expect(devices[3].isConnected, true);

          expect(devices[4].id, 'c4ca6f7a53027d1b7e4972e28478e7a28e2faee2');
          expect(devices[4].name, 'iPhone');
          expect(await devices[4].sdkNameAndVersion, 'iOS 13.3 17C54');
          expect(devices[4].cpuArchitecture, DarwinArch.arm64);
          expect(devices[4].connectionInterface, DeviceConnectionInterface.attached);
          expect(devices[4].isConnected, false);
709

710
          expect(fakeProcessManager, hasNoRemainingExpectations);
711 712
        }, overrides: <Type, Generator>{
          Platform: () => macPlatform,
713
          Artifacts: () => Artifacts.test(),
714 715
        });

716 717 718 719 720 721 722 723 724
        testWithoutContext('available devices xcdevice fails', () async {
          fakeProcessManager.addCommand(const FakeCommand(
            command: <String>['xcrun', 'xcdevice', 'list', '--timeout', '2'],
            exception: ProcessException('xcrun', <String>['xcdevice', 'list', '--timeout', '2']),
          ));

          expect(await xcdevice.getAvailableIOSDevices(), isEmpty);
        });

725 726 727 728 729
        testWithoutContext('uses timeout', () async {
          fakeProcessManager.addCommand(const FakeCommand(
            command: <String>['xcrun', 'xcdevice', 'list', '--timeout', '20'],
            stdout: '[]',
          ));
730
          await xcdevice.getAvailableIOSDevices(timeout: const Duration(seconds: 20));
731
          expect(fakeProcessManager, hasNoRemainingExpectations);
732 733 734 735
        });

        testUsingContext('ignores "Preparing debugger support for iPhone" error', () async {
          const String devicesOutput = '''
736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758
[
  {
    "simulator" : false,
    "operatingSystemVersion" : "13.3 (17C54)",
    "interface" : "usb",
    "available" : false,
    "platform" : "com.apple.platform.iphoneos",
    "modelCode" : "iPhone8,1",
    "identifier" : "43ad2fda7991b34fe1acbda82f9e2fd3d6ddc9f7",
    "architecture" : "arm64",
    "modelName" : "iPhone 6s",
    "name" : "iPhone",
    "error" : {
      "code" : -10,
      "failureReason" : "",
      "description" : "iPhone is busy: Preparing debugger support for iPhone",
      "recoverySuggestion" : "Xcode will continue when iPhone is finished.",
      "domain" : "com.apple.platform.iphoneos"
    }
  }
]
''';

759 760 761 762
          fakeProcessManager.addCommand(const FakeCommand(
            command: <String>['xcrun', 'xcdevice', 'list', '--timeout', '2'],
            stdout: devicesOutput,
          ));
763
          final List<IOSDevice> devices = await xcdevice.getAvailableIOSDevices();
764 765
          expect(devices, hasLength(1));
          expect(devices[0].id, '43ad2fda7991b34fe1acbda82f9e2fd3d6ddc9f7');
766
          expect(fakeProcessManager, hasNoRemainingExpectations);
767 768
        }, overrides: <Type, Generator>{
          Platform: () => macPlatform,
769
          Artifacts: () => Artifacts.test(),
770 771 772 773
        });

        testUsingContext('handles unknown architectures', () async {
          const String devicesOutput = '''
774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793
[
  {
    "simulator" : false,
    "operatingSystemVersion" : "13.3 (17C54)",
    "interface" : "usb",
    "available" : true,
    "platform" : "com.apple.platform.iphoneos",
    "modelCode" : "iPhone8,1",
    "identifier" : "d83d5bc53967baa0ee18626ba87b6254b2ab5418",
    "architecture" : "armv7x",
    "modelName" : "iPad 3 BOGUS",
    "name" : "iPad"
  },
  {
    "simulator" : false,
    "operatingSystemVersion" : "13.3 (17C54)",
    "interface" : "usb",
    "available" : true,
    "platform" : "com.apple.platform.iphoneos",
    "modelCode" : "iPhone8,1",
794
    "identifier" : "43ad2fda7991b34fe1acbda82f9e2fd3d6ddc9f7",
795 796 797 798 799 800 801
    "architecture" : "BOGUS",
    "modelName" : "Future iPad",
    "name" : "iPad"
  }
]
''';

802 803 804 805
          fakeProcessManager.addCommand(const FakeCommand(
            command: <String>['xcrun', 'xcdevice', 'list', '--timeout', '2'],
            stdout: devicesOutput,
          ));
806
          final List<IOSDevice> devices = await xcdevice.getAvailableIOSDevices();
807 808
          expect(devices[0].cpuArchitecture, DarwinArch.armv7);
          expect(devices[1].cpuArchitecture, DarwinArch.arm64);
809
          expect(fakeProcessManager, hasNoRemainingExpectations);
810 811
        }, overrides: <Type, Generator>{
          Platform: () => macPlatform,
812
          Artifacts: () => Artifacts.test(),
813
        });
814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866

        testUsingContext('Sdk Version is parsed correctly',()  async {
          const String devicesOutput = '''
[
  {
    "simulator" : false,
    "operatingSystemVersion" : "13.3 (17C54)",
    "interface" : "usb",
    "available" : true,
    "platform" : "com.apple.platform.iphoneos",
    "modelCode" : "iPhone8,1",
    "identifier" : "00008027-00192736010F802E",
    "architecture" : "arm64",
    "modelName" : "iPhone 6s",
    "name" : "An iPhone (Space Gray)"
  },
  {
    "simulator" : false,
    "operatingSystemVersion" : "10.1",
    "interface" : "usb",
    "available" : true,
    "platform" : "com.apple.platform.iphoneos",
    "modelCode" : "iPad11,4",
    "identifier" : "234234234234234234345445687594e089dede3c44",
    "architecture" : "arm64",
    "modelName" : "iPad Air 3rd Gen",
    "name" : "A networked iPad"
  },
  {
    "simulator" : false,
    "interface" : "usb",
    "available" : true,
    "platform" : "com.apple.platform.iphoneos",
    "modelCode" : "iPad11,4",
    "identifier" : "f577a7903cc54959be2e34bc4f7f80b7009efcf4",
    "architecture" : "BOGUS",
    "modelName" : "iPad Air 3rd Gen",
    "name" : "iPad 2"
  }
]
''';
          fakeProcessManager.addCommand(const FakeCommand(
            command: <String>['xcrun', 'xcdevice', 'list', '--timeout', '2'],
            stdout: devicesOutput,
          ));

          final List<IOSDevice> devices = await xcdevice.getAvailableIOSDevices();
          expect(await devices[0].sdkNameAndVersion,'iOS 13.3 17C54');
          expect(await devices[1].sdkNameAndVersion,'iOS 10.1');
          expect(await devices[2].sdkNameAndVersion,'iOS unknown version');
        }, overrides: <Type, Generator>{
          Platform: () => macPlatform,
        });
867

868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051
        testUsingContext('use connected entry when filtering out duplicates', () async {
          const String devicesOutput = '''
[
  {
    "simulator" : false,
    "operatingSystemVersion" : "13.3 (17C54)",
    "interface" : "usb",
    "available" : false,
    "platform" : "com.apple.platform.iphoneos",
    "modelCode" : "iPhone8,1",
    "identifier" : "c4ca6f7a53027d1b7e4972e28478e7a28e2faee2",
    "architecture" : "arm64",
    "modelName" : "iPhone 6s",
    "name" : "iPhone"
  },
  {
    "simulator" : false,
    "operatingSystemVersion" : "13.3 (17C54)",
    "interface" : "usb",
    "available" : false,
    "platform" : "com.apple.platform.iphoneos",
    "modelCode" : "iPhone8,1",
    "identifier" : "c4ca6f7a53027d1b7e4972e28478e7a28e2faee2",
    "architecture" : "arm64",
    "modelName" : "iPhone 6s",
    "name" : "iPhone",
    "error" : {
      "code" : -13,
      "failureReason" : "",
      "description" : "iPhone iPad is not connected",
      "recoverySuggestion" : "Xcode will continue when iPhone is connected and unlocked.",
      "domain" : "com.apple.platform.iphoneos"
    }
  }
]
''';

          fakeProcessManager.addCommand(const FakeCommand(
            command: <String>['xcrun', 'xcdevice', 'list', '--timeout', '2'],
            stdout: devicesOutput,
          ));
          final List<IOSDevice> devices = await xcdevice.getAvailableIOSDevices();
          expect(devices, hasLength(1));

          expect(devices[0].id, 'c4ca6f7a53027d1b7e4972e28478e7a28e2faee2');
          expect(devices[0].name, 'iPhone');
          expect(await devices[0].sdkNameAndVersion, 'iOS 13.3 17C54');
          expect(devices[0].cpuArchitecture, DarwinArch.arm64);
          expect(devices[0].connectionInterface, DeviceConnectionInterface.attached);
          expect(devices[0].isConnected, true);

          expect(fakeProcessManager, hasNoRemainingExpectations);
        }, overrides: <Type, Generator>{
          Platform: () => macPlatform,
          Artifacts: () => Artifacts.test(),
        });

        testUsingContext('use entry with sdk when filtering out duplicates', () async {
          const String devicesOutput = '''
[
  {
    "simulator" : false,
    "interface" : "usb",
    "available" : false,
    "platform" : "com.apple.platform.iphoneos",
    "modelCode" : "iPhone8,1",
    "identifier" : "c4ca6f7a53027d1b7e4972e28478e7a28e2faee2",
    "architecture" : "arm64",
    "modelName" : "iPhone 6s",
    "name" : "iPhone_1",
    "error" : {
      "code" : -13,
      "failureReason" : "",
      "description" : "iPhone iPad is not connected",
      "recoverySuggestion" : "Xcode will continue when iPhone is connected and unlocked.",
      "domain" : "com.apple.platform.iphoneos"
    }
  },
  {
    "simulator" : false,
    "operatingSystemVersion" : "13.3 (17C54)",
    "interface" : "usb",
    "available" : false,
    "platform" : "com.apple.platform.iphoneos",
    "modelCode" : "iPhone8,1",
    "identifier" : "c4ca6f7a53027d1b7e4972e28478e7a28e2faee2",
    "architecture" : "arm64",
    "modelName" : "iPhone 6s",
    "name" : "iPhone_2",
    "error" : {
      "code" : -13,
      "failureReason" : "",
      "description" : "iPhone iPad is not connected",
      "recoverySuggestion" : "Xcode will continue when iPhone is connected and unlocked.",
      "domain" : "com.apple.platform.iphoneos"
    }
  }
]
''';

          fakeProcessManager.addCommand(const FakeCommand(
            command: <String>['xcrun', 'xcdevice', 'list', '--timeout', '2'],
            stdout: devicesOutput,
          ));
          final List<IOSDevice> devices = await xcdevice.getAvailableIOSDevices();
          expect(devices, hasLength(1));

          expect(devices[0].id, 'c4ca6f7a53027d1b7e4972e28478e7a28e2faee2');
          expect(devices[0].name, 'iPhone_2');
          expect(await devices[0].sdkNameAndVersion, 'iOS 13.3 17C54');
          expect(devices[0].cpuArchitecture, DarwinArch.arm64);
          expect(devices[0].connectionInterface, DeviceConnectionInterface.attached);
          expect(devices[0].isConnected, false);

          expect(fakeProcessManager, hasNoRemainingExpectations);
        }, overrides: <Type, Generator>{
          Platform: () => macPlatform,
          Artifacts: () => Artifacts.test(),
        });

        testUsingContext('use entry with higher sdk when filtering out duplicates', () async {
          const String devicesOutput = '''
[
  {
    "simulator" : false,
    "operatingSystemVersion" : "14.3 (17C54)",
    "interface" : "usb",
    "available" : false,
    "platform" : "com.apple.platform.iphoneos",
    "modelCode" : "iPhone8,1",
    "identifier" : "c4ca6f7a53027d1b7e4972e28478e7a28e2faee2",
    "architecture" : "arm64",
    "modelName" : "iPhone 6s",
    "name" : "iPhone_1",
    "error" : {
      "code" : -13,
      "failureReason" : "",
      "description" : "iPhone iPad is not connected",
      "recoverySuggestion" : "Xcode will continue when iPhone is connected and unlocked.",
      "domain" : "com.apple.platform.iphoneos"
    }
  },
  {
    "simulator" : false,
    "operatingSystemVersion" : "13.3 (17C54)",
    "interface" : "usb",
    "available" : false,
    "platform" : "com.apple.platform.iphoneos",
    "modelCode" : "iPhone8,1",
    "identifier" : "c4ca6f7a53027d1b7e4972e28478e7a28e2faee2",
    "architecture" : "arm64",
    "modelName" : "iPhone 6s",
    "name" : "iPhone_2",
    "error" : {
      "code" : -13,
      "failureReason" : "",
      "description" : "iPhone iPad is not connected",
      "recoverySuggestion" : "Xcode will continue when iPhone is connected and unlocked.",
      "domain" : "com.apple.platform.iphoneos"
    }
  }
]
''';

          fakeProcessManager.addCommand(const FakeCommand(
            command: <String>['xcrun', 'xcdevice', 'list', '--timeout', '2'],
            stdout: devicesOutput,
          ));
          final List<IOSDevice> devices = await xcdevice.getAvailableIOSDevices();
          expect(devices, hasLength(1));

          expect(devices[0].id, 'c4ca6f7a53027d1b7e4972e28478e7a28e2faee2');
          expect(devices[0].name, 'iPhone_1');
          expect(await devices[0].sdkNameAndVersion, 'iOS 14.3 17C54');
          expect(devices[0].cpuArchitecture, DarwinArch.arm64);
          expect(devices[0].connectionInterface, DeviceConnectionInterface.attached);
          expect(devices[0].isConnected, false);

          expect(fakeProcessManager, hasNoRemainingExpectations);
        }, overrides: <Type, Generator>{
          Platform: () => macPlatform,
          Artifacts: () => Artifacts.test(),
        });

1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063
        testUsingContext('handles bad output',()  async {
          fakeProcessManager.addCommand(const FakeCommand(
            command: <String>['xcrun', 'xcdevice', 'list', '--timeout', '2'],
            stdout: 'Something bad happened, not JSON',
          ));

          final List<IOSDevice> devices = await xcdevice.getAvailableIOSDevices();
          expect(devices, isEmpty);
          expect(logger.errorText, contains('xcdevice returned non-JSON response'));
        }, overrides: <Type, Generator>{
          Platform: () => macPlatform,
        });
1064
      });
1065

1066 1067 1068 1069
      group('diagnostics', () {
        final FakePlatform macPlatform = FakePlatform(operatingSystem: 'macos');
        testUsingContext('uses cache', () async {
          const String devicesOutput = '''
1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089
[
  {
    "simulator" : false,
    "operatingSystemVersion" : "13.3 (17C54)",
    "interface" : "network",
    "available" : false,
    "platform" : "com.apple.platform.iphoneos",
    "modelCode" : "iPhone8,1",
    "identifier" : "d83d5bc53967baa0ee18626ba87b6254b2ab5418",
    "architecture" : "arm64",
    "modelName" : "iPhone 6s",
    "error" : {
      "code" : -13,
      "failureReason" : "",
      "domain" : "com.apple.platform.iphoneos"
    }
  }
]
''';

1090 1091 1092 1093 1094
          fakeProcessManager.addCommand(const FakeCommand(
            command: <String>['xcrun', 'xcdevice', 'list', '--timeout', '2'],
            stdout: devicesOutput,
          ));

1095
          await xcdevice.getAvailableIOSDevices();
1096 1097
          final List<String> errors = await xcdevice.getDiagnostics();
          expect(errors, hasLength(1));
1098
          expect(fakeProcessManager, hasNoRemainingExpectations);
1099 1100 1101 1102
        }, overrides: <Type, Generator>{
          Platform: () => macPlatform,
        });

1103 1104 1105 1106 1107 1108 1109 1110 1111
        testWithoutContext('diagnostics xcdevice fails', () async {
          fakeProcessManager.addCommand(const FakeCommand(
            command: <String>['xcrun', 'xcdevice', 'list', '--timeout', '2'],
            exception: ProcessException('xcrun', <String>['xcdevice', 'list', '--timeout', '2']),
          ));

          expect(await xcdevice.getDiagnostics(), isEmpty);
        });

1112 1113
        testUsingContext('returns error message', () async {
          const String devicesOutput = '''
1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131
[
   {
    "simulator" : false,
    "operatingSystemVersion" : "13.3 (17C54)",
    "interface" : "usb",
    "available" : false,
    "platform" : "com.apple.platform.iphoneos",
    "modelCode" : "iPhone8,1",
    "identifier" : "98206e7a4afd4aedaff06e687594e089dede3c44",
    "architecture" : "arm64",
    "modelName" : "iPhone 6s",
    "name" : "An iPhone (Space Gray)",
    "error" : {
      "code" : -9,
      "failureReason" : "",
      "underlyingErrors" : [
        {
          "code" : 5,
1132
          "failureReason" : "allowsSecureServices: 1. isConnected: 0. Platform: <DVTPlatform:0x7f804ce32880:'com.apple.platform.iphoneos':<DVTFilePath:0x7f804ce32800:'/Users/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform'>>. DTDKDeviceIdentifierIsIDID: 0",
1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193
          "description" : "📱<DVTiOSDevice (0x7f801f190450), iPhone, iPhone, 13.3 (17C54), d83d5bc53967baa0ee18626ba87b6254b2ab5418> -- Failed _shouldMakeReadyForDevelopment check even though device is not locked by passcode.",
          "recoverySuggestion" : "",
          "domain" : "com.apple.platform.iphoneos"
        }
      ],
      "description" : "iPhone is not paired with your computer.",
      "recoverySuggestion" : "To use iPhone with Xcode, unlock it and choose to trust this computer when prompted.",
      "domain" : "com.apple.platform.iphoneos"
    }
  },
  {
    "simulator" : false,
    "operatingSystemVersion" : "13.3 (17C54)",
    "interface" : "usb",
    "available" : false,
    "platform" : "com.apple.platform.iphoneos",
    "modelCode" : "iPhone8,1",
    "identifier" : "d83d5bc53967baa0ee18626ba87b6254b2ab5418",
    "architecture" : "arm64",
    "modelName" : "iPhone 6s",
    "name" : "iPhone",
    "error" : {
      "failureReason" : "",
      "description" : "iPhone is not paired with your computer",
      "domain" : "com.apple.platform.iphoneos"
    }
  },
  {
    "simulator" : false,
    "operatingSystemVersion" : "13.3 (17C54)",
    "interface" : "network",
    "available" : false,
    "platform" : "com.apple.platform.iphoneos",
    "modelCode" : "iPhone8,1",
    "identifier" : "d83d5bc53967baa0ee18626ba87b6254b2ab5418",
    "architecture" : "arm64",
    "modelName" : "iPhone 6s",
    "error" : {
      "code" : -13,
      "failureReason" : "",
      "domain" : "com.apple.platform.iphoneos"
    }
  },
  {
    "simulator" : false,
    "operatingSystemVersion" : "13.3 (17C54)",
    "interface" : "usb",
    "available" : false,
    "platform" : "com.apple.platform.iphoneos",
    "modelCode" : "iPhone8,1",
    "identifier" : "43ad2fda7991b34fe1acbda82f9e2fd3d6ddc9f7",
    "architecture" : "arm64",
    "modelName" : "iPhone 6s",
    "name" : "iPhone",
    "error" : {
      "code" : -10,
      "failureReason" : "",
      "description" : "iPhone is busy: Preparing debugger support for iPhone",
      "recoverySuggestion" : "Xcode will continue when iPhone is finished.",
      "domain" : "com.apple.platform.iphoneos"
    }
1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222
  },
  {
    "modelCode" : "iPad8,5",
    "simulator" : false,
    "modelName" : "iPad Pro (12.9-inch) (3rd generation)",
    "error" : {
      "code" : -13,
      "failureReason" : "",
      "underlyingErrors" : [
        {
          "code" : 4,
          "failureReason" : "",
          "description" : "iPad is locked.",
          "recoverySuggestion" : "To use iPad with Xcode, unlock it.",
          "domain" : "DVTDeviceIneligibilityErrorDomain"
        }
      ],
      "description" : "iPad is not connected",
      "recoverySuggestion" : "Xcode will continue when iPad is connected.",
      "domain" : "com.apple.platform.iphoneos"
    },
    "operatingSystemVersion" : "15.6 (19G5027e)",
    "identifier" : "00008027-0019253601068123",
    "platform" : "com.apple.platform.iphoneos",
    "architecture" : "arm64e",
    "interface" : "usb",
    "available" : false,
    "name" : "iPad",
    "modelUTI" : "com.apple.ipad-pro-12point9-1"
1223 1224 1225 1226
  }
]
''';

1227 1228 1229 1230 1231 1232 1233
          fakeProcessManager.addCommand(const FakeCommand(
            command: <String>['xcrun', 'xcdevice', 'list', '--timeout', '2'],
            stdout: devicesOutput,
          ));

          final List<String> errors = await xcdevice.getDiagnostics();
          expect(errors, hasLength(4));
1234

1235 1236 1237 1238
          expect(errors[0], 'Error: iPhone is not paired with your computer. To use iPhone with Xcode, unlock it and choose to trust this computer when prompted. (code -9)');
          expect(errors[1], 'Error: iPhone is not paired with your computer.');
          expect(errors[2], 'Error: Xcode pairing error. (code -13)');
          expect(errors[3], 'Error: iPhone is busy: Preparing debugger support for iPhone. Xcode will continue when iPhone is finished. (code -10)');
1239
          expect(errors, isNot(contains('Xcode will continue')));
1240
          expect(fakeProcessManager, hasNoRemainingExpectations);
1241 1242 1243
        }, overrides: <Type, Generator>{
          Platform: () => macPlatform,
        });
1244 1245
      });
    });
1246 1247
  });
}
1248

1249 1250
class FakeXcodeProjectInterpreter extends Fake implements XcodeProjectInterpreter {
  @override
1251
  Version version = Version(0, 0, 0);
1252 1253 1254 1255 1256 1257 1258

  @override
  bool isInstalled = false;

  @override
  List<String> xcrunCommand() => <String>['xcrun'];
}