@@ -18,14 +18,49 @@ import 'utils/screenshot_transformer.dart';
1818const int tcpPort = 3001 ;
1919
2020void main (List <String > args) async {
21- const ProcessManager pm = LocalProcessManager ();
2221 final ArgParser parser = ArgParser ()
23- ..addOption ('adb' , help: 'absolute path to the adb tool' , mandatory: true )
24- ..addOption ('out-dir' , help: 'out directory' , mandatory: true );
22+ ..addOption (
23+ 'adb' ,
24+ help: 'absolute path to the adb tool' ,
25+ mandatory: true ,
26+ )
27+ ..addOption (
28+ 'out-dir' ,
29+ help: 'out directory' ,
30+ mandatory: true ,
31+ )
32+ ..addFlag (
33+ 'smoke-test' ,
34+ help: 'runs a single test to verify the setup' ,
35+ negatable: false ,
36+ defaultsTo: true ,
37+ );
2538
26- final ArgResults results = parser.parse (args);
27- final Directory outDir = Directory (results['out-dir' ] as String );
28- final File adb = File (results['adb' ] as String );
39+ runZonedGuarded (
40+ () async {
41+ final ArgResults results = parser.parse (args);
42+ final Directory outDir = Directory (results['out-dir' ] as String );
43+ final File adb = File (results['adb' ] as String );
44+ final bool smokeTest = results['smoke-test' ] as bool ;
45+ await _run (outDir: outDir, adb: adb, smokeTest: smokeTest);
46+ exit (0 );
47+ },
48+ (Object error, StackTrace stackTrace) {
49+ if (error is ! Panic ) {
50+ stderr.writeln (error);
51+ stderr.writeln (stackTrace);
52+ }
53+ exit (1 );
54+ },
55+ );
56+ }
57+
58+ Future <void > _run ({
59+ required Directory outDir,
60+ required File adb,
61+ required bool smokeTest,
62+ }) async {
63+ const ProcessManager pm = LocalProcessManager ();
2964
3065 if (! outDir.existsSync ()) {
3166 panic (< String > ['out-dir does not exist: $outDir ' , 'make sure to build the selected engine variant' ]);
@@ -170,15 +205,25 @@ void main(List<String> args) async {
170205 });
171206
172207 await step ('Running instrumented tests...' , () async {
173- final int exitCode = await pm.runAndForward (< String > [
208+ final ( int exitCode, StringBuffer out) = await pm.runAndCapture (< String > [
174209 adb.path,
175210 'shell' ,
176211 'am' ,
177212 'instrument' ,
178- '-w' , 'dev.flutter.scenarios.test/dev.flutter.TestRunner' ,
213+ '-w' ,
214+ if (smokeTest)
215+ '-e class dev.flutter.scenarios.EngineLaunchE2ETest' ,
216+ 'dev.flutter.scenarios.test/dev.flutter.TestRunner' ,
179217 ]);
180218 if (exitCode != 0 ) {
181- panic (< String > ['could not install test apk' ]);
219+ panic (< String > ['instrumented tests failed to run' ]);
220+ }
221+ // Unfortunately adb shell am instrument does not return a non-zero exit
222+ // code when tests fail, but it does seem to print "FAILURES!!!" to
223+ // stdout, so we can use that as a signal that something went wrong.
224+ if (out.toString ().contains ('FAILURES!!!' )) {
225+ stdout.write (out);
226+ panic (< String > ['1 or more tests failed' ]);
182227 }
183228 });
184229 } finally {
@@ -221,8 +266,7 @@ void main(List<String> args) async {
221266
222267 await step ('Flush logcat...' , () async {
223268 await logcat.flush ();
269+ await logcat.close ();
224270 });
225-
226- exit (0 );
227271 }
228272}
0 commit comments