xcodeproj_test.dart 26.2 KB
Newer Older
1 2 3
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
4

5 6
import 'dart:async';

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 12
import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/ios/xcodeproj.dart';
13
import 'package:flutter_tools/src/project.dart';
14 15 16 17
import 'package:mockito/mockito.dart';
import 'package:platform/platform.dart';
import 'package:process/process.dart';

18 19
import '../../src/common.dart';
import '../../src/context.dart';
20
import '../../src/mocks.dart' as mocks;
21
import '../../src/pubspec_schema.dart';
22 23

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

void main() {
26
  group('xcodebuild versioning', () {
27
    mocks.MockProcessManager mockProcessManager;
28 29 30 31 32
    XcodeProjectInterpreter xcodeProjectInterpreter;
    FakePlatform macOS;
    FileSystem fs;

    setUp(() {
33
      mockProcessManager = mocks.MockProcessManager();
34
      xcodeProjectInterpreter = XcodeProjectInterpreter();
35
      macOS = fakePlatform('macos');
36
      fs = MemoryFileSystem();
37 38 39 40 41 42 43
      fs.file(xcodebuild).createSync(recursive: true);
    });

    void testUsingOsxContext(String description, dynamic testMethod()) {
      testUsingContext(description, testMethod, overrides: <Type, Generator>{
        Platform: () => macOS,
        FileSystem: () => fs,
44
        ProcessManager: () => mockProcessManager,
45 46 47 48 49
      });
    }

    testUsingOsxContext('versionText returns null when xcodebuild is not installed', () {
      when(mockProcessManager.runSync(<String>[xcodebuild, '-version']))
50
          .thenThrow(const ProcessException(xcodebuild, <String>['-version']));
51 52 53 54 55
      expect(xcodeProjectInterpreter.versionText, isNull);
    });

    testUsingOsxContext('versionText returns null when xcodebuild is not fully installed', () {
      when(mockProcessManager.runSync(<String>[xcodebuild, '-version'])).thenReturn(
56
        ProcessResult(
57 58 59 60 61 62 63 64 65 66 67 68 69
          0,
          1,
          "xcode-select: error: tool 'xcodebuild' requires Xcode, "
          "but active developer directory '/Library/Developer/CommandLineTools' "
          'is a command line tools instance',
          '',
        ),
      );
      expect(xcodeProjectInterpreter.versionText, isNull);
    });

    testUsingOsxContext('versionText returns formatted version text', () {
      when(mockProcessManager.runSync(<String>[xcodebuild, '-version']))
70
          .thenReturn(ProcessResult(1, 0, 'Xcode 8.3.3\nBuild version 8E3004b', ''));
71 72 73 74 75
      expect(xcodeProjectInterpreter.versionText, 'Xcode 8.3.3, Build version 8E3004b');
    });

    testUsingOsxContext('versionText handles Xcode version string with unexpected format', () {
      when(mockProcessManager.runSync(<String>[xcodebuild, '-version']))
76
          .thenReturn(ProcessResult(1, 0, 'Xcode Ultra5000\nBuild version 8E3004b', ''));
77 78 79 80 81
      expect(xcodeProjectInterpreter.versionText, 'Xcode Ultra5000, Build version 8E3004b');
    });

    testUsingOsxContext('majorVersion returns major version', () {
      when(mockProcessManager.runSync(<String>[xcodebuild, '-version']))
82 83
          .thenReturn(ProcessResult(1, 0, 'Xcode 10.3.3\nBuild version 8E3004b', ''));
      expect(xcodeProjectInterpreter.majorVersion, 10);
84 85 86 87
    });

    testUsingOsxContext('majorVersion is null when version has unexpected format', () {
      when(mockProcessManager.runSync(<String>[xcodebuild, '-version']))
88
          .thenReturn(ProcessResult(1, 0, 'Xcode Ultra5000\nBuild version 8E3004b', ''));
89 90 91 92 93
      expect(xcodeProjectInterpreter.majorVersion, isNull);
    });

    testUsingOsxContext('minorVersion returns minor version', () {
      when(mockProcessManager.runSync(<String>[xcodebuild, '-version']))
94
          .thenReturn(ProcessResult(1, 0, 'Xcode 8.3.3\nBuild version 8E3004b', ''));
95 96 97 98 99
      expect(xcodeProjectInterpreter.minorVersion, 3);
    });

    testUsingOsxContext('minorVersion returns 0 when minor version is unspecified', () {
      when(mockProcessManager.runSync(<String>[xcodebuild, '-version']))
100
          .thenReturn(ProcessResult(1, 0, 'Xcode 8\nBuild version 8E3004b', ''));
101 102 103 104 105
      expect(xcodeProjectInterpreter.minorVersion, 0);
    });

    testUsingOsxContext('minorVersion is null when version has unexpected format', () {
      when(mockProcessManager.runSync(<String>[xcodebuild, '-version']))
106
          .thenReturn(ProcessResult(1, 0, 'Xcode Ultra5000\nBuild version 8E3004b', ''));
107 108 109 110 111 112 113
      expect(xcodeProjectInterpreter.minorVersion, isNull);
    });

    testUsingContext('isInstalled is false when not on MacOS', () {
      fs.file(xcodebuild).deleteSync();
      expect(xcodeProjectInterpreter.isInstalled, isFalse);
    }, overrides: <Type, Generator>{
114
      Platform: () => fakePlatform('notMacOS'),
115 116 117 118 119 120 121 122 123
    });

    testUsingOsxContext('isInstalled is false when xcodebuild does not exist', () {
      fs.file(xcodebuild).deleteSync();
      expect(xcodeProjectInterpreter.isInstalled, isFalse);
    });

    testUsingOsxContext('isInstalled is false when Xcode is not fully installed', () {
      when(mockProcessManager.runSync(<String>[xcodebuild, '-version'])).thenReturn(
124
        ProcessResult(
125 126 127 128 129 130 131 132 133 134 135 136 137
          0,
          1,
          "xcode-select: error: tool 'xcodebuild' requires Xcode, "
          "but active developer directory '/Library/Developer/CommandLineTools' "
          'is a command line tools instance',
          '',
        ),
      );
      expect(xcodeProjectInterpreter.isInstalled, isFalse);
    });

    testUsingOsxContext('isInstalled is false when version has unexpected format', () {
      when(mockProcessManager.runSync(<String>[xcodebuild, '-version']))
138
          .thenReturn(ProcessResult(1, 0, 'Xcode Ultra5000\nBuild version 8E3004b', ''));
139 140 141 142 143
      expect(xcodeProjectInterpreter.isInstalled, isFalse);
    });

    testUsingOsxContext('isInstalled is true when version has expected format', () {
      when(mockProcessManager.runSync(<String>[xcodebuild, '-version']))
144
          .thenReturn(ProcessResult(1, 0, 'Xcode 8.3.3\nBuild version 8E3004b', ''));
145 146
      expect(xcodeProjectInterpreter.isInstalled, isTrue);
    });
147

148
    testUsingOsxContext('build settings is empty when xcodebuild failed to get the build settings', () async {
149 150 151 152
      when(mockProcessManager.runSync(
               argThat(contains(xcodebuild)),
               workingDirectory: anyNamed('workingDirectory'),
               environment: anyNamed('environment')))
153
          .thenReturn(ProcessResult(0, 1, '', ''));
154
      expect(await xcodeProjectInterpreter.getBuildSettings('', ''), const <String, String>{});
155
    });
156 157 158

    testUsingContext('build settings flakes', () async {
      const Duration delay = Duration(seconds: 1);
159 160 161 162
      mockProcessManager.processFactory = mocks.flakyProcessFactory(
        flakes: 1,
        delay: delay + const Duration(seconds: 1),
      );
163
      expect(await xcodeProjectInterpreter.getBuildSettings(
164 165 166 167 168 169 170 171 172 173 174
                 '', '', timeout: delay),
             const <String, String>{});
      // build settings times out and is killed once, then succeeds.
      verify(mockProcessManager.killPid(any)).called(1);
      // The verbose logs should tell us something timed out.
      expect(testLogger.traceText, contains('timed out'));
    }, overrides: <Type, Generator>{
      Platform: () => macOS,
      FileSystem: () => fs,
      ProcessManager: () => mockProcessManager,
    });
175
  });
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192

  group('xcodebuild -list', () {
    mocks.MockProcessManager mockProcessManager;
    FakePlatform macOS;
    FileSystem fs;

    setUp(() {
      mockProcessManager = mocks.MockProcessManager();
      macOS = fakePlatform('macos');
      fs = MemoryFileSystem();
      fs.file(xcodebuild).createSync(recursive: true);
    });

    void testUsingOsxContext(String description, dynamic testMethod()) {
      testUsingContext(description, testMethod, overrides: <Type, Generator>{
        Platform: () => macOS,
        FileSystem: () => fs,
193
        ProcessManager: () => mockProcessManager,
194 195 196 197 198
      });
    }

    testUsingOsxContext('getInfo returns something when xcodebuild -list succeeds', () async {
      const String workingDirectory = '/';
199 200 201 202 203
      when(mockProcessManager.run(
        <String>[xcodebuild, '-list'],
        environment: anyNamed('environment'),
        workingDirectory: workingDirectory),
      ).thenAnswer((_) {
204 205 206 207 208 209 210 211 212
        return Future<ProcessResult>.value(ProcessResult(1, 0, '', ''));
      });
      final XcodeProjectInterpreter xcodeProjectInterpreter = XcodeProjectInterpreter();
      expect(await xcodeProjectInterpreter.getInfo(workingDirectory), isNotNull);
    });

    testUsingOsxContext('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.';
213 214 215 216 217
      when(mockProcessManager.run(
        <String>[xcodebuild, '-list'],
        environment: anyNamed('environment'),
        workingDirectory: workingDirectory),
      ).thenAnswer((_) {
218 219 220 221 222 223 224 225 226
        return Future<ProcessResult>.value(ProcessResult(1, 66, '', stderr));
      });
      final XcodeProjectInterpreter xcodeProjectInterpreter = XcodeProjectInterpreter();
      expect(
          () async => await xcodeProjectInterpreter.getInfo(workingDirectory),
          throwsToolExit(message: stderr));
    });
  });

