run_test.dart 23.2 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 7
import 'dart:async';
import 'package:file/file.dart';
import 'package:file/memory.dart';
8
import 'package:flutter_tools/src/application_package.dart';
9
import 'package:flutter_tools/src/artifacts.dart';
10
import 'package:flutter_tools/src/base/common.dart';
11
import 'package:flutter_tools/src/base/context.dart';
12
import 'package:flutter_tools/src/base/file_system.dart';
13
import 'package:flutter_tools/src/base/io.dart';
14
import 'package:flutter_tools/src/base/logger.dart';
15
import 'package:flutter_tools/src/base/user_messages.dart';
16
import 'package:flutter_tools/src/build_info.dart';
17
import 'package:flutter_tools/src/cache.dart';
18
import 'package:flutter_tools/src/commands/run.dart';
19
import 'package:flutter_tools/src/device.dart';
20
import 'package:flutter_tools/src/globals.dart' as globals;
21
import 'package:flutter_tools/src/reporting/reporting.dart';
22 23
import 'package:flutter_tools/src/runner/flutter_command.dart';
import 'package:mockito/mockito.dart';
24

25 26
import '../../src/common.dart';
import '../../src/context.dart';
27
import '../../src/fakes.dart';
28
import '../../src/mocks.dart';
29
import '../../src/testbed.dart';
30

