run_test.dart 23.5 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
        when(mockDeviceManager.findTargetDevices(any, timeout: anyNamed('timeout'))).thenAnswer(
182 183 184 185 186 187 188 189 190 191 192 193 194 195
          (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, timeout: anyNamed('timeout'))).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
      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,
          ]);
        });

257
        when(mockDeviceManager.findTargetDevices(any, timeout: anyNamed('timeout'))).thenAnswer(
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
            (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
        const Duration timeout = Duration(seconds: 10);
        when(mockDeviceManager.findTargetDevices(any, timeout: timeout)).thenAnswer(
306 307 308 309 310 311 312
          (Invocation invocation) => Future<List<Device>>.value(<Device>[])
        );

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

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

      testUsingContext('passes device target platform to usage', () async {
        final RunCommand command = RunCommand();
        applyMocksToCommand(command);
        final MockDevice mockDevice = MockDevice(TargetPlatform.ios);
344
        when(mockDevice.supportsRuntimeMode(any)).thenAnswer((Invocation invocation) => true);
345
        when(mockDevice.isLocalEmulator).thenAnswer((Invocation invocation) => Future<bool>.value(false));
346
        when(mockDevice.getLogReader(app: anyNamed('app'))).thenReturn(FakeDeviceLogReader());
347
        when(mockDevice.supportsFastStart).thenReturn(true);
348
        when(mockDevice.sdkNameAndVersion).thenAnswer((Invocation invocation) => Future<String>.value('iOS 13'));
349 350 351 352 353 354 355 356 357
        // 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'),
358
          userIdentifier: anyNamed('userIdentifier'),
359 360 361 362 363 364 365 366 367
        )).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(
368
          (Invocation invocation) => Future<List<Device>>.value(<Device>[mockDevice])
369 370
        );

371
        when(mockDeviceManager.findTargetDevices(any, timeout: anyNamed('timeout'))).thenAnswer(
372 373 374
          (Invocation invocation) => Future<List<Device>>.value(<Device>[mockDevice])
        );

375
        final Directory tempDir = globals.fs.systemTempDirectory.createTempSync('flutter_run_test.');
376 377 378 379 380 381
        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');
382
        globals.fs.currentDirectory = tempDir;
383

384 385 386 387 388 389 390 391 392 393
        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);
394 395
        } on Exception catch (e) {
          fail('ToolExit expected, got $e');
396 397 398 399 400 401 402
        }
        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>;
403 404 405 406 407 408 409 410

        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);
411 412 413 414 415 416 417 418 419
      }, overrides: <Type, Generator>{
        ApplicationPackageFactory: () => mockApplicationPackageFactory,
        Artifacts: () => mockArtifacts,
        Cache: () => mockCache,
        DeviceManager: () => mockDeviceManager,
        FileSystem: () => fs,
        ProcessManager: () => mockProcessManager,
        Usage: () => mockUsage,
      });
420 421
    });

422 423 424
    group('dart-flags option', () {
      RunCommand command;
      List<String> args;
425 426
      MockDeviceManager mockDeviceManager;

427 428 429 430 431 432
      setUp(() {
        command = TestRunCommand();
        args = <String> [
          'run',
          '--dart-flags', '"--observe"',
          '--no-hot',
433
          '--no-pub',
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]);
        });
440
        when(mockDeviceManager.findTargetDevices(any, timeout: anyNamed('timeout'))).thenAnswer(
441 442
          (Invocation invocation) => Future<List<Device>>.value(<Device>[fakeDevice])
        );
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 490 491 492
      });

      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,
      });
    });

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

      expect(await RunCommand().requiredArtifacts, unorderedEquals(<DevelopmentArtifact>{
        DevelopmentArtifact.universal,
502
        DevelopmentArtifact.androidGenSnapshot,
503 504 505
      }));

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

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

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

      expect(await RunCommand().requiredArtifacts, unorderedEquals(<DevelopmentArtifact>{
        DevelopmentArtifact.universal,
        DevelopmentArtifact.iOS,
526
        DevelopmentArtifact.androidGenSnapshot,
527 528 529
      }));

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

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

545
class MockArtifacts extends Mock implements Artifacts {}
546
class MockCache extends Mock implements Cache {}
547
class MockUsage extends Mock implements Usage {}
548

549 550 551 552 553 554 555
class MockDeviceManager extends Mock implements DeviceManager {}
class MockDevice extends Mock implements Device {
  MockDevice(this._targetPlatform);

  final TargetPlatform _targetPlatform;

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

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

class FakeDevice extends Fake implements Device {
568 569 570
  FakeDevice({bool isLocalEmulator = false})
   : _isLocalEmulator = isLocalEmulator;

571 572
  static const int kSuccess = 1;
  static const int kFailure = -1;
573
  final TargetPlatform _targetPlatform = TargetPlatform.ios;
574
  final bool _isLocalEmulator;
575

576 577 578
  @override
  String get id => 'fake_device';

579 580 581
  void _throwToolExit(int code) => throwToolExit(null, exitCode: code);

  @override
582
  Future<bool> get isLocalEmulator => Future<bool>.value(_isLocalEmulator);
583

584 585 586
  @override
  bool supportsRuntimeMode(BuildMode mode) => true;

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

590 591 592
  @override
  bool get supportsFastStart => false;

593 594 595 596
  @override
  Future<String> get sdkNameAndVersion => Future<String>.value('');

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

  @override
  String get name => 'FakeDevice';

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

610 611 612
  @override
  final PlatformType platformType = PlatformType.ios;

613 614 615 616 617 618 619 620 621 622
  @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,
623
    String userIdentifier,
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642
  }) 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;
  }
}