227 228
  group('Xcode project properties', () {
    test('properties from default project can be parsed', () {
229
      const String output = '''
230 231 232 233 234 235 236 237 238 239 240 241 242 243
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

''';
244
      final XcodeProjectInfo info = XcodeProjectInfo.fromXcodeBuildOutput(output);
245 246 247 248 249
      expect(info.targets, <String>['Runner']);
      expect(info.schemes, <String>['Runner']);
      expect(info.buildConfigurations, <String>['Debug', 'Release']);
    });
    test('properties from project with custom schemes can be parsed', () {
250
      const String output = '''
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
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

''';
268
      final XcodeProjectInfo info = XcodeProjectInfo.fromXcodeBuildOutput(output);
269 270 271 272 273 274 275 276 277 278 279
      expect(info.targets, <String>['Runner']);
      expect(info.schemes, <String>['Free', 'Paid']);
      expect(info.buildConfigurations, <String>['Debug (Free)', 'Debug (Paid)', 'Release (Free)', 'Release (Paid)']);
    });
    test('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');
    });
    test('expected build configuration for non-flavored build is derived from BuildMode', () {
      expect(XcodeProjectInfo.expectedBuildConfigurationFor(BuildInfo.debug, 'Runner'), 'Debug');
280
      expect(XcodeProjectInfo.expectedBuildConfigurationFor(BuildInfo.profile, 'Runner'), 'Profile');
281 282 283 284 285 286 287 288 289
      expect(XcodeProjectInfo.expectedBuildConfigurationFor(BuildInfo.release, 'Runner'), 'Release');
    });
    test('expected scheme for flavored build is the title-cased flavor', () {
      expect(XcodeProjectInfo.expectedSchemeFor(const BuildInfo(BuildMode.debug, 'hello')), 'Hello');
      expect(XcodeProjectInfo.expectedSchemeFor(const BuildInfo(BuildMode.profile, 'HELLO')), 'HELLO');
      expect(XcodeProjectInfo.expectedSchemeFor(const BuildInfo(BuildMode.release, 'Hello')), 'Hello');
    });
    test('expected build configuration for flavored build is Mode-Flavor', () {
      expect(XcodeProjectInfo.expectedBuildConfigurationFor(const BuildInfo(BuildMode.debug, 'hello'), 'Hello'), 'Debug-Hello');
290
      expect(XcodeProjectInfo.expectedBuildConfigurationFor(const BuildInfo(BuildMode.profile, 'HELLO'), 'Hello'), 'Profile-Hello');
291 292 293
      expect(XcodeProjectInfo.expectedBuildConfigurationFor(const BuildInfo(BuildMode.release, 'Hello'), 'Hello'), 'Release-Hello');
    });
    test('scheme for default project is Runner', () {
294
      final XcodeProjectInfo info = XcodeProjectInfo(<String>['Runner'], <String>['Debug', 'Release'], <String>['Runner']);
295 296 297 298 299 300
      expect(info.schemeFor(BuildInfo.debug), 'Runner');
      expect(info.schemeFor(BuildInfo.profile), 'Runner');
      expect(info.schemeFor(BuildInfo.release), 'Runner');
      expect(info.schemeFor(const BuildInfo(BuildMode.debug, 'unknown')), isNull);
    });
    test('build configuration for default project is matched against BuildMode', () {
301
      final XcodeProjectInfo info = XcodeProjectInfo(<String>['Runner'], <String>['Debug', 'Profile', 'Release'], <String>['Runner']);
302
      expect(info.buildConfigurationFor(BuildInfo.debug, 'Runner'), 'Debug');
303
      expect(info.buildConfigurationFor(BuildInfo.profile, 'Runner'), 'Profile');
304 305 306
      expect(info.buildConfigurationFor(BuildInfo.release, 'Runner'), 'Release');
    });
    test('scheme for project with custom schemes is matched against flavor', () {
307
      final XcodeProjectInfo info = XcodeProjectInfo(
308 309 310 311 312 313 314 315 316 317 318
        <String>['Runner'],
        <String>['Debug (Free)', 'Debug (Paid)', 'Release (Free)', 'Release (Paid)'],
        <String>['Free', 'Paid'],
      );
      expect(info.schemeFor(const BuildInfo(BuildMode.debug, 'free')), 'Free');
      expect(info.schemeFor(const BuildInfo(BuildMode.profile, 'Free')), 'Free');
      expect(info.schemeFor(const BuildInfo(BuildMode.release, 'paid')), 'Paid');
      expect(info.schemeFor(const BuildInfo(BuildMode.debug, null)), isNull);
      expect(info.schemeFor(const BuildInfo(BuildMode.debug, 'unknown')), isNull);
    });
    test('build configuration for project with custom schemes is matched against BuildMode and flavor', () {
319
      final XcodeProjectInfo info = XcodeProjectInfo(
320
        <String>['Runner'],
321
        <String>['debug (free)', 'Debug paid', 'profile - Free', 'Profile-Paid', 'release - Free', 'Release-Paid'],
322 323 324 325
        <String>['Free', 'Paid'],
      );
      expect(info.buildConfigurationFor(const BuildInfo(BuildMode.debug, 'free'), 'Free'), 'debug (free)');
      expect(info.buildConfigurationFor(const BuildInfo(BuildMode.debug, 'Paid'), 'Paid'), 'Debug paid');
326
      expect(info.buildConfigurationFor(const BuildInfo(BuildMode.profile, 'FREE'), 'Free'), 'profile - Free');
327 328 329
      expect(info.buildConfigurationFor(const BuildInfo(BuildMode.release, 'paid'), 'Paid'), 'Release-Paid');
    });
    test('build configuration for project with inconsistent naming is null', () {
330
      final XcodeProjectInfo info = XcodeProjectInfo(
331 332 333 334 335 336 337 338 339
        <String>['Runner'],
        <String>['Debug-F', 'Dbg Paid', 'Rel Free', 'Release Full'],
        <String>['Free', 'Paid'],
      );
      expect(info.buildConfigurationFor(const BuildInfo(BuildMode.debug, 'Free'), 'Free'), null);
      expect(info.buildConfigurationFor(const BuildInfo(BuildMode.profile, 'Free'), 'Free'), null);
      expect(info.buildConfigurationFor(const BuildInfo(BuildMode.release, 'Paid'), 'Paid'), null);
    });
  });
