diff --git a/packages/flutter_tools/lib/src/commands/drive.dart b/packages/flutter_tools/lib/src/commands/drive.dart index 83171afd09..1057c367db 100644 --- a/packages/flutter_tools/lib/src/commands/drive.dart +++ b/packages/flutter_tools/lib/src/commands/drive.dart @@ -3,6 +3,7 @@ // found in the LICENSE file. import 'dart:async'; +import 'dart:io' as io; import 'package:path/path.dart' as path; import 'package:test/src/executable.dart' as executable; // ignore: implementation_imports @@ -110,7 +111,6 @@ class DriveCommand extends RunCommandBase { try { return await testRunner([testFile]) - .then((_) => 0) .catchError((dynamic error, dynamic stackTrace) { printError('CAUGHT EXCEPTION: $error\n$stackTrace'); return 1; @@ -285,15 +285,16 @@ Future startApp(DriveCommand command) async { } /// Runs driver tests. -typedef Future TestRunner(List testArgs); +typedef Future TestRunner(List testArgs); TestRunner testRunner = runTests; void restoreTestRunner() { testRunner = runTests; } -Future runTests(List testArgs) { +Future runTests(List testArgs) async { printTrace('Running driver tests.'); - return executable.main(testArgs); + await executable.main(testArgs); + return io.exitCode; } diff --git a/packages/flutter_tools/test/drive_test.dart b/packages/flutter_tools/test/drive_test.dart index a321a00d2f..e28fde18e8 100644 --- a/packages/flutter_tools/test/drive_test.dart +++ b/packages/flutter_tools/test/drive_test.dart @@ -146,7 +146,7 @@ void main() { }); testRunner = expectAsync((List testArgs) { expect(testArgs, [testFile]); - return new Future.value(); + return new Future.value(0); }); appStopper = expectAsync((_) { return new Future.value(0); @@ -167,6 +167,37 @@ void main() { }); }); + testUsingContext('returns exitCode set by test runner', () async { + withMockDevice(); + + String testApp = '/some/app/test/e2e.dart'; + String testFile = '/some/app/test_driver/e2e_test.dart'; + + appStarter = expectAsync((_) { + return new Future.value(0); + }); + testRunner = expectAsync((_) { + return new Future.value(123); + }); + appStopper = expectAsync((_) { + return new Future.value(0); + }); + + MemoryFileSystem memFs = fs; + await memFs.file(testApp).writeAsString('main() {}'); + await memFs.file(testFile).writeAsString('main() {}'); + + List args = [ + 'drive', + '--target=$testApp', + ]; + return createTestCommandRunner(command).run(args).then((int code) { + expect(code, equals(123)); + BufferLogger buffer = logger; + expect(buffer.errorText, isEmpty); + }); + }); + group('findTargetDevice', () { testUsingContext('uses specified device', () async {