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

5 6
// @dart = 2.8

7
import 'package:file/memory.dart';
8
import 'package:flutter_tools/src/artifacts.dart';
9 10
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart';
11
import 'package:flutter_tools/src/base/logger.dart';
12
import 'package:flutter_tools/src/base/platform.dart';
13
import 'package:flutter_tools/src/base/version.dart';
14
import 'package:flutter_tools/src/build_info.dart';
15
import 'package:flutter_tools/src/ios/xcode_build_settings.dart';
16
import 'package:flutter_tools/src/ios/xcodeproj.dart';
17
import 'package:flutter_tools/src/project.dart';
18
import 'package:flutter_tools/src/reporting/reporting.dart';
19

20 21
import '../../src/common.dart';
import '../../src/context.dart';
22
import '../../src/fake_process_manager.dart';
23 24

const String xcodebuild = '/usr/bin/xcodebuild';
25 26

void main() {
27 28
  group('MockProcessManager', () {
    setUp(() {
29
      final FileSystem fileSystem = MemoryFileSystem.test();
30 31 32 33
      fileSystem.file(xcodebuild).createSync(recursive: true);
    });
  });

34 35 36 37 38 39 40
  const FakeCommand kWhichSysctlCommand = FakeCommand(
    command: <String>[
      'which',
      'sysctl',
    ],
  );

41 42
  // x64 host.
  const FakeCommand kx64CheckCommand = FakeCommand(
43 44 45 46 47 48 49
    command: <String>[
      'sysctl',
      'hw.optional.arm64',
    ],
    exitCode: 1,
  );

50 51 52 53 54 55 56 57 58
  // ARM host.
  const FakeCommand kARMCheckCommand = FakeCommand(
    command: <String>[
      'sysctl',
      'hw.optional.arm64',
    ],
    stdout: 'hw.optional.arm64: 1',
  );

59
  FakeProcessManager fakeProcessManager;
60 61 62 63 64 65
  XcodeProjectInterpreter xcodeProjectInterpreter;
  FakePlatform platform;
  FileSystem fileSystem;
  BufferLogger logger;

  setUp(() {
66
    fakeProcessManager = FakeProcessManager.empty();
67
    platform = FakePlatform(operatingSystem: 'macos');
68
    fileSystem = MemoryFileSystem.test();
69
    fileSystem.file(xcodebuild).createSync(recursive: true);
70
    logger = BufferLogger.test();
71 72 73 74
    xcodeProjectInterpreter = XcodeProjectInterpreter(
      logger: logger,
      fileSystem: fileSystem,
      platform: platform,
75
      processManager: fakeProcessManager,
76
      usage: null,
77 78
    );
  });
79

80
  testWithoutContext('xcodebuild versionText returns null when xcodebuild is not fully installed', () {
81
    fakeProcessManager.addCommands(const <FakeCommand>[
82
      kWhichSysctlCommand,
83
      kx64CheckCommand,
84 85 86 87 88 89 90 91
      FakeCommand(
        command: <String>['xcrun', 'xcodebuild', '-version'],
        stdout: "xcode-select: error: tool 'xcodebuild' requires Xcode, "
            "but active developer directory '/Library/Developer/CommandLineTools' "
            'is a command line tools instance',
        exitCode: 1,
      ),
    ]);
92

93
    expect(xcodeProjectInterpreter.versionText, isNull);
94
    expect(fakeProcessManager, hasNoRemainingExpectations);
95
  });
96

97 98 99
  testWithoutContext('xcodebuild versionText returns null when xcodebuild is not installed', () {
    fakeProcessManager.addCommands(const <FakeCommand>[
      kWhichSysctlCommand,
100
      kx64CheckCommand,
101 102 103 104 105 106 107 108 109
      FakeCommand(
        command: <String>['xcrun', 'xcodebuild', '-version'],
        exception: ProcessException(xcodebuild, <String>['-version']),
      ),
    ]);

    expect(xcodeProjectInterpreter.versionText, isNull);
  });

110
  testWithoutContext('xcodebuild versionText returns formatted version text', () {
111
    fakeProcessManager.addCommands(const <FakeCommand>[
112
      kWhichSysctlCommand,
113
      kx64CheckCommand,
114 115 116 117 118
      FakeCommand(
        command: <String>['xcrun', 'xcodebuild', '-version'],
        stdout: 'Xcode 8.3.3\nBuild version 8E3004b',
      ),
    ]);
119

120
    expect(xcodeProjectInterpreter.versionText, 'Xcode 8.3.3, Build version 8E3004b');
121
    expect(fakeProcessManager, hasNoRemainingExpectations);
122
  });
123

124
  testWithoutContext('xcodebuild versionText handles Xcode version string with unexpected format', () {
125
    fakeProcessManager.addCommands(const <FakeCommand>[
126
      kWhichSysctlCommand,
127
      kx64CheckCommand,
128 129 130 131 132
      FakeCommand(
        command: <String>['xcrun', 'xcodebuild', '-version'],
        stdout: 'Xcode Ultra5000\nBuild version 8E3004b',
      ),
    ]);
133

134
    expect(xcodeProjectInterpreter.versionText, 'Xcode Ultra5000, Build version 8E3004b');
135
    expect(fakeProcessManager, hasNoRemainingExpectations);
136
  });
137

138
  testWithoutContext('xcodebuild version parts can be parsed', () {
139
    fakeProcessManager.addCommands(const <FakeCommand>[
140
      kWhichSysctlCommand,
141
      kx64CheckCommand,
142 143 144 145 146
      FakeCommand(
        command: <String>['xcrun', 'xcodebuild', '-version'],
        stdout: 'Xcode 11.4.1\nBuild version 11N111s',
      ),
    ]);
147

148
    expect(xcodeProjectInterpreter.version, Version(11, 4, 1));
149
    expect(fakeProcessManager, hasNoRemainingExpectations);
150
  });
151

152
  testWithoutContext('xcodebuild minor and patch version default to 0', () {
153
    fakeProcessManager.addCommands(const <FakeCommand>[
154
      kWhichSysctlCommand,
155
      kx64CheckCommand,
156 157 158 159 160
      FakeCommand(
        command: <String>['xcrun', 'xcodebuild', '-version'],
        stdout: 'Xcode 11\nBuild version 11N111s',
      ),
    ]);
161

162
    expect(xcodeProjectInterpreter.version, Version(11, 0, 0));
163
    expect(fakeProcessManager, hasNoRemainingExpectations);
164
  });
165

166
  testWithoutContext('xcodebuild version parts is null when version has unexpected format', () {
167
    fakeProcessManager.addCommands(const <FakeCommand>[
168
      kWhichSysctlCommand,
169
      kx64CheckCommand,
170 171 172 173 174
      FakeCommand(
        command: <String>['xcrun', 'xcodebuild', '-version'],
        stdout: 'Xcode Ultra5000\nBuild version 8E3004b',
      ),
    ]);
175
    expect(xcodeProjectInterpreter.version, isNull);
176
    expect(fakeProcessManager, hasNoRemainingExpectations);
177
  });
178

179
  testWithoutContext('xcodebuild isInstalled is false when not on MacOS', () {
180
    final Platform platform = FakePlatform(operatingSystem: 'notMacOS');
181 182 183 184
    xcodeProjectInterpreter = XcodeProjectInterpreter(
      logger: logger,
      fileSystem: fileSystem,
      platform: platform,
185
      processManager: fakeProcessManager,
186
      usage: TestUsage(),
187 188 189 190
    );
    fileSystem.file(xcodebuild).deleteSync();

    expect(xcodeProjectInterpreter.isInstalled, isFalse);
191
    expect(fakeProcessManager, hasNoRemainingExpectations);
192 193 194 195 196 197
  });

  testWithoutContext('xcodebuild isInstalled is false when xcodebuild does not exist', () {
    fileSystem.file(xcodebuild).deleteSync();

    expect(xcodeProjectInterpreter.isInstalled, isFalse);
198
    expect(fakeProcessManager, hasNoRemainingExpectations);
199 200
  });

201 202 203
  testWithoutContext(
      'xcodebuild isInstalled is false when Xcode is not fully installed', () {
    fakeProcessManager.addCommands(const <FakeCommand>[
204
      kWhichSysctlCommand,
205
      kx64CheckCommand,
206 207 208 209 210 211 212 213
      FakeCommand(
        command: <String>['xcrun', 'xcodebuild', '-version'],
        stdout: "xcode-select: error: tool 'xcodebuild' requires Xcode, "
            "but active developer directory '/Library/Developer/CommandLineTools' "
            'is a command line tools instance',
        exitCode: 1,
      ),
    ]);
214

215
    expect(xcodeProjectInterpreter.isInstalled, isFalse);
216
    expect(fakeProcessManager, hasNoRemainingExpectations);
217
  });
218

219
  testWithoutContext('xcodebuild isInstalled is false when version has unexpected format', () {
220
    fakeProcessManager.addCommands(const <FakeCommand>[
221
      kWhichSysctlCommand,
222
      kx64CheckCommand,
223 224 225 226 227
      FakeCommand(
        command: <String>['xcrun', 'xcodebuild', '-version'],
        stdout: 'Xcode Ultra5000\nBuild version 8E3004b',
      ),
    ]);
228

229
    expect(xcodeProjectInterpreter.isInstalled, isFalse);
230
    expect(fakeProcessManager, hasNoRemainingExpectations);
231
  });
232

233
  testWithoutContext('xcodebuild isInstalled is true when version has expected format', () {
234
    fakeProcessManager.addCommands(const <FakeCommand>[
235
      kWhichSysctlCommand,
236
      kx64CheckCommand,
237 238 239 240 241
      FakeCommand(
        command: <String>['xcrun', 'xcodebuild', '-version'],
        stdout: 'Xcode 8.3.3\nBuild version 8E3004b',
      ),
    ]);
242

243
    expect(xcodeProjectInterpreter.isInstalled, isTrue);
244
    expect(fakeProcessManager, hasNoRemainingExpectations);
245
  });
246

247 248
  testWithoutContext('xcrun runs natively on arm64', () {
    fakeProcessManager.addCommands(const <FakeCommand>[
249
      kWhichSysctlCommand,
250
      kARMCheckCommand,
251 252 253 254 255 256 257
    ]);

    expect(xcodeProjectInterpreter.xcrunCommand(), <String>[
      '/usr/bin/arch',
      '-arm64e',
      'xcrun',
    ]);
258
    expect(fakeProcessManager, hasNoRemainingExpectations);
259 260
  });

261
  testUsingContext('xcodebuild build settings is empty when xcodebuild failed to get the build settings', () async {
262
    platform.environment = const <String, String>{};
263

264
    fakeProcessManager.addCommands(<FakeCommand>[
265
      kWhichSysctlCommand,
266
      const FakeCommand(
267 268 269 270 271 272 273 274 275 276 277 278 279 280
        command: <String>[
          'sysctl',
          'hw.optional.arm64',
        ],
        exitCode: 1,
      ),
      FakeCommand(
        command: <String>[
          'xcrun',
          'xcodebuild',
          '-project',
          '/',
          '-scheme',
          'Free',
281 282
          '-showBuildSettings',
          'BUILD_DIR=${fileSystem.path.absolute('build', 'ios')}',
283 284 285 286
        ],
        exitCode: 1,
      ),
    ]);
287

288 289 290
    expect(
        await xcodeProjectInterpreter.getBuildSettings('', buildContext: const XcodeProjectBuildContext(scheme: 'Free')),
        const <String, String>{});
291
    expect(fakeProcessManager, hasNoRemainingExpectations);
292 293 294
  }, overrides: <Type, Generator>{
    FileSystem: () => fileSystem,
    ProcessManager: () => FakeProcessManager.any(),
295 296
  });

297
  testUsingContext('build settings passes in the simulator SDK', () async {
298 299
    platform.environment = const <String, String>{};

300 301
    fakeProcessManager.addCommands(<FakeCommand>[
      kWhichSysctlCommand,
302
      kx64CheckCommand,
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
      FakeCommand(
        command: <String>[
          'xcrun',
          'xcodebuild',
          '-project',
          '/',
          '-sdk',
          'iphonesimulator',
          '-showBuildSettings',
          'BUILD_DIR=${fileSystem.path.absolute('build', 'ios')}',
        ],
        exitCode: 1,
      ),
    ]);

    expect(
      await xcodeProjectInterpreter.getBuildSettings(
        '',
        buildContext: const XcodeProjectBuildContext(environmentType: EnvironmentType.simulator),
      ),
      const <String, String>{},
    );
325
    expect(fakeProcessManager, hasNoRemainingExpectations);
326 327 328 329 330 331 332 333 334
  }, overrides: <Type, Generator>{
    FileSystem: () => fileSystem,
    ProcessManager: () => FakeProcessManager.any(),
  });

  testUsingContext('build settings accepts an empty scheme', () async {
    platform.environment = const <String, String>{};

    fakeProcessManager.addCommands(<FakeCommand>[
335
      kWhichSysctlCommand,
336
      kx64CheckCommand,
337 338 339 340 341 342
      FakeCommand(
        command: <String>[
          'xcrun',
          'xcodebuild',
          '-project',
          '/',
343 344
          '-showBuildSettings',
          'BUILD_DIR=${fileSystem.path.absolute('build', 'ios')}',
345 346 347 348
        ],
        exitCode: 1,
      ),
    ]);
349

350 351
    expect(await xcodeProjectInterpreter.getBuildSettings('', buildContext: const XcodeProjectBuildContext()),
        const <String, String>{});
352
    expect(fakeProcessManager, hasNoRemainingExpectations);
353 354 355
  }, overrides: <Type, Generator>{
    FileSystem: () => fileSystem,
    ProcessManager: () => FakeProcessManager.any(),
356 357
  });

358
  testUsingContext('xcodebuild build settings contains Flutter Xcode environment variables', () async {
359
    platform.environment = const <String, String>{
360 361
      'FLUTTER_XCODE_CODE_SIGN_STYLE': 'Manual',
      'FLUTTER_XCODE_ARCHS': 'arm64'
362
    };
363
    fakeProcessManager.addCommands(<FakeCommand>[
364
      kWhichSysctlCommand,
365
      kx64CheckCommand,
366 367 368 369 370 371 372 373 374
      FakeCommand(
        command: <String>[
          'xcrun',
          'xcodebuild',
          '-project',
          fileSystem.path.separator,
          '-scheme',
          'Free',
          '-showBuildSettings',
375
          'BUILD_DIR=${fileSystem.path.absolute('build', 'ios')}',
376 377 378 379 380
          'CODE_SIGN_STYLE=Manual',
          'ARCHS=arm64'
        ],
      ),
    ]);
381 382 383
    expect(
        await xcodeProjectInterpreter.getBuildSettings('', buildContext: const XcodeProjectBuildContext(scheme: 'Free')),
        const <String, String>{});
384
    expect(fakeProcessManager, hasNoRemainingExpectations);
385 386 387
  }, overrides: <Type, Generator>{
    FileSystem: () => fileSystem,
    ProcessManager: () => FakeProcessManager.any(),
388 389 390
  });

  testWithoutContext('xcodebuild clean contains Flutter Xcode environment variables', () async {
391
    platform.environment = const <String, String>{
392 393
      'FLUTTER_XCODE_CODE_SIGN_STYLE': 'Manual',
      'FLUTTER_XCODE_ARCHS': 'arm64'
394 395
    };

396
    fakeProcessManager.addCommands(const <FakeCommand>[
397
      kWhichSysctlCommand,
398
      kx64CheckCommand,
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413
      FakeCommand(
        command: <String>[
          'xcrun',
          'xcodebuild',
          '-workspace',
          'workspace_path',
          '-scheme',
          'Free',
          '-quiet',
          'clean',
          'CODE_SIGN_STYLE=Manual',
          'ARCHS=arm64'
        ],
      ),
    ]);
414

415
    await xcodeProjectInterpreter.cleanWorkspace('workspace_path', 'Free');
416
    expect(fakeProcessManager, hasNoRemainingExpectations);
417 418 419 420
  });

  testWithoutContext('xcodebuild -list getInfo returns something when xcodebuild -list succeeds', () async {
    const String workingDirectory = '/';
421
    fakeProcessManager.addCommands(const <FakeCommand>[
422
      kWhichSysctlCommand,
423
      kx64CheckCommand,
424 425 426 427
      FakeCommand(
        command: <String>['xcrun', 'xcodebuild', '-list'],
      ),
    ]);
428

429 430 431 432
    final XcodeProjectInterpreter xcodeProjectInterpreter = XcodeProjectInterpreter(
      logger: logger,
      fileSystem: fileSystem,
      platform: platform,
433
      processManager: fakeProcessManager,
434
      usage: TestUsage(),
435 436 437
    );

    expect(await xcodeProjectInterpreter.getInfo(workingDirectory), isNotNull);
438
    expect(fakeProcessManager, hasNoRemainingExpectations);
439 440 441 442 443
  });

  testWithoutContext('xcodebuild -list getInfo throws a tool exit when it is unable to find a project', () async {
    const String workingDirectory = '/';
    const String stderr = 'Useful Xcode failure message about missing project.';
444

445
    fakeProcessManager.addCommands(const <FakeCommand>[
446
      kWhichSysctlCommand,
447
      kx64CheckCommand,
448 449 450 451 452 453
      FakeCommand(
        command: <String>['xcrun', 'xcodebuild', '-list'],
        exitCode: 66,
        stderr: stderr,
      ),
    ]);
454

455 456 457 458
    final XcodeProjectInterpreter xcodeProjectInterpreter = XcodeProjectInterpreter(
      logger: logger,
      fileSystem: fileSystem,
      platform: platform,
459
      processManager: fakeProcessManager,
460
      usage: TestUsage(),
461 462
    );

463 464 465 466 467 468 469 470 471 472
    expect(() => xcodeProjectInterpreter.getInfo(workingDirectory), throwsToolExit(message: stderr));
    expect(fakeProcessManager, hasNoRemainingExpectations);
  });

  testWithoutContext('xcodebuild -list getInfo throws a tool exit when project is corrupted', () async {
    const String workingDirectory = '/';
    const String stderr = 'Useful Xcode failure message about corrupted project.';

    fakeProcessManager.addCommands(const <FakeCommand>[
      kWhichSysctlCommand,
473
      kx64CheckCommand,
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490
      FakeCommand(
        command: <String>['xcrun', 'xcodebuild', '-list'],
        exitCode: 74,
        stderr: stderr,
      ),
    ]);

    final XcodeProjectInterpreter xcodeProjectInterpreter = XcodeProjectInterpreter(
      logger: logger,
      fileSystem: fileSystem,
      platform: platform,
      processManager: fakeProcessManager,
      usage: TestUsage(),
    );

    expect(() => xcodeProjectInterpreter.getInfo(workingDirectory), throwsToolExit(message: stderr));
    expect(fakeProcessManager, hasNoRemainingExpectations);
491 492 493 494
  });

  testWithoutContext('Xcode project properties from default project can be parsed', () {
    const String output = '''
495 496 497 498 499 500 501 502 503 504 505 506 507 508
Information about project "Runner":
    Targets:
        Runner

    Build Configurations:
        Debug
        Release

    If no build configuration is specified and -scheme is not passed then "Release" is used.

    Schemes:
        Runner

''';
509
    final XcodeProjectInfo info = XcodeProjectInfo.fromXcodeBuildOutput(output, logger);
510 511 512 513 514 515 516
    expect(info.targets, <String>['Runner']);
    expect(info.schemes, <String>['Runner']);
    expect(info.buildConfigurations, <String>['Debug', 'Release']);
  });

  testWithoutContext('Xcode project properties from project with custom schemes can be parsed', () {
    const String output = '''
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533
Information about project "Runner":
    Targets:
        Runner

    Build Configurations:
        Debug (Free)
        Debug (Paid)
        Release (Free)
        Release (Paid)

    If no build configuration is specified and -scheme is not passed then "Release (Free)" is used.

    Schemes:
        Free
        Paid

''';
534
    final XcodeProjectInfo info = XcodeProjectInfo.fromXcodeBuildOutput(output, logger);
535 536 537 538 539 540 541 542 543 544 545 546 547 548 549
    expect(info.targets, <String>['Runner']);
    expect(info.schemes, <String>['Free', 'Paid']);
    expect(info.buildConfigurations, <String>['Debug (Free)', 'Debug (Paid)', 'Release (Free)', 'Release (Paid)']);
  });

  testWithoutContext('expected scheme for non-flavored build is Runner', () {
    expect(XcodeProjectInfo.expectedSchemeFor(BuildInfo.debug), 'Runner');
    expect(XcodeProjectInfo.expectedSchemeFor(BuildInfo.profile), 'Runner');
    expect(XcodeProjectInfo.expectedSchemeFor(BuildInfo.release), 'Runner');
  });

  testWithoutContext('expected build configuration for non-flavored build is derived from BuildMode', () {
    expect(XcodeProjectInfo.expectedBuildConfigurationFor(BuildInfo.debug, 'Runner'), 'Debug');
    expect(XcodeProjectInfo.expectedBuildConfigurationFor(BuildInfo.profile, 'Runner'), 'Profile');
    expect(XcodeProjectInfo.expectedBuildConfigurationFor(BuildInfo.release, 'Runner'), 'Release');
550
  });
551

552
  testWithoutContext('expected scheme for flavored build is the title-cased flavor', () {
553 554 555
    expect(XcodeProjectInfo.expectedSchemeFor(const BuildInfo(BuildMode.debug, 'hello', treeShakeIcons: false)), 'Hello');
    expect(XcodeProjectInfo.expectedSchemeFor(const BuildInfo(BuildMode.profile, 'HELLO', treeShakeIcons: false)), 'HELLO');
    expect(XcodeProjectInfo.expectedSchemeFor(const BuildInfo(BuildMode.release, 'Hello', treeShakeIcons: false)), 'Hello');
556 557
  });
  testWithoutContext('expected build configuration for flavored build is Mode-Flavor', () {
558 559 560
    expect(XcodeProjectInfo.expectedBuildConfigurationFor(const BuildInfo(BuildMode.debug, 'hello', treeShakeIcons: false), 'Hello'), 'Debug-Hello');
    expect(XcodeProjectInfo.expectedBuildConfigurationFor(const BuildInfo(BuildMode.profile, 'HELLO', treeShakeIcons: false), 'Hello'), 'Profile-Hello');
    expect(XcodeProjectInfo.expectedBuildConfigurationFor(const BuildInfo(BuildMode.release, 'Hello', treeShakeIcons: false), 'Hello'), 'Release-Hello');
561 562 563
  });

  testWithoutContext('scheme for default project is Runner', () {
564
    final XcodeProjectInfo info = XcodeProjectInfo(<String>['Runner'], <String>['Debug', 'Release'], <String>['Runner'], logger);
565 566 567 568

    expect(info.schemeFor(BuildInfo.debug), 'Runner');
    expect(info.schemeFor(BuildInfo.profile), 'Runner');
    expect(info.schemeFor(BuildInfo.release), 'Runner');
569
    expect(info.schemeFor(const BuildInfo(BuildMode.debug, 'unknown', treeShakeIcons: false)), isNull);
570 571 572
  });

  testWithoutContext('build configuration for default project is matched against BuildMode', () {
573
    final XcodeProjectInfo info = XcodeProjectInfo(<String>['Runner'], <String>['Debug', 'Profile', 'Release'], <String>['Runner'], logger);
574 575 576 577 578 579 580 581 582 583 584

    expect(info.buildConfigurationFor(BuildInfo.debug, 'Runner'), 'Debug');
    expect(info.buildConfigurationFor(BuildInfo.profile, 'Runner'), 'Profile');
    expect(info.buildConfigurationFor(BuildInfo.release, 'Runner'), 'Release');
  });

  testWithoutContext('scheme for project with custom schemes is matched against flavor', () {
    final XcodeProjectInfo info = XcodeProjectInfo(
      <String>['Runner'],
      <String>['Debug (Free)', 'Debug (Paid)', 'Release (Free)', 'Release (Paid)'],
      <String>['Free', 'Paid'],
585
      logger,
586 587
    );

588 589 590
    expect(info.schemeFor(const BuildInfo(BuildMode.debug, 'free', treeShakeIcons: false)), 'Free');
    expect(info.schemeFor(const BuildInfo(BuildMode.profile, 'Free', treeShakeIcons: false)), 'Free');
    expect(info.schemeFor(const BuildInfo(BuildMode.release, 'paid', treeShakeIcons: false)), 'Paid');
591
    expect(info.schemeFor(BuildInfo.debug), isNull);
592
    expect(info.schemeFor(const BuildInfo(BuildMode.debug, 'unknown', treeShakeIcons: false)), isNull);
593 594
  });

595 596 597 598 599 600 601 602 603
  testWithoutContext('reports default scheme error and exit', () {
    final XcodeProjectInfo defaultInfo = XcodeProjectInfo(
      <String>[],
      <String>[],
      <String>['Runner'],
      logger,
    );

    expect(
604
      defaultInfo.reportFlavorNotFoundAndExit,
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
      throwsToolExit(
        message: 'The Xcode project does not define custom schemes. You cannot use the --flavor option.'
      ),
    );
  });

  testWithoutContext('reports custom scheme error and exit', () {
    final XcodeProjectInfo info = XcodeProjectInfo(
      <String>[],
      <String>[],
      <String>['Free', 'Paid'],
      logger,
    );

    expect(
620
      info.reportFlavorNotFoundAndExit,
621 622 623 624 625 626
      throwsToolExit(
        message: 'You must specify a --flavor option to select one of the available schemes.'
      ),
    );
  });

627 628 629 630 631
  testWithoutContext('build configuration for project with custom schemes is matched against BuildMode and flavor', () {
    final XcodeProjectInfo info = XcodeProjectInfo(
      <String>['Runner'],
      <String>['debug (free)', 'Debug paid', 'profile - Free', 'Profile-Paid', 'release - Free', 'Release-Paid'],
      <String>['Free', 'Paid'],
632
      logger,
633 634
    );

635 636 637 638
    expect(info.buildConfigurationFor(const BuildInfo(BuildMode.debug, 'free', treeShakeIcons: false), 'Free'), 'debug (free)');
    expect(info.buildConfigurationFor(const BuildInfo(BuildMode.debug, 'Paid', treeShakeIcons: false), 'Paid'), 'Debug paid');
    expect(info.buildConfigurationFor(const BuildInfo(BuildMode.profile, 'FREE', treeShakeIcons: false), 'Free'), 'profile - Free');
    expect(info.buildConfigurationFor(const BuildInfo(BuildMode.release, 'paid', treeShakeIcons: false), 'Paid'), 'Release-Paid');
639 640 641 642 643 644 645
  });

  testWithoutContext('build configuration for project with inconsistent naming is null', () {
    final XcodeProjectInfo info = XcodeProjectInfo(
      <String>['Runner'],
      <String>['Debug-F', 'Dbg Paid', 'Rel Free', 'Release Full'],
      <String>['Free', 'Paid'],
646
      logger,
647
    );
648 649 650
    expect(info.buildConfigurationFor(const BuildInfo(BuildMode.debug, 'Free', treeShakeIcons: false), 'Free'), null);
    expect(info.buildConfigurationFor(const BuildInfo(BuildMode.profile, 'Free', treeShakeIcons: false), 'Free'), null);
    expect(info.buildConfigurationFor(const BuildInfo(BuildMode.release, 'Paid', treeShakeIcons: false), 'Paid'), null);
651 652
  });
 group('environmentVariablesAsXcodeBuildSettings', () {
653 654 655
    FakePlatform platform;

    setUp(() {
656
      platform = FakePlatform();
657 658
    });

659
    testWithoutContext('environment variables as Xcode build settings', () {
660
      platform.environment = const <String, String>{
661 662 663 664
        'Ignored': 'Bogus',
        'FLUTTER_NOT_XCODE': 'Bogus',
        'FLUTTER_XCODE_CODE_SIGN_STYLE': 'Manual',
        'FLUTTER_XCODE_ARCHS': 'arm64'
665
      };
666
      final List<String> environmentVariablesAsBuildSettings = environmentVariablesAsXcodeBuildSettings(platform);
667 668 669 670
      expect(environmentVariablesAsBuildSettings, <String>['CODE_SIGN_STYLE=Manual', 'ARCHS=arm64']);
    });
  });

671
  group('updateGeneratedXcodeProperties', () {
672
    Artifacts localArtifacts;
673 674 675 676
    FakePlatform macOS;
    FileSystem fs;

    setUp(() {
677
      fs = MemoryFileSystem.test();
678
      localArtifacts = Artifacts.test(localEngine: 'out/ios_profile_arm');
679
      macOS = FakePlatform(operatingSystem: 'macos');
680
      fs.file(xcodebuild).createSync(recursive: true);
681 682
    });

683 684 685 686 687 688 689 690 691 692 693 694 695 696 697
    group('arm simulator', () {
      FakeProcessManager fakeProcessManager;
      XcodeProjectInterpreter xcodeProjectInterpreter;

      setUp(() {
        fakeProcessManager = FakeProcessManager.empty();
        xcodeProjectInterpreter = XcodeProjectInterpreter.test(processManager: fakeProcessManager);
      });

      testUsingContext('does not exclude arm64 simulator when supported by all plugins', () async {
        const BuildInfo buildInfo = BuildInfo.debug;
        final FlutterProject project = FlutterProject.fromDirectoryTest(fs.directory('path/to/project'));
        final Directory podXcodeProject = project.ios.hostAppRoot.childDirectory('Pods').childDirectory('Pods.xcodeproj')
          ..createSync(recursive: true);

698
        final String buildDirectory = fileSystem.path.absolute('build', 'ios');
699 700 701 702 703 704 705 706 707 708 709 710 711 712 713
        fakeProcessManager.addCommands(<FakeCommand>[
          kWhichSysctlCommand,
          kARMCheckCommand,
          FakeCommand(
            command: <String>[
              '/usr/bin/arch',
              '-arm64e',
              'xcrun',
              'xcodebuild',
              '-alltargets',
              '-sdk',
              'iphonesimulator',
              '-project',
              podXcodeProject.path,
              '-showBuildSettings',
714 715
              'BUILD_DIR=$buildDirectory',
              'OBJROOT=$buildDirectory',
716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753
            ],
            stdout: '''
Build settings for action build and target plugin1:
    ENABLE_BITCODE = NO;
    EXCLUDED_ARCHS = i386;
    INFOPLIST_FILE = Runner/Info.plist;
    UNRELATED_BUILD_SETTING = arm64;

Build settings for action build and target plugin2:
    ENABLE_BITCODE = NO;
    EXCLUDED_ARCHS = i386;
    INFOPLIST_FILE = Runner/Info.plist;
    UNRELATED_BUILD_SETTING = arm64;
				'''
          ),
        ]);
        await updateGeneratedXcodeProperties(
          project: project,
          buildInfo: buildInfo,
        );

        final File config = fs.file('path/to/project/ios/Flutter/Generated.xcconfig');
        expect(config.readAsStringSync(), contains('EXCLUDED_ARCHS[sdk=iphonesimulator*]=i386\n'));
        expect(fakeProcessManager, hasNoRemainingExpectations);
      }, overrides: <Type, Generator>{
        Artifacts: () => localArtifacts,
        Platform: () => macOS,
        FileSystem: () => fs,
        ProcessManager: () => fakeProcessManager,
        XcodeProjectInterpreter: () => xcodeProjectInterpreter,
      });

      testUsingContext('excludes arm64 simulator when build setting fetch fails', () async {
        const BuildInfo buildInfo = BuildInfo.debug;
        final FlutterProject project = FlutterProject.fromDirectoryTest(fs.directory('path/to/project'));
        final Directory podXcodeProject = project.ios.hostAppRoot.childDirectory('Pods').childDirectory('Pods.xcodeproj')
          ..createSync(recursive: true);

754
        final String buildDirectory = fileSystem.path.absolute('build', 'ios');
755 756 757 758 759 760 761 762 763 764 765 766 767 768 769
        fakeProcessManager.addCommands(<FakeCommand>[
          kWhichSysctlCommand,
          kARMCheckCommand,
          FakeCommand(
              command: <String>[
                '/usr/bin/arch',
                '-arm64e',
                'xcrun',
                'xcodebuild',
                '-alltargets',
                '-sdk',
                'iphonesimulator',
                '-project',
                podXcodeProject.path,
                '-showBuildSettings',
770 771
                'BUILD_DIR=$buildDirectory',
                'OBJROOT=$buildDirectory',
772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797
              ],
              exitCode: 1,
          ),
        ]);
        await updateGeneratedXcodeProperties(
          project: project,
          buildInfo: buildInfo,
        );

        final File config = fs.file('path/to/project/ios/Flutter/Generated.xcconfig');
        expect(config.readAsStringSync(), contains('EXCLUDED_ARCHS[sdk=iphonesimulator*]=i386 arm64\n'));
        expect(fakeProcessManager, hasNoRemainingExpectations);
      }, overrides: <Type, Generator>{
        Artifacts: () => localArtifacts,
        Platform: () => macOS,
        FileSystem: () => fs,
        ProcessManager: () => fakeProcessManager,
        XcodeProjectInterpreter: () => xcodeProjectInterpreter,
      });

      testUsingContext('excludes arm64 simulator when unsupported by plugins', () async {
        const BuildInfo buildInfo = BuildInfo.debug;
        final FlutterProject project = FlutterProject.fromDirectoryTest(fs.directory('path/to/project'));
        final Directory podXcodeProject = project.ios.hostAppRoot.childDirectory('Pods').childDirectory('Pods.xcodeproj')
          ..createSync(recursive: true);

798
        final String buildDirectory = fileSystem.path.absolute('build', 'ios');
799 800 801 802 803 804 805 806 807 808 809 810 811 812 813
        fakeProcessManager.addCommands(<FakeCommand>[
          kWhichSysctlCommand,
          kARMCheckCommand,
          FakeCommand(
              command: <String>[
                '/usr/bin/arch',
                '-arm64e',
                'xcrun',
                'xcodebuild',
                '-alltargets',
                '-sdk',
                'iphonesimulator',
                '-project',
                podXcodeProject.path,
                '-showBuildSettings',
814 815
                'BUILD_DIR=$buildDirectory',
                'OBJROOT=$buildDirectory',
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
              ],
              stdout: '''
Build settings for action build and target plugin1:
    ENABLE_BITCODE = NO;
    EXCLUDED_ARCHS = i386;
    INFOPLIST_FILE = Runner/Info.plist;
    UNRELATED_BUILD_SETTING = arm64;

Build settings for action build and target plugin2:
    ENABLE_BITCODE = NO;
    EXCLUDED_ARCHS = i386 arm64;
    INFOPLIST_FILE = Runner/Info.plist;
    UNRELATED_BUILD_SETTING = arm64;
				'''
          ),
        ]);
        await updateGeneratedXcodeProperties(
          project: project,
          buildInfo: buildInfo,
        );

        final File config = fs.file('path/to/project/ios/Flutter/Generated.xcconfig');
        expect(config.readAsStringSync(), contains('EXCLUDED_ARCHS[sdk=iphonesimulator*]=i386 arm64\n'));
        expect(fakeProcessManager, hasNoRemainingExpectations);
      }, overrides: <Type, Generator>{
        Artifacts: () => localArtifacts,
        Platform: () => macOS,
        FileSystem: () => fs,
        ProcessManager: () => fakeProcessManager,
        XcodeProjectInterpreter: () => xcodeProjectInterpreter,
      });
    });

849
    void testUsingOsxContext(String description, dynamic Function() testMethod) {
850
      testUsingContext(description, testMethod, overrides: <Type, Generator>{
851
        Artifacts: () => localArtifacts,
852 853
        Platform: () => macOS,
        FileSystem: () => fs,
854
        ProcessManager: () => FakeProcessManager.any(),
855 856 857
      });
    }

858
    testUsingOsxContext('sets ARCHS=armv7 when armv7 local engine is set', () async {
859
      const BuildInfo buildInfo = BuildInfo.debug;
860
      final FlutterProject project = FlutterProject.fromDirectoryTest(fs.directory('path/to/project'));
861 862
      await updateGeneratedXcodeProperties(
        project: project,
863 864 865
        buildInfo: buildInfo,
      );

866
      final File config = fs.file('path/to/project/ios/Flutter/Generated.xcconfig');
867 868 869 870
      expect(config.existsSync(), isTrue);

      final String contents = config.readAsStringSync();
      expect(contents.contains('ARCHS=armv7'), isTrue);
871
      expect(contents.contains('EXCLUDED_ARCHS[sdk=iphonesimulator*]=i386'), isTrue);
872

873
      final File buildPhaseScript = fs.file('path/to/project/ios/Flutter/flutter_export_environment.sh');
874 875 876 877
      expect(buildPhaseScript.existsSync(), isTrue);

      final String buildPhaseScriptContents = buildPhaseScript.readAsStringSync();
      expect(buildPhaseScriptContents.contains('ARCHS=armv7'), isTrue);
878
      expect(buildPhaseScriptContents.contains('EXCLUDED_ARCHS'), isFalse);
879 880
    });

881
    testUsingOsxContext('does not exclude arm64 simulator when there are no plugins', () async {
882 883 884 885 886 887 888 889 890 891 892 893 894 895
      const BuildInfo buildInfo = BuildInfo.debug;
      final FlutterProject project = FlutterProject.fromDirectoryTest(fs.directory('path/to/project'));
      await updateGeneratedXcodeProperties(
        project: project,
        buildInfo: buildInfo,
      );

      final File config = fs.file('path/to/project/ios/Flutter/Generated.xcconfig');
      expect(config.readAsStringSync(), contains('EXCLUDED_ARCHS[sdk=iphonesimulator*]=i386\n'));

      final File buildPhaseScript = fs.file('path/to/project/ios/Flutter/flutter_export_environment.sh');
      expect(buildPhaseScript.readAsStringSync(), isNot(contains('EXCLUDED_ARCHS')));
    });

896
    testUsingOsxContext('sets TRACK_WIDGET_CREATION=true when trackWidgetCreation is true', () async {
897
      const BuildInfo buildInfo = BuildInfo(BuildMode.debug, null, trackWidgetCreation: true, treeShakeIcons: false);
898
      final FlutterProject project = FlutterProject.fromDirectoryTest(fs.directory('path/to/project'));
899 900
      await updateGeneratedXcodeProperties(
        project: project,
901 902 903
        buildInfo: buildInfo,
      );

904
      final File config = fs.file('path/to/project/ios/Flutter/Generated.xcconfig');
905 906 907 908
      expect(config.existsSync(), isTrue);

      final String contents = config.readAsStringSync();
      expect(contents.contains('TRACK_WIDGET_CREATION=true'), isTrue);
909

910
      final File buildPhaseScript = fs.file('path/to/project/ios/Flutter/flutter_export_environment.sh');
911 912 913 914
      expect(buildPhaseScript.existsSync(), isTrue);

      final String buildPhaseScriptContents = buildPhaseScript.readAsStringSync();
      expect(buildPhaseScriptContents.contains('TRACK_WIDGET_CREATION=true'), isTrue);
915 916 917
    });

    testUsingOsxContext('does not set TRACK_WIDGET_CREATION when trackWidgetCreation is false', () async {
918
      const BuildInfo buildInfo = BuildInfo.debug;
919
      final FlutterProject project = FlutterProject.fromDirectoryTest(fs.directory('path/to/project'));
920 921
      await updateGeneratedXcodeProperties(
        project: project,
922 923 924
        buildInfo: buildInfo,
      );

925
      final File config = fs.file('path/to/project/ios/Flutter/Generated.xcconfig');
926 927 928 929
      expect(config.existsSync(), isTrue);

      final String contents = config.readAsStringSync();
      expect(contents.contains('TRACK_WIDGET_CREATION=true'), isFalse);
930

931
      final File buildPhaseScript = fs.file('path/to/project/ios/Flutter/flutter_export_environment.sh');
932 933 934 935
      expect(buildPhaseScript.existsSync(), isTrue);

      final String buildPhaseScriptContents = buildPhaseScript.readAsStringSync();
      expect(buildPhaseScriptContents.contains('TRACK_WIDGET_CREATION=true'), isFalse);
936 937
    });

938
    group('sim local engine', () {
939 940 941 942 943 944 945
      testUsingContext('sets ARCHS=x86_64 when x86 sim local engine is set', () async {
        const BuildInfo buildInfo = BuildInfo.debug;
        final FlutterProject project = FlutterProject.fromDirectoryTest(fs.directory('path/to/project'));
        await updateGeneratedXcodeProperties(
          project: project,
          buildInfo: buildInfo,
        );
946

947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962
        final File config = fs.file('path/to/project/ios/Flutter/Generated.xcconfig');
        expect(config.existsSync(), isTrue);

        final String contents = config.readAsStringSync();
        expect(contents.contains('ARCHS=x86_64'), isTrue);

        final File buildPhaseScript = fs.file('path/to/project/ios/Flutter/flutter_export_environment.sh');
        expect(buildPhaseScript.existsSync(), isTrue);

        final String buildPhaseScriptContents = buildPhaseScript.readAsStringSync();
        expect(buildPhaseScriptContents.contains('ARCHS=x86_64'), isTrue);
      }, overrides: <Type, Generator>{
        Artifacts: () => Artifacts.test(localEngine: 'out/ios_debug_sim_unopt'),
        Platform: () => macOS,
        FileSystem: () => fs,
        ProcessManager: () => FakeProcessManager.any(),
963
      });
964

965
      testUsingContext('sets ARCHS=arm64 when arm64 sim local engine is set', () async {
966 967 968 969 970 971
        const BuildInfo buildInfo = BuildInfo.debug;
        final FlutterProject project = FlutterProject.fromDirectoryTest(fs.directory('path/to/project'));
        await updateGeneratedXcodeProperties(
          project: project,
          buildInfo: buildInfo,
        );
972

973 974 975 976
        final File config = fs.file('path/to/project/ios/Flutter/Generated.xcconfig');
        expect(config.existsSync(), isTrue);

        final String contents = config.readAsStringSync();
977
        expect(contents.contains('ARCHS=arm64'), isTrue);
978 979 980 981 982

        final File buildPhaseScript = fs.file('path/to/project/ios/Flutter/flutter_export_environment.sh');
        expect(buildPhaseScript.existsSync(), isTrue);

        final String buildPhaseScriptContents = buildPhaseScript.readAsStringSync();
983
        expect(buildPhaseScriptContents.contains('ARCHS=arm64'), isTrue);
984
      }, overrides: <Type, Generator>{
985
        Artifacts: () => Artifacts.test(localEngine: 'out/ios_debug_sim_arm64'),
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
        Platform: () => macOS,
        FileSystem: () => fs,
        ProcessManager: () => FakeProcessManager.any(),
      });
    });

    group('armv7 local engine', () {
      Artifacts localArtifacts;

      setUp(() {
        localArtifacts = Artifacts.test(localEngine: 'out/ios_profile');
      });

      testUsingContext('sets ARCHS=armv7 when armv7 local engine is set', () async {
        const BuildInfo buildInfo = BuildInfo.debug;

        final FlutterProject project = FlutterProject.fromDirectoryTest(fs.directory('path/to/project'));
        await updateGeneratedXcodeProperties(
          project: project,
          buildInfo: buildInfo,
        );

        final File config = fs.file('path/to/project/ios/Flutter/Generated.xcconfig');
        expect(config.existsSync(), isTrue);

        final String contents = config.readAsStringSync();
        expect(contents.contains('ARCHS=arm64'), isTrue);
      }, overrides: <Type, Generator>{
        Artifacts: () => localArtifacts,
        Platform: () => macOS,
        FileSystem: () => fs,
        ProcessManager: () => FakeProcessManager.any(),
      });
1019
    });
1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030

    String propertyFor(String key, File file) {
      final List<String> properties = file
          .readAsLinesSync()
          .where((String line) => line.startsWith('$key='))
          .map((String line) => line.split('=')[1])
          .toList();
      return properties.isEmpty ? null : properties.first;
    }

    Future<void> checkBuildVersion({
1031
      String manifestString,
1032 1033 1034 1035
      BuildInfo buildInfo,
      String expectedBuildName,
      String expectedBuildNumber,
    }) async {
1036
      final File manifestFile = fs.file('path/to/project/pubspec.yaml');
1037 1038 1039
      manifestFile.createSync(recursive: true);
      manifestFile.writeAsStringSync(manifestString);

1040
      await updateGeneratedXcodeProperties(
1041
        project: FlutterProject.fromDirectoryTest(fs.directory('path/to/project')),
1042 1043 1044
        buildInfo: buildInfo,
      );

1045
      final File localPropertiesFile = fs.file('path/to/project/ios/Flutter/Generated.xcconfig');
1046 1047
      expect(propertyFor('FLUTTER_BUILD_NAME', localPropertiesFile), expectedBuildName);
      expect(propertyFor('FLUTTER_BUILD_NUMBER', localPropertiesFile), expectedBuildNumber);
1048
      expect(propertyFor('FLUTTER_BUILD_NUMBER', localPropertiesFile), isNotNull);
1049 1050
    }

1051
    testUsingOsxContext('extract build name and number from pubspec.yaml', () async {
1052 1053 1054 1055 1056 1057 1058 1059 1060
      const String manifest = '''
name: test
version: 1.0.0+1
dependencies:
  flutter:
    sdk: flutter
flutter:
''';

1061
      const BuildInfo buildInfo = BuildInfo(BuildMode.release, null, treeShakeIcons: false);
1062
      await checkBuildVersion(
1063
        manifestString: manifest,
1064 1065 1066 1067 1068 1069
        buildInfo: buildInfo,
        expectedBuildName: '1.0.0',
        expectedBuildNumber: '1',
      );
    });

1070
    testUsingOsxContext('extract build name from pubspec.yaml', () async {
1071 1072 1073 1074 1075 1076 1077 1078
      const String manifest = '''
name: test
version: 1.0.0
dependencies:
  flutter:
    sdk: flutter
flutter:
''';
1079
      const BuildInfo buildInfo = BuildInfo(BuildMode.release, null, treeShakeIcons: false);
1080
      await checkBuildVersion(
1081
        manifestString: manifest,
1082 1083
        buildInfo: buildInfo,
        expectedBuildName: '1.0.0',
1084
        expectedBuildNumber: '1.0.0',
1085 1086 1087
      );
    });

1088
    testUsingOsxContext('allow build info to override build name', () async {
1089 1090 1091 1092 1093 1094 1095 1096
      const String manifest = '''
name: test
version: 1.0.0+1
dependencies:
  flutter:
    sdk: flutter
flutter:
''';
1097
      const BuildInfo buildInfo = BuildInfo(BuildMode.release, null, buildName: '1.0.2', treeShakeIcons: false);
1098
      await checkBuildVersion(
1099
        manifestString: manifest,
1100 1101 1102 1103 1104 1105
        buildInfo: buildInfo,
        expectedBuildName: '1.0.2',
        expectedBuildNumber: '1',
      );
    });

1106 1107 1108 1109 1110 1111 1112 1113 1114
    testUsingOsxContext('allow build info to override build name with build number fallback', () async {
      const String manifest = '''
name: test
version: 1.0.0
dependencies:
  flutter:
    sdk: flutter
flutter:
''';
1115
      const BuildInfo buildInfo = BuildInfo(BuildMode.release, null, buildName: '1.0.2', treeShakeIcons: false);
1116 1117 1118 1119 1120 1121 1122 1123
      await checkBuildVersion(
        manifestString: manifest,
        buildInfo: buildInfo,
        expectedBuildName: '1.0.2',
        expectedBuildNumber: '1.0.2',
      );
    });

1124
    testUsingOsxContext('allow build info to override build number', () async {
1125 1126 1127 1128 1129 1130 1131 1132
      const String manifest = '''
name: test
version: 1.0.0+1
dependencies:
  flutter:
    sdk: flutter
flutter:
''';
1133
      const BuildInfo buildInfo = BuildInfo(BuildMode.release, null, buildNumber: '3', treeShakeIcons: false);
1134
      await checkBuildVersion(
1135
        manifestString: manifest,
1136 1137 1138 1139 1140 1141
        buildInfo: buildInfo,
        expectedBuildName: '1.0.0',
        expectedBuildNumber: '3',
      );
    });

1142
    testUsingOsxContext('allow build info to override build name and number', () async {
1143 1144 1145 1146 1147 1148 1149 1150
      const String manifest = '''
name: test
version: 1.0.0+1
dependencies:
  flutter:
    sdk: flutter
flutter:
''';
1151
      const BuildInfo buildInfo = BuildInfo(BuildMode.release, null, buildName: '1.0.2', buildNumber: '3', treeShakeIcons: false);
1152
      await checkBuildVersion(
1153
        manifestString: manifest,
1154 1155 1156 1157 1158 1159
        buildInfo: buildInfo,
        expectedBuildName: '1.0.2',
        expectedBuildNumber: '3',
      );
    });

1160
    testUsingOsxContext('allow build info to override build name and set number', () async {
1161 1162 1163 1164 1165 1166 1167 1168
      const String manifest = '''
name: test
version: 1.0.0
dependencies:
  flutter:
    sdk: flutter
flutter:
''';
1169
      const BuildInfo buildInfo = BuildInfo(BuildMode.release, null, buildName: '1.0.2', buildNumber: '3', treeShakeIcons: false);
1170
      await checkBuildVersion(
1171
        manifestString: manifest,
1172 1173 1174 1175 1176 1177
        buildInfo: buildInfo,
        expectedBuildName: '1.0.2',
        expectedBuildNumber: '3',
      );
    });

1178
    testUsingOsxContext('allow build info to set build name and number', () async {
1179 1180 1181 1182 1183 1184 1185
      const String manifest = '''
name: test
dependencies:
  flutter:
    sdk: flutter
flutter:
''';
1186
      const BuildInfo buildInfo = BuildInfo(BuildMode.release, null, buildName: '1.0.2', buildNumber: '3', treeShakeIcons: false);
1187
      await checkBuildVersion(
1188
        manifestString: manifest,
1189 1190 1191 1192 1193
        buildInfo: buildInfo,
        expectedBuildName: '1.0.2',
        expectedBuildNumber: '3',
      );
    });
1194 1195 1196 1197 1198 1199 1200 1201 1202

    testUsingOsxContext('default build name and number when version is missing', () async {
      const String manifest = '''
name: test
dependencies:
  flutter:
    sdk: flutter
flutter:
''';
1203
      const BuildInfo buildInfo = BuildInfo(BuildMode.release, null, treeShakeIcons: false);
1204 1205 1206 1207 1208 1209 1210
      await checkBuildVersion(
        manifestString: manifest,
        buildInfo: buildInfo,
        expectedBuildName: '1.0.0',
        expectedBuildNumber: '1',
      );
    });
1211
  });
1212
}