340 341 342 343 344 345 346 347

  group('updateGeneratedXcodeProperties', () {
    MockLocalEngineArtifacts mockArtifacts;
    MockProcessManager mockProcessManager;
    FakePlatform macOS;
    FileSystem fs;

    setUp(() {
348 349 350
      fs = MemoryFileSystem();
      mockArtifacts = MockLocalEngineArtifacts();
      mockProcessManager = MockProcessManager();
351 352 353 354 355 356 357 358 359
      macOS = fakePlatform('macos');
      fs.file(xcodebuild).createSync(recursive: true);
    });

    void testUsingOsxContext(String description, dynamic testMethod()) {
      testUsingContext(description, testMethod, overrides: <Type, Generator>{
        Artifacts: () => mockArtifacts,
        Platform: () => macOS,
        FileSystem: () => fs,
360
        ProcessManager: () => mockProcessManager,
361 362 363
      });
    }

364
    testUsingOsxContext('sets ARCHS=armv7 when armv7 local engine is set', () async {
365 366
      when(mockArtifacts.getArtifactPath(Artifact.flutterFramework,
          platform: TargetPlatform.ios, mode: anyNamed('mode'))).thenReturn('engine');
367
      when(mockArtifacts.engineOutPath).thenReturn(fs.path.join('out', 'ios_profile_arm'));
368

369
      const BuildInfo buildInfo = BuildInfo(BuildMode.debug, null);
370
      final FlutterProject project = FlutterProject.fromPath('path/to/project');
371 372
      await updateGeneratedXcodeProperties(
        project: project,
373 374 375 376 377 378 379 380
        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=armv7'), isTrue);
381 382 383 384 385 386

      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=armv7'), isTrue);
387 388
    });

389
    testUsingOsxContext('sets TRACK_WIDGET_CREATION=true when trackWidgetCreation is true', () async {
390 391
      when(mockArtifacts.getArtifactPath(Artifact.flutterFramework,
          platform: TargetPlatform.ios, mode: anyNamed('mode'))).thenReturn('engine');
392
      when(mockArtifacts.engineOutPath).thenReturn(fs.path.join('out', 'ios_profile_arm'));
393
      const BuildInfo buildInfo = BuildInfo(BuildMode.debug, null, trackWidgetCreation: true);
394
      final FlutterProject project = FlutterProject.fromPath('path/to/project');
395 396
      await updateGeneratedXcodeProperties(
        project: project,
397 398 399 400 401 402 403 404
        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('TRACK_WIDGET_CREATION=true'), isTrue);
405 406 407 408 409 410

      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('TRACK_WIDGET_CREATION=true'), isTrue);
411 412 413
    });

    testUsingOsxContext('does not set TRACK_WIDGET_CREATION when trackWidgetCreation is false', () async {
414 415
      when(mockArtifacts.getArtifactPath(Artifact.flutterFramework,
          platform: TargetPlatform.ios, mode: anyNamed('mode'))).thenReturn('engine');
416
      when(mockArtifacts.engineOutPath).thenReturn(fs.path.join('out', 'ios_profile_arm'));
417
      const BuildInfo buildInfo = BuildInfo(BuildMode.debug, null);
418
      final FlutterProject project = FlutterProject.fromPath('path/to/project');
419 420
      await updateGeneratedXcodeProperties(
        project: project,
421 422 423 424 425 426 427 428
        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('TRACK_WIDGET_CREATION=true'), isFalse);
429 430 431 432 433 434

      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('TRACK_WIDGET_CREATION=true'), isFalse);
435 436
    });

437
    testUsingOsxContext('sets ARCHS=armv7 when armv7 local engine is set', () async {
438 439
      when(mockArtifacts.getArtifactPath(Artifact.flutterFramework,
          platform: TargetPlatform.ios, mode: anyNamed('mode'))).thenReturn('engine');
440
      when(mockArtifacts.engineOutPath).thenReturn(fs.path.join('out', 'ios_profile'));
441
      const BuildInfo buildInfo = BuildInfo(BuildMode.debug, null);
442

443
      final FlutterProject project = FlutterProject.fromPath('path/to/project');
444 445
      await updateGeneratedXcodeProperties(
        project: project,
446 447 448 449 450 451 452 453 454
        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);
    });
455 456 457 458 459 460 461 462 463 464 465

    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({
466
      String manifestString,
467 468 469 470
      BuildInfo buildInfo,
      String expectedBuildName,
      String expectedBuildNumber,
    }) async {
471 472
      when(mockArtifacts.getArtifactPath(Artifact.flutterFramework,
          platform: TargetPlatform.ios, mode: anyNamed('mode'))).thenReturn('engine');
473 474 475 476 477 478 479
      when(mockArtifacts.engineOutPath).thenReturn(fs.path.join('out', 'ios'));

      final File manifestFile = fs.file('path/to/project/pubspec.yaml');
      manifestFile.createSync(recursive: true);
      manifestFile.writeAsStringSync(manifestString);

      // write schemaData otherwise pubspec.yaml file can't be loaded
480
      writeEmptySchemaFile(fs);
481

482
      await updateGeneratedXcodeProperties(
483
        project: FlutterProject.fromPath('path/to/project'),
484 485 486
        buildInfo: buildInfo,
      );

487
      final File localPropertiesFile = fs.file('path/to/project/ios/Flutter/Generated.xcconfig');
488 489
      expect(propertyFor('FLUTTER_BUILD_NAME', localPropertiesFile), expectedBuildName);
      expect(propertyFor('FLUTTER_BUILD_NUMBER', localPropertiesFile), expectedBuildNumber);
490
      expect(propertyFor('FLUTTER_BUILD_NUMBER', localPropertiesFile), isNotNull);
491 492
    }

493
    testUsingOsxContext('extract build name and number from pubspec.yaml', () async {
494 495 496 497 498 499 500 501 502
      const String manifest = '''
name: test
version: 1.0.0+1
dependencies:
  flutter:
    sdk: flutter
flutter:
''';

503
      const BuildInfo buildInfo = BuildInfo(BuildMode.release, null);
504
      await checkBuildVersion(
505
        manifestString: manifest,
506 507 508 509 510 511
        buildInfo: buildInfo,
        expectedBuildName: '1.0.0',
        expectedBuildNumber: '1',
      );
    });

512
    testUsingOsxContext('extract build name from pubspec.yaml', () async {
513 514 515 516 517 518 519 520
      const String manifest = '''
name: test
version: 1.0.0
dependencies:
  flutter:
    sdk: flutter
flutter:
''';
521
      const BuildInfo buildInfo = BuildInfo(BuildMode.release, null);
522
      await checkBuildVersion(
523
        manifestString: manifest,
524 525
        buildInfo: buildInfo,
        expectedBuildName: '1.0.0',
526
        expectedBuildNumber: '1.0.0',
527 528 529
      );
    });

530
    testUsingOsxContext('allow build info to override build name', () async {
531 532 533 534 535 536 537 538
      const String manifest = '''
name: test
version: 1.0.0+1
dependencies:
  flutter:
    sdk: flutter
flutter:
''';
539
      const BuildInfo buildInfo = BuildInfo(BuildMode.release, null, buildName: '1.0.2');
540
      await checkBuildVersion(
541
        manifestString: manifest,
542 543 544 545 546 547
        buildInfo: buildInfo,
        expectedBuildName: '1.0.2',
        expectedBuildNumber: '1',
      );
    });

548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565
    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:
''';
      const BuildInfo buildInfo = BuildInfo(BuildMode.release, null, buildName: '1.0.2');
      await checkBuildVersion(
        manifestString: manifest,
        buildInfo: buildInfo,
        expectedBuildName: '1.0.2',
        expectedBuildNumber: '1.0.2',
      );
    });

566
    testUsingOsxContext('allow build info to override build number', () async {
567 568 569 570 571 572 573 574
      const String manifest = '''
name: test
version: 1.0.0+1
dependencies:
  flutter:
    sdk: flutter
flutter:
''';
575
      const BuildInfo buildInfo = BuildInfo(BuildMode.release, null, buildNumber: '3');
576
      await checkBuildVersion(
577
        manifestString: manifest,
578 579 580 581 582 583
        buildInfo: buildInfo,
        expectedBuildName: '1.0.0',
        expectedBuildNumber: '3',
      );
    });

584
    testUsingOsxContext('allow build info to override build name and number', () async {
585 586 587 588 589 590 591 592
      const String manifest = '''
name: test
version: 1.0.0+1
dependencies:
  flutter:
    sdk: flutter
flutter:
''';
593
      const BuildInfo buildInfo = BuildInfo(BuildMode.release, null, buildName: '1.0.2', buildNumber: '3');
594
      await checkBuildVersion(
595
        manifestString: manifest,
596 597 598 599 600 601
        buildInfo: buildInfo,
        expectedBuildName: '1.0.2',
        expectedBuildNumber: '3',
      );
    });

602
    testUsingOsxContext('allow build info to override build name and set number', () async {
603 604 605 606 607 608 609 610
      const String manifest = '''
name: test
version: 1.0.0
dependencies:
  flutter:
    sdk: flutter
flutter:
''';
611
      const BuildInfo buildInfo = BuildInfo(BuildMode.release, null, buildName: '1.0.2', buildNumber: '3');
612
      await checkBuildVersion(
613
        manifestString: manifest,
614 615 616 617 618 619
        buildInfo: buildInfo,
        expectedBuildName: '1.0.2',
        expectedBuildNumber: '3',
      );
    });

620
    testUsingOsxContext('allow build info to set build name and number', () async {
621 622 623 624 625 626 627
      const String manifest = '''
name: test
dependencies:
  flutter:
    sdk: flutter
flutter:
''';
628
      const BuildInfo buildInfo = BuildInfo(BuildMode.release, null, buildName: '1.0.2', buildNumber: '3');
629
      await checkBuildVersion(
630
        manifestString: manifest,
631 632 633 634 635
        buildInfo: buildInfo,
        expectedBuildName: '1.0.2',
        expectedBuildNumber: '3',
      );
    });
636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652

    testUsingOsxContext('default build name and number when version is missing', () async {
      const String manifest = '''
name: test
dependencies:
  flutter:
    sdk: flutter
flutter:
''';
      const BuildInfo buildInfo = BuildInfo(BuildMode.release, null);
      await checkBuildVersion(
        manifestString: manifest,
        buildInfo: buildInfo,
        expectedBuildName: '1.0.0',
        expectedBuildNumber: '1',
      );
    });
653
  });
654
}
655 656

Platform fakePlatform(String name) {
657
  return FakePlatform.fromPlatform(const LocalPlatform())..operatingSystem = name;
658 659
}

660
class MockLocalEngineArtifacts extends Mock implements LocalEngineArtifacts {}
661 662
class MockProcessManager extends Mock implements ProcessManager {}
class MockXcodeProjectInterpreter extends Mock implements XcodeProjectInterpreter { }