31
void main() {
32
  group('run', () {
33 34
    MockApplicationPackageFactory mockApplicationPackageFactory;
    MockDeviceManager mockDeviceManager;
35
    FileSystem fileSystem;
36 37 38

    setUpAll(() {
      Cache.disableLocking();
39 40 41
    });

    setUp(() {
42 43
      mockApplicationPackageFactory = MockApplicationPackageFactory();
      mockDeviceManager = MockDeviceManager();
44
      fileSystem = MemoryFileSystem.test();
45 46
    });

47
    testUsingContext('fails when target not found', () async {
48
      final RunCommand command = RunCommand();
49
      applyMocksToCommand(command);
50
      try {
51
        await createTestCommandRunner(command).run(<String>['run', '-t', 'abc123', '--no-pub']);
52 53 54 55
        fail('Expect exception');
      } on ToolExit catch (e) {
        expect(e.exitCode ?? 1, 1);
      }
56 57 58 59
    }, overrides: <Type, Generator>{
      FileSystem: () => fileSystem,
      ProcessManager: () => FakeProcessManager.any(),
      Logger: () => BufferLogger.test(),
60
    });
61

62
    testUsingContext('does not support "--use-application-binary" and "--fast-start"', () async {
63 64 65
      fileSystem.file('lib/main.dart').createSync(recursive: true);
      fileSystem.file('pubspec.yaml').createSync();
      fileSystem.file('.packages').createSync();
66 67 68 69 70 71 72 73 74 75 76 77

      final RunCommand command = RunCommand();
      applyMocksToCommand(command);
      try {
        await createTestCommandRunner(command).run(<String>[
          'run',
          '--use-application-binary=app/bar/faz',
          '--fast-start',
          '--no-pub',
          '--show-test-device',
        ]);
        fail('Expect exception');
78
      } on Exception catch (e) {
79
        expect(e.toString(), isNot(contains('--fast-start is not supported with --use-application-binary')));
80 81
      }
    }, overrides: <Type, Generator>{
82
      FileSystem: () => fileSystem,
83
      ProcessManager: () => FakeProcessManager.any(),
84
      Logger: () => BufferLogger.test(),
85 86
    });

87
    testUsingContext('Walks upward looking for a pubspec.yaml and succeeds if found', () async {
88 89 90 91 92 93
      fileSystem.file('pubspec.yaml').createSync();
      fileSystem.file('.packages')
        .writeAsStringSync('\n');
      fileSystem.file('lib/main.dart')
        .createSync(recursive: true);
      fileSystem.currentDirectory = fileSystem.directory('a/b/c')
94 95 96 97 98 99 100 101 102 103
        ..createSync(recursive: true);

      final RunCommand command = RunCommand();
      applyMocksToCommand(command);
      try {
        await createTestCommandRunner(command).run(<String>[
          'run',
          '--no-pub',
        ]);
        fail('Expect exception');
104
      } on Exception catch (e) {
105
        expect(e, isA<ToolExit>());
106 107
      }
      final BufferLogger bufferLogger = globals.logger as BufferLogger;
108 109 110 111
      expect(
        bufferLogger.statusText,
        containsIgnoringWhitespace('Changing current working directory to:'),
      );
112
    }, overrides: <Type, Generator>{
113
      FileSystem: () => fileSystem,
114
      ProcessManager: () => FakeProcessManager.any(),
115
      Logger: () => BufferLogger.test(),
116 117 118
    });

    testUsingContext('Walks upward looking for a pubspec.yaml and exits if missing', () async {
119
      fileSystem.currentDirectory = fileSystem.directory('a/b/c')
120
        ..createSync(recursive: true);
121 122
      fileSystem.file('lib/main.dart')
        .createSync(recursive: true);
123 124 125 126 127 128 129 130 131

      final RunCommand command = RunCommand();
      applyMocksToCommand(command);
      try {
        await createTestCommandRunner(command).run(<String>[
          'run',
          '--no-pub',
        ]);
        fail('Expect exception');
132
      } on Exception catch (e) {
133
        expect(e, isA<ToolExit>());
134 135 136
        expect(e.toString(), contains('No pubspec.yaml file found'));
      }
    }, overrides: <Type, Generator>{
137
      FileSystem: () => fileSystem,
138
      ProcessManager: () => FakeProcessManager.any(),
139
      Logger: () => BufferLogger.test(),
140 141
    });

142
    group('run app', () {
143
      MemoryFileSystem fs;
144
      MockArtifacts mockArtifacts;
145 146
      MockCache mockCache;
      MockProcessManager mockProcessManager;
147
      MockUsage mockUsage;
148 149
      Directory tempDir;

150
      setUp(() {
151
        mockArtifacts = MockArtifacts();
152
        mockCache = MockCache();
153
        mockUsage = MockUsage();
154 155 156 157 158 159 160
        fs = MemoryFileSystem();
        mockProcessManager = MockProcessManager();

        tempDir = fs.systemTempDirectory.createTempSync('flutter_run_test.');
        fs.currentDirectory = tempDir;

        tempDir.childFile('pubspec.yaml')
161
          .writeAsStringSync('name: flutter_app');
162
        tempDir.childFile('.packages')
163
          .writeAsStringSync('# Generated by pub on 2019-11-25 12:38:01.801784.');
164 165 166 167 168 169 170 171 172
        final Directory libDir = tempDir.childDirectory('lib');
        libDir.createSync();
        final File mainFile = libDir.childFile('main.dart');
        mainFile.writeAsStringSync('void main() {}');

        when(mockDeviceManager.hasSpecifiedDeviceId).thenReturn(false);
        when(mockDeviceManager.hasSpecifiedAllDevices).thenReturn(false);
      });

173
      testUsingContext('exits with a user message when no supported devices attached', () async {
174 175 176
        final RunCommand command = RunCommand();
        applyMocksToCommand(command);

177 178
        const List<Device> noDevices = <Device>[];
        when(mockDeviceManager.getDevices()).thenAnswer(
179
          (Invocation invocation) => Future<List<Device>>.value(noDevices)
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
        );
        when(mockDeviceManager.findTargetDevices(any)).thenAnswer(
          (Invocation invocation) => Future<List<Device>>.value(noDevices)
        );

        try {
          await createTestCommandRunner(command).run(<String>[
            'run',
            '--no-pub',
            '--no-hot',
          ]);
          fail('Expect exception');
        } on ToolExit catch (e) {
          expect(e.message, null);
        }

196 197 198 199
        expect(
          testLogger.statusText,
          containsIgnoringWhitespace(userMessages.flutterNoSupportedDevices),
        );
200 201 202
      }, overrides: <Type, Generator>{
        DeviceManager: () => mockDeviceManager,
        FileSystem: () => fs,
203 204 205
        ProcessManager: () => mockProcessManager,
      });

206 207 208 209 210
      testUsingContext('fails when targeted device is not Android with --device-user', () async {
        globals.fs.file('pubspec.yaml').createSync();
        globals.fs.file('.packages').writeAsStringSync('\n');
        globals.fs.file('lib/main.dart').createSync(recursive: true);
        final FakeDevice device = FakeDevice(isLocalEmulator: true);
211
        when(mockDeviceManager.getAllConnectedDevices()).thenAnswer((Invocation invocation) async {
212 213
          return <Device>[device];
        });
214
        when(mockDeviceManager.getDevices()).thenAnswer((Invocation invocation) async {
215 216
          return <Device>[device];
        });
217
        when(mockDeviceManager.findTargetDevices(any)).thenAnswer((Invocation invocation) async {
218 219
          return <Device>[device];
        });
220 221
        when(mockDeviceManager.hasSpecifiedAllDevices).thenReturn(false);
        when(mockDeviceManager.deviceDiscoverers).thenReturn(<DeviceDiscovery>[]);
222 223 224 225 226 227 228 229 230 231 232 233

        final RunCommand command = RunCommand();
        applyMocksToCommand(command);
        await expectLater(createTestCommandRunner(command).run(<String>[
          'run',
          '--no-pub',
          '--device-user',
          '10',
        ]), throwsToolExit(message: '--device-user is only supported for Android. At least one Android device is required.'));
      }, overrides: <Type, Generator>{
        FileSystem: () => MemoryFileSystem.test(),
        ProcessManager: () => FakeProcessManager.any(),
234
        DeviceManager: () => mockDeviceManager,
235
        Stdio: () => MockStdio(),
236 237
      });

238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
      testUsingContext('shows unsupported devices when no supported devices are found',  () async {
        final RunCommand command = RunCommand();
        applyMocksToCommand(command);

        final MockDevice mockDevice = MockDevice(TargetPlatform.android_arm);
        when(mockDevice.isLocalEmulator).thenAnswer((Invocation invocation) => Future<bool>.value(true));
        when(mockDevice.isSupported()).thenAnswer((Invocation invocation) => true);
        when(mockDevice.supportsFastStart).thenReturn(true);
        when(mockDevice.id).thenReturn('mock-id');
        when(mockDevice.name).thenReturn('mock-name');
        when(mockDevice.platformType).thenReturn(PlatformType.android);
        when(mockDevice.sdkNameAndVersion).thenAnswer((Invocation invocation) => Future<String>.value('api-14'));

        when(mockDeviceManager.getDevices()).thenAnswer((Invocation invocation) {
          return Future<List<Device>>.value(<Device>[
            mockDevice,
          ]);
        });

        when(mockDeviceManager.findTargetDevices(any)).thenAnswer(
            (Invocation invocation) => Future<List<Device>>.value(<Device>[]),
        );

        try {
          await createTestCommandRunner(command).run(<String>[
            'run',
            '--no-pub',
            '--no-hot',
          ]);
          fail('Expect exception');
        } on ToolExit catch (e) {
          expect(e.message, null);
        }

        expect(
          testLogger.statusText,
          containsIgnoringWhitespace(userMessages.flutterNoSupportedDevices),
        );
        expect(
          testLogger.statusText,
          containsIgnoringWhitespace(userMessages.flutterFoundButUnsupportedDevices),
        );
        expect(
          testLogger.statusText,
          containsIgnoringWhitespace(
            userMessages.flutterMissPlatformProjects(
              Device.devicesPlatformTypes(<Device>[mockDevice]),
            ),
          ),
        );
      }, overrides: <Type, Generator>{
        DeviceManager: () => mockDeviceManager,
        FileSystem: () => fs,
291 292 293 294 295 296 297 298
        ProcessManager: () => mockProcessManager,
      });

      testUsingContext('updates cache before checking for devices', () async {
        final RunCommand command = RunCommand();
        applyMocksToCommand(command);

        // Called as part of requiredArtifacts()
299
        when(mockDeviceManager.getDevices()).thenAnswer(
300
          (Invocation invocation) => Future<List<Device>>.value(<Device>[])
301
        );
302 303
        // No devices are attached, we just want to verify update the cache
        // BEFORE checking for devices
304 305 306 307 308 309 310 311 312 313 314 315 316
        when(mockDeviceManager.findTargetDevices(any)).thenAnswer(
          (Invocation invocation) => Future<List<Device>>.value(<Device>[])
        );

        try {
          await createTestCommandRunner(command).run(<String>[
            'run',
            '--no-pub',
          ]);
          fail('Exception expected');
        } on ToolExit catch (e) {
          // We expect a ToolExit because no devices are attached
          expect(e.message, null);
317 318
        } on Exception catch (e) {
          fail('ToolExit expected, got $e');
319 320 321
        }

        verifyInOrder(<void>[
322
          // cache update
323
          mockCache.updateAll(<DevelopmentArtifact>{DevelopmentArtifact.universal}),
324 325 326
          // as part of gathering `requiredArtifacts`
          mockDeviceManager.getDevices(),
          // in validateCommand()
327 328 329 330 331 332 333 334 335
          mockDeviceManager.findTargetDevices(any),
        ]);
      }, overrides: <Type, Generator>{
        ApplicationPackageFactory: () => mockApplicationPackageFactory,
        Cache: () => mockCache,
        DeviceManager: () => mockDeviceManager,
        FileSystem: () => fs,
        ProcessManager: () => mockProcessManager,
      });
336 337 338 339 340

      testUsingContext('passes device target platform to usage', () async {
        final RunCommand command = RunCommand();
        applyMocksToCommand(command);
        final MockDevice mockDevice = MockDevice(TargetPlatform.ios);
341
        when(mockDevice.supportsRuntimeMode(any)).thenAnswer((Invocation invocation) => true);
342
        when(mockDevice.isLocalEmulator).thenAnswer((Invocation invocation) => Future<bool>.value(false));
343
        when(mockDevice.getLogReader(app: anyNamed('app'))).thenReturn(FakeDeviceLogReader());
344
        when(mockDevice.supportsFastStart).thenReturn(true);
345
        when(mockDevice.sdkNameAndVersion).thenAnswer((Invocation invocation) => Future<String>.value('iOS 13'));
346 347 348 349 350 351 352 353 354
        // App fails to start because we're only interested in usage
        when(mockDevice.startApp(
          any,
          mainPath: anyNamed('mainPath'),
          debuggingOptions: anyNamed('debuggingOptions'),
          platformArgs: anyNamed('platformArgs'),
          route: anyNamed('route'),
          prebuiltApplication: anyNamed('prebuiltApplication'),
          ipv6: anyNamed('ipv6'),
355
          userIdentifier: anyNamed('userIdentifier'),
356 357 358 359 360 361 362 363 364
        )).thenAnswer((Invocation invocation) => Future<LaunchResult>.value(LaunchResult.failed()));

        when(mockArtifacts.getArtifactPath(
          Artifact.flutterPatchedSdkPath,
          platform: anyNamed('platform'),
          mode: anyNamed('mode'),
        )).thenReturn('/path/to/sdk');

        when(mockDeviceManager.getDevices()).thenAnswer(
365
          (Invocation invocation) => Future<List<Device>>.value(<Device>[mockDevice])
366 367 368 369 370 371
        );

        when(mockDeviceManager.findTargetDevices(any)).thenAnswer(
          (Invocation invocation) => Future<List<Device>>.value(<Device>[mockDevice])
        );

372
        final Directory tempDir = globals.fs.systemTempDirectory.createTempSync('flutter_run_test.');
373 374 375 376 377 378
        tempDir.childDirectory('ios').childFile('AppDelegate.swift').createSync(recursive: true);
        tempDir.childFile('.packages').createSync();
        tempDir.childDirectory('lib').childFile('main.dart').createSync(recursive: true);
        tempDir.childFile('pubspec.yaml')
          ..createSync()
          ..writeAsStringSync('# Hello, World');
379
        globals.fs.currentDirectory = tempDir;
380

381 382 383 384 385 386 387 388 389 390
        try {
          await createTestCommandRunner(command).run(<String>[
            'run',
            '--no-pub',
            '--no-hot',
          ]);
          fail('Exception expected');
        } on ToolExit catch (e) {
          // We expect a ToolExit because app does not start
          expect(e.message, null);
391 392
        } on Exception catch (e) {
          fail('ToolExit expected, got $e');
393 394 395 396 397 398 399
        }
        final List<dynamic> captures = verify(mockUsage.sendCommand(
          captureAny,
          parameters: captureAnyNamed('parameters'),
        )).captured;
        expect(captures[0], 'run');
        final Map<String, String> parameters = captures[1] as Map<String, String>;
400 401 402 403 404 405 406 407

        expect(parameters[cdKey(CustomDimensions.commandRunIsEmulator)], 'false');
        expect(parameters[cdKey(CustomDimensions.commandRunTargetName)], 'ios');
        expect(parameters[cdKey(CustomDimensions.commandRunProjectHostLanguage)], 'swift');
        expect(parameters[cdKey(CustomDimensions.commandRunTargetOsVersion)], 'iOS 13');
        expect(parameters[cdKey(CustomDimensions.commandRunModeName)], 'debug');
        expect(parameters[cdKey(CustomDimensions.commandRunProjectModule)], 'false');
        expect(parameters.containsKey(cdKey(CustomDimensions.commandRunAndroidEmbeddingVersion)), false);
408 409 410 411 412 413 414 415 416
      }, overrides: <Type, Generator>{
        ApplicationPackageFactory: () => mockApplicationPackageFactory,
        Artifacts: () => mockArtifacts,
        Cache: () => mockCache,
        DeviceManager: () => mockDeviceManager,
        FileSystem: () => fs,
        ProcessManager: () => mockProcessManager,
        Usage: () => mockUsage,
      });
417 418
    });

419 420 421
    group('dart-flags option', () {
      RunCommand command;
      List<String> args;
422 423
      MockDeviceManager mockDeviceManager;

424 425 426 427 428 429
      setUp(() {
        command = TestRunCommand();
        args = <String> [
          'run',
          '--dart-flags', '"--observe"',
          '--no-hot',
430
          '--no-pub',
431
        ];
432 433 434 435 436 437 438 439
        mockDeviceManager = MockDeviceManager();
        final FakeDevice fakeDevice = FakeDevice();
        when(mockDeviceManager.getDevices()).thenAnswer((Invocation invocation) {
          return Future<List<Device>>.value(<Device>[fakeDevice]);
        });
        when(mockDeviceManager.findTargetDevices(any)).thenAnswer(
          (Invocation invocation) => Future<List<Device>>.value(<Device>[fakeDevice])
        );
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489
      });

      testUsingContext('is populated in debug mode', () async {
        // FakeDevice.startApp checks that --dart-flags doesn't get dropped and
        // throws ToolExit with FakeDevice.kSuccess if the flag is populated.
        try {
          await createTestCommandRunner(command).run(args);
          fail('Expect exception');
        } on ToolExit catch (e) {
          expect(e.exitCode, FakeDevice.kSuccess);
        }
      }, overrides: <Type, Generator>{
        ApplicationPackageFactory: () => mockApplicationPackageFactory,
        DeviceManager: () => mockDeviceManager,
      });

      testUsingContext('is populated in profile mode', () async {
        args.add('--profile');

        // FakeDevice.startApp checks that --dart-flags doesn't get dropped and
        // throws ToolExit with FakeDevice.kSuccess if the flag is populated.
        try {
          await createTestCommandRunner(command).run(args);
          fail('Expect exception');
        } on ToolExit catch (e) {
          expect(e.exitCode, FakeDevice.kSuccess);
        }
      }, overrides: <Type, Generator>{
        ApplicationPackageFactory: () => mockApplicationPackageFactory,
        DeviceManager: () => mockDeviceManager,
      });

      testUsingContext('is not populated in release mode', () async {
        args.add('--release');

        // FakeDevice.startApp checks that --dart-flags *does* get dropped and
        // throws ToolExit with FakeDevice.kSuccess if the flag is set to the
        // empty string.
        try {
          await createTestCommandRunner(command).run(args);
          fail('Expect exception');
        } on ToolExit catch (e) {
          expect(e.exitCode, FakeDevice.kSuccess);
        }
      }, overrides: <Type, Generator>{
        ApplicationPackageFactory: () => mockApplicationPackageFactory,
        DeviceManager: () => mockDeviceManager,
      });
    });

490 491
    testUsingContext('should only request artifacts corresponding to connected devices', () async {
      when(mockDeviceManager.getDevices()).thenAnswer((Invocation invocation) {
492
        return Future<List<Device>>.value(<Device>[
493 494 495 496 497 498
          MockDevice(TargetPlatform.android_arm),
        ]);
      });

      expect(await RunCommand().requiredArtifacts, unorderedEquals(<DevelopmentArtifact>{
        DevelopmentArtifact.universal,
499
        DevelopmentArtifact.androidGenSnapshot,
500 501 502
      }));

      when(mockDeviceManager.getDevices()).thenAnswer((Invocation invocation) {
503
        return Future<List<Device>>.value(<Device>[
504 505 506 507 508 509 510 511 512 513
          MockDevice(TargetPlatform.ios),
        ]);
      });

      expect(await RunCommand().requiredArtifacts, unorderedEquals(<DevelopmentArtifact>{
        DevelopmentArtifact.universal,
        DevelopmentArtifact.iOS,
      }));

      when(mockDeviceManager.getDevices()).thenAnswer((Invocation invocation) {
514
        return Future<List<Device>>.value(<Device>[
515 516 517 518 519 520 521 522
          MockDevice(TargetPlatform.ios),
          MockDevice(TargetPlatform.android_arm),
        ]);
      });

      expect(await RunCommand().requiredArtifacts, unorderedEquals(<DevelopmentArtifact>{
        DevelopmentArtifact.universal,
        DevelopmentArtifact.iOS,
523
        DevelopmentArtifact.androidGenSnapshot,
524 525 526
      }));

      when(mockDeviceManager.getDevices()).thenAnswer((Invocation invocation) {
527
        return Future<List<Device>>.value(<Device>[
528
          MockDevice(TargetPlatform.web_javascript),
529 530 531 532 533 534 535 536 537 538
        ]);
      });

      expect(await RunCommand().requiredArtifacts, unorderedEquals(<DevelopmentArtifact>{
        DevelopmentArtifact.universal,
        DevelopmentArtifact.web,
      }));
    }, overrides: <Type, Generator>{
      DeviceManager: () => mockDeviceManager,
    });
539 540
  });
}
541

