modernize flutter drive w.r.t. debug/profile/release options (#4217)

* modernize `flutter drive` w.r.t. debug/profil/release options

* make error message prettier
This commit is contained in:
Yegor 2016-05-27 10:02:36 -07:00
parent 6f3382aa57
commit f544abd016
2 changed files with 28 additions and 13 deletions

View file

@ -100,7 +100,19 @@ class DriveCommand extends RunCommandBase {
if (!argResults['use-existing-app']) {
printStatus('Starting application: ${argResults["target"]}');
int result = await appStarter(this, getBuildMode());
if (getBuildMode() == BuildMode.release) {
// This is because we need VM service to be able to drive the app.
printError(
'Flutter Driver does not support running in release mode.\n'
'\n'
'Use --profile mode for testing application performance.\n'
'Use --debug (default) mode for testing correctness (with assertions).'
);
return 1;
}
int result = await appStarter(this);
if (result != 0) {
printError('Application failed to start. Will not run test. Quitting.');
return result;
@ -229,14 +241,14 @@ Future<Device> findTargetDevice() async {
}
/// Starts the application on the device given command configuration.
typedef Future<int> AppStarter(DriveCommand command, BuildMode buildMode);
typedef Future<int> AppStarter(DriveCommand command);
AppStarter appStarter = startApp;
void restoreAppStarter() {
appStarter = startApp;
}
Future<int> startApp(DriveCommand command, BuildMode buildMode) async {
Future<int> startApp(DriveCommand command) async {
String mainPath = findMainDartFile(command.target);
if (await fs.type(mainPath) != FileSystemEntityType.FILE) {
printError('Tried to run $mainPath, but that file does not exist.');
@ -248,7 +260,8 @@ Future<int> startApp(DriveCommand command, BuildMode buildMode) async {
printTrace('Building an APK.');
int result = await build_apk.buildApk(
command.device.platform,
target: command.target
target: command.target,
buildMode: command.getBuildMode()
);
if (result != 0)
@ -263,20 +276,22 @@ Future<int> startApp(DriveCommand command, BuildMode buildMode) async {
.getPackageForPlatform(command.device.platform);
command.device.installApp(package);
Map<String, dynamic> platformArgs = <String, dynamic>{};
if (command.traceStartup)
platformArgs['trace-startup'] = command.traceStartup;
printTrace('Starting application.');
LaunchResult result = await command.device.startApp(
package,
buildMode,
command.getBuildMode(),
mainPath: mainPath,
route: command.route,
debuggingOptions: new DebuggingOptions.enabled(
buildMode,
command.getBuildMode(),
startPaused: true,
observatoryPort: command.debugPort
),
platformArgs: <String, dynamic>{
'trace-startup': command.traceStartup,
}
platformArgs: platformArgs
);
return result.started ? 0 : 2;

View file

@ -38,7 +38,7 @@ void main() {
targetDeviceFinder = () {
throw 'Unexpected call to targetDeviceFinder';
};
appStarter = (_, __) {
appStarter = (_) {
throw 'Unexpected call to appStarter';
};
testRunner = (_) {
@ -75,7 +75,7 @@ void main() {
testUsingContext('returns 1 when app fails to run', () async {
withMockDevice();
appStarter = expectAsync((_, __) async => 1);
appStarter = expectAsync((_) async => 1);
String testApp = '/some/app/test_driver/e2e.dart';
String testFile = '/some/app/test_driver/e2e_test.dart';
@ -140,7 +140,7 @@ void main() {
String testApp = '/some/app/test/e2e.dart';
String testFile = '/some/app/test_driver/e2e_test.dart';
appStarter = expectAsync((_, __) {
appStarter = expectAsync((_) {
return new Future<int>.value(0);
});
testRunner = expectAsync((List<String> testArgs) {
@ -172,7 +172,7 @@ void main() {
String testApp = '/some/app/test/e2e.dart';
String testFile = '/some/app/test_driver/e2e_test.dart';
appStarter = expectAsync((_, __) {
appStarter = expectAsync((_) {
return new Future<int>.value(0);
});
testRunner = expectAsync((_) {