2019-11-27 23:04:02 +00:00
|
|
|
// Copyright 2014 The Flutter Authors. All rights reserved.
|
2016-03-04 22:36:32 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-11-10 01:08:53 +00:00
|
|
|
import 'dart:async';
|
|
|
|
import 'package:file/file.dart';
|
|
|
|
import 'package:file/memory.dart';
|
2019-06-11 18:37:47 +00:00
|
|
|
import 'package:flutter_tools/src/application_package.dart';
|
2019-12-09 23:13:02 +00:00
|
|
|
import 'package:flutter_tools/src/artifacts.dart';
|
2016-11-14 03:09:03 +00:00
|
|
|
import 'package:flutter_tools/src/base/common.dart';
|
2019-11-10 01:08:53 +00:00
|
|
|
import 'package:flutter_tools/src/base/context.dart';
|
2019-12-10 18:26:14 +00:00
|
|
|
import 'package:flutter_tools/src/base/file_system.dart';
|
2020-06-08 18:53:17 +00:00
|
|
|
import 'package:flutter_tools/src/base/io.dart';
|
2019-12-10 18:26:14 +00:00
|
|
|
import 'package:flutter_tools/src/base/logger.dart';
|
2019-12-09 23:13:02 +00:00
|
|
|
import 'package:flutter_tools/src/base/user_messages.dart';
|
2019-04-08 20:49:09 +00:00
|
|
|
import 'package:flutter_tools/src/build_info.dart';
|
2019-06-11 18:37:47 +00:00
|
|
|
import 'package:flutter_tools/src/cache.dart';
|
2016-03-04 22:36:32 +00:00
|
|
|
import 'package:flutter_tools/src/commands/run.dart';
|
2019-04-08 20:49:09 +00:00
|
|
|
import 'package:flutter_tools/src/device.dart';
|
2020-01-06 19:04:20 +00:00
|
|
|
import 'package:flutter_tools/src/globals.dart' as globals;
|
2019-12-09 23:13:02 +00:00
|
|
|
import 'package:flutter_tools/src/reporting/reporting.dart';
|
2019-04-08 20:49:09 +00:00
|
|
|
import 'package:flutter_tools/src/runner/flutter_command.dart';
|
|
|
|
import 'package:mockito/mockito.dart';
|
2016-03-04 22:36:32 +00:00
|
|
|
|
2019-07-13 18:51:44 +00:00
|
|
|
import '../../src/common.dart';
|
|
|
|
import '../../src/context.dart';
|
2020-03-19 00:43:25 +00:00
|
|
|
import '../../src/fakes.dart';
|
2019-07-13 18:51:44 +00:00
|
|
|
import '../../src/mocks.dart';
|
2019-11-10 01:08:53 +00:00
|
|
|
import '../../src/testbed.dart';
|
2016-03-04 22:36:32 +00:00
|
|
|
|
2016-03-10 01:43:14 +00:00
|
|
|
void main() {
|
2019-06-08 02:33:14 +00:00
|
|
|
group('run', () {
|
2019-06-11 18:37:47 +00:00
|
|
|
MockApplicationPackageFactory mockApplicationPackageFactory;
|
|
|
|
MockDeviceManager mockDeviceManager;
|
2020-06-24 18:26:36 +00:00
|
|
|
FileSystem fileSystem;
|
2019-06-11 18:37:47 +00:00
|
|
|
|
|
|
|
setUpAll(() {
|
|
|
|
Cache.disableLocking();
|
2020-06-24 18:26:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
setUp(() {
|
2019-06-11 18:37:47 +00:00
|
|
|
mockApplicationPackageFactory = MockApplicationPackageFactory();
|
|
|
|
mockDeviceManager = MockDeviceManager();
|
2020-06-24 18:26:36 +00:00
|
|
|
fileSystem = MemoryFileSystem.test();
|
2019-06-11 18:37:47 +00:00
|
|
|
});
|
|
|
|
|
2016-11-14 03:09:03 +00:00
|
|
|
testUsingContext('fails when target not found', () async {
|
2018-09-12 06:29:29 +00:00
|
|
|
final RunCommand command = RunCommand();
|
2016-03-04 22:36:32 +00:00
|
|
|
applyMocksToCommand(command);
|
2016-11-14 03:09:03 +00:00
|
|
|
try {
|
2019-10-08 21:53:28 +00:00
|
|
|
await createTestCommandRunner(command).run(<String>['run', '-t', 'abc123', '--no-pub']);
|
2016-11-14 03:09:03 +00:00
|
|
|
fail('Expect exception');
|
|
|
|
} on ToolExit catch (e) {
|
|
|
|
expect(e.exitCode ?? 1, 1);
|
|
|
|
}
|
2020-06-24 18:26:36 +00:00
|
|
|
}, overrides: <Type, Generator>{
|
|
|
|
FileSystem: () => fileSystem,
|
|
|
|
ProcessManager: () => FakeProcessManager.any(),
|
|
|
|
Logger: () => BufferLogger.test(),
|
2016-03-04 22:36:32 +00:00
|
|
|
});
|
2019-04-08 20:49:09 +00:00
|
|
|
|
2019-12-10 18:26:14 +00:00
|
|
|
testUsingContext('does not support "--use-application-binary" and "--fast-start"', () async {
|
2020-06-24 18:26:36 +00:00
|
|
|
fileSystem.file('lib/main.dart').createSync(recursive: true);
|
|
|
|
fileSystem.file('pubspec.yaml').createSync();
|
|
|
|
fileSystem.file('.packages').createSync();
|
2019-12-10 18:26:14 +00:00
|
|
|
|
|
|
|
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');
|
2020-03-06 18:22:12 +00:00
|
|
|
} on Exception catch (e) {
|
2020-01-25 03:18:01 +00:00
|
|
|
expect(e.toString(), isNot(contains('--fast-start is not supported with --use-application-binary')));
|
2019-12-10 18:26:14 +00:00
|
|
|
}
|
|
|
|
}, overrides: <Type, Generator>{
|
2020-06-24 18:26:36 +00:00
|
|
|
FileSystem: () => fileSystem,
|
2019-12-10 18:26:14 +00:00
|
|
|
ProcessManager: () => FakeProcessManager.any(),
|
2020-06-24 18:26:36 +00:00
|
|
|
Logger: () => BufferLogger.test(),
|
2019-12-10 18:26:14 +00:00
|
|
|
});
|
|
|
|
|
2020-01-28 05:48:01 +00:00
|
|
|
testUsingContext('Walks upward looking for a pubspec.yaml and succeeds if found', () async {
|
2020-06-24 18:26:36 +00:00
|
|
|
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')
|
2020-01-28 05:48:01 +00:00
|
|
|
..createSync(recursive: true);
|
|
|
|
|
|
|
|
final RunCommand command = RunCommand();
|
|
|
|
applyMocksToCommand(command);
|
|
|
|
try {
|
|
|
|
await createTestCommandRunner(command).run(<String>[
|
|
|
|
'run',
|
|
|
|
'--no-pub',
|
|
|
|
]);
|
|
|
|
fail('Expect exception');
|
2020-03-06 18:22:12 +00:00
|
|
|
} on Exception catch (e) {
|
2020-04-02 17:57:07 +00:00
|
|
|
expect(e, isA<ToolExit>());
|
2020-01-28 05:48:01 +00:00
|
|
|
}
|
|
|
|
final BufferLogger bufferLogger = globals.logger as BufferLogger;
|
2020-04-28 20:12:12 +00:00
|
|
|
expect(
|
|
|
|
bufferLogger.statusText,
|
|
|
|
containsIgnoringWhitespace('Changing current working directory to:'),
|
|
|
|
);
|
2020-01-28 05:48:01 +00:00
|
|
|
}, overrides: <Type, Generator>{
|
2020-06-24 18:26:36 +00:00
|
|
|
FileSystem: () => fileSystem,
|
2020-01-28 05:48:01 +00:00
|
|
|
ProcessManager: () => FakeProcessManager.any(),
|
2020-06-24 18:26:36 +00:00
|
|
|
Logger: () => BufferLogger.test(),
|
2020-01-28 05:48:01 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
testUsingContext('Walks upward looking for a pubspec.yaml and exits if missing', () async {
|
2020-06-24 18:26:36 +00:00
|
|
|
fileSystem.currentDirectory = fileSystem.directory('a/b/c')
|
2020-01-28 05:48:01 +00:00
|
|
|
..createSync(recursive: true);
|
2020-06-24 18:26:36 +00:00
|
|
|
fileSystem.file('lib/main.dart')
|
|
|
|
.createSync(recursive: true);
|
2020-01-28 05:48:01 +00:00
|
|
|
|
|
|
|
final RunCommand command = RunCommand();
|
|
|
|
applyMocksToCommand(command);
|
|
|
|
try {
|
|
|
|
await createTestCommandRunner(command).run(<String>[
|
|
|
|
'run',
|
|
|
|
'--no-pub',
|
|
|
|
]);
|
|
|
|
fail('Expect exception');
|
2020-03-06 18:22:12 +00:00
|
|
|
} on Exception catch (e) {
|
2020-04-02 17:57:07 +00:00
|
|
|
expect(e, isA<ToolExit>());
|
2020-01-28 05:48:01 +00:00
|
|
|
expect(e.toString(), contains('No pubspec.yaml file found'));
|
|
|
|
}
|
|
|
|
}, overrides: <Type, Generator>{
|
2020-06-24 18:26:36 +00:00
|
|
|
FileSystem: () => fileSystem,
|
2020-01-28 05:48:01 +00:00
|
|
|
ProcessManager: () => FakeProcessManager.any(),
|
2020-06-24 18:26:36 +00:00
|
|
|
Logger: () => BufferLogger.test(),
|
2020-01-28 05:48:01 +00:00
|
|
|
});
|
|
|
|
|
2019-12-09 23:13:02 +00:00
|
|
|
group('run app', () {
|
2019-11-26 17:02:34 +00:00
|
|
|
MemoryFileSystem fs;
|
2019-12-09 23:13:02 +00:00
|
|
|
MockArtifacts mockArtifacts;
|
2019-11-26 17:02:34 +00:00
|
|
|
MockCache mockCache;
|
|
|
|
MockProcessManager mockProcessManager;
|
2019-12-09 23:13:02 +00:00
|
|
|
MockUsage mockUsage;
|
2019-11-26 17:02:34 +00:00
|
|
|
Directory tempDir;
|
|
|
|
|
2020-06-24 18:26:36 +00:00
|
|
|
setUp(() {
|
2019-12-09 23:13:02 +00:00
|
|
|
mockArtifacts = MockArtifacts();
|
2019-11-26 17:02:34 +00:00
|
|
|
mockCache = MockCache();
|
2019-12-09 23:13:02 +00:00
|
|
|
mockUsage = MockUsage();
|
2019-11-26 17:02:34 +00:00
|
|
|
fs = MemoryFileSystem();
|
|
|
|
mockProcessManager = MockProcessManager();
|
|
|
|
|
|
|
|
tempDir = fs.systemTempDirectory.createTempSync('flutter_run_test.');
|
|
|
|
fs.currentDirectory = tempDir;
|
|
|
|
|
|
|
|
tempDir.childFile('pubspec.yaml')
|
2020-03-05 07:03:26 +00:00
|
|
|
.writeAsStringSync('name: flutter_app');
|
2019-11-26 17:02:34 +00:00
|
|
|
tempDir.childFile('.packages')
|
2020-03-05 07:03:26 +00:00
|
|
|
.writeAsStringSync('# Generated by pub on 2019-11-25 12:38:01.801784.');
|
2019-11-26 17:02:34 +00:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
2019-12-09 23:13:02 +00:00
|
|
|
testUsingContext('exits with a user message when no supported devices attached', () async {
|
2019-11-26 17:02:34 +00:00
|
|
|
final RunCommand command = RunCommand();
|
|
|
|
applyMocksToCommand(command);
|
|
|
|
|
2019-12-09 23:13:02 +00:00
|
|
|
const List<Device> noDevices = <Device>[];
|
|
|
|
when(mockDeviceManager.getDevices()).thenAnswer(
|
2020-02-20 01:40:24 +00:00
|
|
|
(Invocation invocation) => Future<List<Device>>.value(noDevices)
|
2019-12-09 23:13:02 +00:00
|
|
|
);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2020-04-28 20:12:12 +00:00
|
|
|
expect(
|
|
|
|
testLogger.statusText,
|
|
|
|
containsIgnoringWhitespace(userMessages.flutterNoSupportedDevices),
|
|
|
|
);
|
2019-12-09 23:13:02 +00:00
|
|
|
}, overrides: <Type, Generator>{
|
|
|
|
DeviceManager: () => mockDeviceManager,
|
|
|
|
FileSystem: () => fs,
|
2020-06-03 23:14:38 +00:00
|
|
|
ProcessManager: () => mockProcessManager,
|
|
|
|
});
|
|
|
|
|
2020-06-08 18:28:02 +00:00
|
|
|
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);
|
2020-07-17 16:41:03 +00:00
|
|
|
when(mockDeviceManager.getAllConnectedDevices()).thenAnswer((Invocation invocation) async {
|
2020-06-08 18:28:02 +00:00
|
|
|
return <Device>[device];
|
|
|
|
});
|
2020-07-17 16:41:03 +00:00
|
|
|
when(mockDeviceManager.getDevices()).thenAnswer((Invocation invocation) async {
|
2020-06-08 18:28:02 +00:00
|
|
|
return <Device>[device];
|
|
|
|
});
|
2020-07-17 16:41:03 +00:00
|
|
|
when(mockDeviceManager.findTargetDevices(any)).thenAnswer((Invocation invocation) async {
|
2020-06-08 18:28:02 +00:00
|
|
|
return <Device>[device];
|
|
|
|
});
|
2020-07-17 16:41:03 +00:00
|
|
|
when(mockDeviceManager.hasSpecifiedAllDevices).thenReturn(false);
|
|
|
|
when(mockDeviceManager.deviceDiscoverers).thenReturn(<DeviceDiscovery>[]);
|
2020-06-08 18:28:02 +00:00
|
|
|
|
|
|
|
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(),
|
2020-07-17 16:41:03 +00:00
|
|
|
DeviceManager: () => mockDeviceManager,
|
2020-06-08 18:53:17 +00:00
|
|
|
Stdio: () => MockStdio(),
|
2020-06-08 18:28:02 +00:00
|
|
|
});
|
|
|
|
|
2020-06-03 23:14:38 +00:00
|
|
|
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,
|
2019-12-09 23:13:02 +00:00
|
|
|
ProcessManager: () => mockProcessManager,
|
|
|
|
});
|
|
|
|
|
|
|
|
testUsingContext('updates cache before checking for devices', () async {
|
|
|
|
final RunCommand command = RunCommand();
|
|
|
|
applyMocksToCommand(command);
|
|
|
|
|
|
|
|
// Called as part of requiredArtifacts()
|
2019-11-26 17:02:34 +00:00
|
|
|
when(mockDeviceManager.getDevices()).thenAnswer(
|
2020-02-20 01:40:24 +00:00
|
|
|
(Invocation invocation) => Future<List<Device>>.value(<Device>[])
|
2019-11-26 17:02:34 +00:00
|
|
|
);
|
2019-12-09 23:13:02 +00:00
|
|
|
// No devices are attached, we just want to verify update the cache
|
|
|
|
// BEFORE checking for devices
|
2019-11-26 17:02:34 +00:00
|
|
|
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);
|
2020-03-06 18:22:12 +00:00
|
|
|
} on Exception catch (e) {
|
|
|
|
fail('ToolExit expected, got $e');
|
2019-11-26 17:02:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
verifyInOrder(<void>[
|
2019-12-09 23:13:02 +00:00
|
|
|
// cache update
|
2019-11-26 17:02:34 +00:00
|
|
|
mockCache.updateAll(<DevelopmentArtifact>{DevelopmentArtifact.universal}),
|
2019-12-09 23:13:02 +00:00
|
|
|
// as part of gathering `requiredArtifacts`
|
|
|
|
mockDeviceManager.getDevices(),
|
|
|
|
// in validateCommand()
|
2019-11-26 17:02:34 +00:00
|
|
|
mockDeviceManager.findTargetDevices(any),
|
|
|
|
]);
|
|
|
|
}, overrides: <Type, Generator>{
|
|
|
|
ApplicationPackageFactory: () => mockApplicationPackageFactory,
|
|
|
|
Cache: () => mockCache,
|
|
|
|
DeviceManager: () => mockDeviceManager,
|
|
|
|
FileSystem: () => fs,
|
|
|
|
ProcessManager: () => mockProcessManager,
|
|
|
|
});
|
2019-12-09 23:13:02 +00:00
|
|
|
|
|
|
|
testUsingContext('passes device target platform to usage', () async {
|
|
|
|
final RunCommand command = RunCommand();
|
|
|
|
applyMocksToCommand(command);
|
|
|
|
final MockDevice mockDevice = MockDevice(TargetPlatform.ios);
|
2020-06-08 18:20:15 +00:00
|
|
|
when(mockDevice.supportsRuntimeMode(any)).thenAnswer((Invocation invocation) => true);
|
2019-12-09 23:13:02 +00:00
|
|
|
when(mockDevice.isLocalEmulator).thenAnswer((Invocation invocation) => Future<bool>.value(false));
|
2020-03-19 00:43:25 +00:00
|
|
|
when(mockDevice.getLogReader(app: anyNamed('app'))).thenReturn(FakeDeviceLogReader());
|
2019-12-10 18:26:14 +00:00
|
|
|
when(mockDevice.supportsFastStart).thenReturn(true);
|
2019-12-17 22:09:34 +00:00
|
|
|
when(mockDevice.sdkNameAndVersion).thenAnswer((Invocation invocation) => Future<String>.value('iOS 13'));
|
2019-12-09 23:13:02 +00:00
|
|
|
// 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'),
|
2020-06-08 18:28:02 +00:00
|
|
|
userIdentifier: anyNamed('userIdentifier'),
|
2019-12-09 23:13:02 +00:00
|
|
|
)).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(
|
2020-02-20 01:40:24 +00:00
|
|
|
(Invocation invocation) => Future<List<Device>>.value(<Device>[mockDevice])
|
2019-12-09 23:13:02 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
when(mockDeviceManager.findTargetDevices(any)).thenAnswer(
|
|
|
|
(Invocation invocation) => Future<List<Device>>.value(<Device>[mockDevice])
|
|
|
|
);
|
|
|
|
|
2020-01-06 19:04:20 +00:00
|
|
|
final Directory tempDir = globals.fs.systemTempDirectory.createTempSync('flutter_run_test.');
|
2019-12-17 22:09:34 +00:00
|
|
|
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');
|
2020-01-06 19:04:20 +00:00
|
|
|
globals.fs.currentDirectory = tempDir;
|
2019-12-17 22:09:34 +00:00
|
|
|
|
2019-12-09 23:13:02 +00:00
|
|
|
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);
|
2020-03-06 18:22:12 +00:00
|
|
|
} on Exception catch (e) {
|
|
|
|
fail('ToolExit expected, got $e');
|
2019-12-09 23:13:02 +00:00
|
|
|
}
|
|
|
|
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>;
|
2019-12-17 22:09:34 +00:00
|
|
|
|
|
|
|
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);
|
2019-12-09 23:13:02 +00:00
|
|
|
}, overrides: <Type, Generator>{
|
|
|
|
ApplicationPackageFactory: () => mockApplicationPackageFactory,
|
|
|
|
Artifacts: () => mockArtifacts,
|
|
|
|
Cache: () => mockCache,
|
|
|
|
DeviceManager: () => mockDeviceManager,
|
|
|
|
FileSystem: () => fs,
|
|
|
|
ProcessManager: () => mockProcessManager,
|
|
|
|
Usage: () => mockUsage,
|
|
|
|
});
|
2019-11-26 17:02:34 +00:00
|
|
|
});
|
|
|
|
|
2019-06-11 18:37:47 +00:00
|
|
|
group('dart-flags option', () {
|
|
|
|
RunCommand command;
|
|
|
|
List<String> args;
|
2020-06-24 18:26:36 +00:00
|
|
|
MockDeviceManager mockDeviceManager;
|
|
|
|
|
2019-06-11 18:37:47 +00:00
|
|
|
setUp(() {
|
|
|
|
command = TestRunCommand();
|
|
|
|
args = <String> [
|
|
|
|
'run',
|
|
|
|
'--dart-flags', '"--observe"',
|
|
|
|
'--no-hot',
|
2019-10-08 21:53:28 +00:00
|
|
|
'--no-pub',
|
2019-06-11 18:37:47 +00:00
|
|
|
];
|
2020-06-24 18:26:36 +00:00
|
|
|
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])
|
|
|
|
);
|
2019-06-11 18:37:47 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
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,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-04-08 20:49:09 +00:00
|
|
|
testUsingContext('should only request artifacts corresponding to connected devices', () async {
|
|
|
|
when(mockDeviceManager.getDevices()).thenAnswer((Invocation invocation) {
|
2020-02-20 01:40:24 +00:00
|
|
|
return Future<List<Device>>.value(<Device>[
|
2019-04-08 20:49:09 +00:00
|
|
|
MockDevice(TargetPlatform.android_arm),
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(await RunCommand().requiredArtifacts, unorderedEquals(<DevelopmentArtifact>{
|
|
|
|
DevelopmentArtifact.universal,
|
2019-09-17 15:19:33 +00:00
|
|
|
DevelopmentArtifact.androidGenSnapshot,
|
2019-04-08 20:49:09 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
when(mockDeviceManager.getDevices()).thenAnswer((Invocation invocation) {
|
2020-02-20 01:40:24 +00:00
|
|
|
return Future<List<Device>>.value(<Device>[
|
2019-04-08 20:49:09 +00:00
|
|
|
MockDevice(TargetPlatform.ios),
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(await RunCommand().requiredArtifacts, unorderedEquals(<DevelopmentArtifact>{
|
|
|
|
DevelopmentArtifact.universal,
|
|
|
|
DevelopmentArtifact.iOS,
|
|
|
|
}));
|
|
|
|
|
|
|
|
when(mockDeviceManager.getDevices()).thenAnswer((Invocation invocation) {
|
2020-02-20 01:40:24 +00:00
|
|
|
return Future<List<Device>>.value(<Device>[
|
2019-04-08 20:49:09 +00:00
|
|
|
MockDevice(TargetPlatform.ios),
|
|
|
|
MockDevice(TargetPlatform.android_arm),
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(await RunCommand().requiredArtifacts, unorderedEquals(<DevelopmentArtifact>{
|
|
|
|
DevelopmentArtifact.universal,
|
|
|
|
DevelopmentArtifact.iOS,
|
2019-09-17 15:19:33 +00:00
|
|
|
DevelopmentArtifact.androidGenSnapshot,
|
2019-04-08 20:49:09 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
when(mockDeviceManager.getDevices()).thenAnswer((Invocation invocation) {
|
2020-02-20 01:40:24 +00:00
|
|
|
return Future<List<Device>>.value(<Device>[
|
2019-06-04 06:19:42 +00:00
|
|
|
MockDevice(TargetPlatform.web_javascript),
|
2019-04-08 20:49:09 +00:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(await RunCommand().requiredArtifacts, unorderedEquals(<DevelopmentArtifact>{
|
|
|
|
DevelopmentArtifact.universal,
|
|
|
|
DevelopmentArtifact.web,
|
|
|
|
}));
|
|
|
|
}, overrides: <Type, Generator>{
|
|
|
|
DeviceManager: () => mockDeviceManager,
|
|
|
|
});
|
2016-03-04 22:36:32 +00:00
|
|
|
});
|
|
|
|
}
|
2019-04-08 20:49:09 +00:00
|
|
|
|
2019-12-09 23:13:02 +00:00
|
|
|
class MockArtifacts extends Mock implements Artifacts {}
|
2019-11-26 17:02:34 +00:00
|
|
|
class MockCache extends Mock implements Cache {}
|
2019-12-09 23:13:02 +00:00
|
|
|
class MockUsage extends Mock implements Usage {}
|
2019-11-26 17:02:34 +00:00
|
|
|
|
2019-04-08 20:49:09 +00:00
|
|
|
class MockDeviceManager extends Mock implements DeviceManager {}
|
|
|
|
class MockDevice extends Mock implements Device {
|
|
|
|
MockDevice(this._targetPlatform);
|
|
|
|
|
|
|
|
final TargetPlatform _targetPlatform;
|
|
|
|
|
|
|
|
@override
|
2019-12-09 23:13:02 +00:00
|
|
|
Future<TargetPlatform> get targetPlatform async => Future<TargetPlatform>.value(_targetPlatform);
|
2019-04-29 23:02:42 +00:00
|
|
|
}
|
2019-06-11 18:37:47 +00:00
|
|
|
|
|
|
|
class TestRunCommand extends RunCommand {
|
|
|
|
@override
|
|
|
|
// ignore: must_call_super
|
|
|
|
Future<void> validateCommand() async {
|
2020-07-17 16:41:03 +00:00
|
|
|
devices = await globals.deviceManager.getDevices();
|
2019-06-11 18:37:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class FakeDevice extends Fake implements Device {
|
2020-03-11 16:41:52 +00:00
|
|
|
FakeDevice({bool isLocalEmulator = false})
|
|
|
|
: _isLocalEmulator = isLocalEmulator;
|
|
|
|
|
2019-06-11 18:37:47 +00:00
|
|
|
static const int kSuccess = 1;
|
|
|
|
static const int kFailure = -1;
|
2020-06-24 18:26:36 +00:00
|
|
|
final TargetPlatform _targetPlatform = TargetPlatform.ios;
|
2020-03-11 16:41:52 +00:00
|
|
|
final bool _isLocalEmulator;
|
2019-06-11 18:37:47 +00:00
|
|
|
|
2019-11-22 16:57:14 +00:00
|
|
|
@override
|
|
|
|
String get id => 'fake_device';
|
|
|
|
|
2019-06-11 18:37:47 +00:00
|
|
|
void _throwToolExit(int code) => throwToolExit(null, exitCode: code);
|
|
|
|
|
|
|
|
@override
|
2020-03-11 16:41:52 +00:00
|
|
|
Future<bool> get isLocalEmulator => Future<bool>.value(_isLocalEmulator);
|
2019-06-11 18:37:47 +00:00
|
|
|
|
2020-06-08 18:20:15 +00:00
|
|
|
@override
|
|
|
|
bool supportsRuntimeMode(BuildMode mode) => true;
|
|
|
|
|
2019-06-11 18:37:47 +00:00
|
|
|
@override
|
|
|
|
bool get supportsHotReload => false;
|
|
|
|
|
2019-12-10 18:26:14 +00:00
|
|
|
@override
|
|
|
|
bool get supportsFastStart => false;
|
|
|
|
|
2019-06-11 18:37:47 +00:00
|
|
|
@override
|
|
|
|
Future<String> get sdkNameAndVersion => Future<String>.value('');
|
|
|
|
|
|
|
|
@override
|
2020-03-25 23:45:49 +00:00
|
|
|
DeviceLogReader getLogReader({
|
|
|
|
ApplicationPackage app,
|
|
|
|
bool includePastLogs = false,
|
|
|
|
}) {
|
2020-03-19 00:43:25 +00:00
|
|
|
return FakeDeviceLogReader();
|
2019-06-11 18:37:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
String get name => 'FakeDevice';
|
|
|
|
|
|
|
|
@override
|
|
|
|
Future<TargetPlatform> get targetPlatform async => _targetPlatform;
|
|
|
|
|
2019-10-30 21:11:18 +00:00
|
|
|
@override
|
|
|
|
final PlatformType platformType = PlatformType.ios;
|
|
|
|
|
2019-06-11 18:37:47 +00:00
|
|
|
@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,
|
2020-06-08 18:28:02 +00:00
|
|
|
String userIdentifier,
|
2019-06-11 18:37:47 +00:00
|
|
|
}) 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;
|
|
|
|
}
|
|
|
|
}
|