542
class MockArtifacts extends Mock implements Artifacts {}
543
class MockCache extends Mock implements Cache {}
544
class MockUsage extends Mock implements Usage {}
545

546 547 548 549 550 551 552
class MockDeviceManager extends Mock implements DeviceManager {}
class MockDevice extends Mock implements Device {
  MockDevice(this._targetPlatform);

  final TargetPlatform _targetPlatform;

  @override
553
  Future<TargetPlatform> get targetPlatform async => Future<TargetPlatform>.value(_targetPlatform);
Dan Field's avatar
Dan Field committed
554
}
555 556 557 558 559

class TestRunCommand extends RunCommand {
  @override
  // ignore: must_call_super
  Future<void> validateCommand() async {
560
    devices = await globals.deviceManager.getDevices();
561 562 563 564
  }
}

class FakeDevice extends Fake implements Device {
565 566 567
  FakeDevice({bool isLocalEmulator = false})
   : _isLocalEmulator = isLocalEmulator;

568 569
  static const int kSuccess = 1;
  static const int kFailure = -1;
570
  final TargetPlatform _targetPlatform = TargetPlatform.ios;
571
  final bool _isLocalEmulator;
572

573 574 575
  @override
  String get id => 'fake_device';

576 577 578
  void _throwToolExit(int code) => throwToolExit(null, exitCode: code);

