|
2 | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | 3 | // found in the LICENSE file. |
4 | 4 |
|
5 | | -import 'dart:async'; |
6 | | -import 'dart:convert'; |
7 | | -import 'dart:io'; |
8 | | - |
9 | | -import 'package:flutter_devicelab/framework/devices.dart'; |
10 | 5 | import 'package:flutter_devicelab/framework/framework.dart'; |
11 | | -import 'package:flutter_devicelab/framework/task_result.dart'; |
12 | | -import 'package:flutter_devicelab/framework/utils.dart'; |
13 | | -import 'package:path/path.dart' as path; |
| 6 | +import 'package:flutter_devicelab/tasks/run_tests.dart'; |
14 | 7 |
|
15 | 8 | void main() { |
16 | | - task(() async { |
17 | | - final Device device = await devices.workingDevice; |
18 | | - await device.unlock(); |
19 | | - final Directory appDir = dir(path.join(flutterDirectory.path, 'dev/integration_tests/ui')); |
20 | | - await inDirectory(appDir, () async { |
21 | | - final Completer<void> ready = Completer<void>(); |
22 | | - final List<String> stdout = <String>[]; |
23 | | - final List<String> stderr = <String>[]; |
24 | | - |
25 | | - // Uninstall if the app is already installed on the device to get to a clean state. |
26 | | - print('uninstalling...'); |
27 | | - final Process uninstall = await startProcess( |
28 | | - path.join(flutterDirectory.path, 'bin', 'flutter'), |
29 | | - <String>['--suppress-analytics', 'install', '--uninstall-only', '-d', device.deviceId], |
30 | | - )..stdout |
31 | | - .transform<String>(utf8.decoder) |
32 | | - .transform<String>(const LineSplitter()) |
33 | | - .listen((String line) { |
34 | | - print('uninstall:stdout: $line'); |
35 | | - })..stderr |
36 | | - .transform<String>(utf8.decoder) |
37 | | - .transform<String>(const LineSplitter()) |
38 | | - .listen((String line) { |
39 | | - print('uninstall:stderr: $line'); |
40 | | - stderr.add(line); |
41 | | - }); |
42 | | - if (await uninstall.exitCode != 0) { |
43 | | - throw 'flutter install --uninstall-only failed.'; |
44 | | - } |
45 | | - |
46 | | - print('run: starting...'); |
47 | | - final Process run = await startProcess( |
48 | | - path.join(flutterDirectory.path, 'bin', 'flutter'), |
49 | | - <String>['--suppress-analytics', 'run', '--release', '-d', device.deviceId, 'lib/main.dart'], |
50 | | - isBot: false, // we just want to test the output, not have any debugging info |
51 | | - ); |
52 | | - int? runExitCode; |
53 | | - run.stdout |
54 | | - .transform<String>(utf8.decoder) |
55 | | - .transform<String>(const LineSplitter()) |
56 | | - .listen((String line) { |
57 | | - print('run:stdout: $line'); |
58 | | - if ( |
59 | | - !line.startsWith('Building flutter tool...') && |
60 | | - !line.startsWith('Running "flutter pub get" in ui...') && |
61 | | - !line.startsWith('Initializing gradle...') && |
62 | | - !line.contains('settings_aar.gradle') && |
63 | | - !line.startsWith('Resolving dependencies...') && |
64 | | - // Catch engine piped output from unrelated concurrent Flutter apps |
65 | | - !line.contains(RegExp(r'[A-Z]\/flutter \([0-9]+\):')) && |
66 | | - // Empty lines could be due to the progress spinner breaking up. |
67 | | - line.length > 1 |
68 | | - ) { |
69 | | - stdout.add(line); |
70 | | - } |
71 | | - if (line.contains('Quit (terminate the application on the device).')) { |
72 | | - ready.complete(); |
73 | | - } |
74 | | - }); |
75 | | - run.stderr |
76 | | - .transform<String>(utf8.decoder) |
77 | | - .transform<String>(const LineSplitter()) |
78 | | - // TODO(egarciad): Remove once https://github.com/flutter/flutter/issues/95131 is fixed. |
79 | | - .skipWhile((String line) => line.contains('Mapping new ns')) |
80 | | - .listen((String line) { |
81 | | - print('run:stderr: $line'); |
82 | | - stderr.add(line); |
83 | | - }); |
84 | | - unawaited(run.exitCode.then<void>((int exitCode) { runExitCode = exitCode; })); |
85 | | - await Future.any<dynamic>(<Future<dynamic>>[ ready.future, run.exitCode ]); |
86 | | - if (runExitCode != null) { |
87 | | - throw 'Failed to run test app; runner unexpected exited, with exit code $runExitCode.'; |
88 | | - } |
89 | | - run.stdin.write('q'); |
90 | | - |
91 | | - await run.exitCode; |
92 | | - |
93 | | - if (stderr.isNotEmpty) { |
94 | | - throw 'flutter run --release had output on standard error.'; |
95 | | - } |
96 | | - |
97 | | - _findNextMatcherInList( |
98 | | - stdout, |
99 | | - (String line) => line.startsWith('Launching lib/main.dart on ') && line.endsWith(' in release mode...'), |
100 | | - 'Launching lib/main.dart on', |
101 | | - ); |
102 | | - |
103 | | - _findNextMatcherInList( |
104 | | - stdout, |
105 | | - (String line) => line.startsWith("Running Gradle task 'assembleRelease'..."), |
106 | | - "Running Gradle task 'assembleRelease'...", |
107 | | - ); |
108 | | - |
109 | | - _findNextMatcherInList( |
110 | | - stdout, |
111 | | - (String line) => line.contains('Built build/app/outputs/flutter-apk/app-release.apk (') && line.contains('MB).'), |
112 | | - 'Built build/app/outputs/flutter-apk/app-release.apk', |
113 | | - ); |
114 | | - |
115 | | - _findNextMatcherInList( |
116 | | - stdout, |
117 | | - (String line) => line.startsWith('Installing build/app/outputs/flutter-apk/app-release.apk...'), |
118 | | - 'Installing build/app/outputs/flutter-apk/app-release.apk...', |
119 | | - ); |
120 | | - |
121 | | - _findNextMatcherInList( |
122 | | - stdout, |
123 | | - (String line) => line.contains('Quit (terminate the application on the device).'), |
124 | | - 'q Quit (terminate the application on the device)', |
125 | | - ); |
126 | | - |
127 | | - _findNextMatcherInList( |
128 | | - stdout, |
129 | | - (String line) => line == 'Application finished.', |
130 | | - 'Application finished.', |
131 | | - ); |
132 | | - }); |
133 | | - return TaskResult.success(null); |
134 | | - }); |
135 | | -} |
136 | | - |
137 | | -void _findNextMatcherInList( |
138 | | - List<String> list, |
139 | | - bool Function(String testLine) matcher, |
140 | | - String errorMessageExpectedLine |
141 | | -) { |
142 | | - final List<String> copyOfListForErrorMessage = List<String>.from(list); |
143 | | - |
144 | | - while (list.isNotEmpty) { |
145 | | - final String nextLine = list.first; |
146 | | - list.removeAt(0); |
147 | | - |
148 | | - if (matcher(nextLine)) { |
149 | | - return; |
150 | | - } |
151 | | - } |
152 | | - |
153 | | - throw ''' |
154 | | -Did not find expected line |
155 | | -
|
156 | | -$errorMessageExpectedLine |
157 | | -
|
158 | | -in flutter run --release stdout |
159 | | -
|
160 | | -$copyOfListForErrorMessage |
161 | | - '''; |
| 9 | + task(createAndroidRunReleaseTest()); |
162 | 10 | } |
0 commit comments