  @override
579
  Future<bool> get isLocalEmulator => Future<bool>.value(_isLocalEmulator);
580

581 582 583
  @override
  bool supportsRuntimeMode(BuildMode mode) => true;

584 585 586
  @override
  bool get supportsHotReload => false;

587 588 589
  @override
  bool get supportsFastStart => false;

590 591 592 593
  @override
  Future<String> get sdkNameAndVersion => Future<String>.value('');

  @override
594 595 596 597
  DeviceLogReader getLogReader({
    ApplicationPackage app,
    bool includePastLogs = false,
  }) {
598
    return FakeDeviceLogReader();
599 600 601 602 603 604 605 606
  }

  @override
  String get name => 'FakeDevice';

  @override
  Future<TargetPlatform> get targetPlatform async => _targetPlatform;

607 608 609
  @override
  final PlatformType platformType = PlatformType.ios;

610 611 612 613 614 615 616 617 618 619
  @override
  Future<LaunchResult> startApp(
    ApplicationPackage package, {
    String mainPath,
    String route,
    DebuggingOptions debuggingOptions,
    Map<String, dynamic> platformArgs,
    bool prebuiltApplication = false,
    bool usesTerminalUi = true,
    bool ipv6 = false,
620
    String userIdentifier,
621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639
  }) async {
    final String dartFlags = debuggingOptions.dartFlags;
    // In release mode, --dart-flags should be set to the empty string and
    // provided flags should be dropped. In debug and profile modes,
    // --dart-flags should not be empty.
    if (debuggingOptions.buildInfo.isRelease) {
      if (dartFlags.isNotEmpty) {
        _throwToolExit(kFailure);
      }
      _throwToolExit(kSuccess);
    } else {
      if (dartFlags.isEmpty) {
        _throwToolExit(kFailure);
      }
      _throwToolExit(kSuccess);
    }
    return null;
  }
}