"Fossies" - the Fresh Open Source Software Archive

Member "flutter-1.22.4/dev/devicelab/bin/tasks/run_release_test.dart" (13 Nov 2020, 5406 Bytes) of package /linux/misc/flutter-1.22.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Dart source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 // Copyright 2014 The Flutter Authors. All rights reserved.
    2 // Use of this source code is governed by a BSD-style license that can be
    3 // found in the LICENSE file.
    4 
    5 import 'dart:async';
    6 import 'dart:convert';
    7 import 'dart:io';
    8 
    9 import 'package:path/path.dart' as path;
   10 
   11 import 'package:flutter_devicelab/framework/adb.dart';
   12 import 'package:flutter_devicelab/framework/framework.dart';
   13 import 'package:flutter_devicelab/framework/utils.dart';
   14 
   15 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         .listen((String line) {
   79           print('run:stderr: $line');
   80           stderr.add(line);
   81         });
   82       run.exitCode.then<void>((int exitCode) { runExitCode = exitCode; });
   83       await Future.any<dynamic>(<Future<dynamic>>[ ready.future, run.exitCode ]);
   84       if (runExitCode != null) {
   85         throw 'Failed to run test app; runner unexpected exited, with exit code $runExitCode.';
   86       }
   87       run.stdin.write('q');
   88 
   89       await run.exitCode;
   90 
   91       if (stderr.isNotEmpty) {
   92         throw 'flutter run --release had output on standard error.';
   93       }
   94 
   95       _findNextMatcherInList(
   96         stdout,
   97         (String line) => line.startsWith('Launching lib/main.dart on ') && line.endsWith(' in release mode...'),
   98         'Launching lib/main.dart on',
   99       );
  100 
  101       _findNextMatcherInList(
  102         stdout,
  103         (String line) => line.startsWith("Running Gradle task 'assembleRelease'..."),
  104         "Running Gradle task 'assembleRelease'...",
  105       );
  106 
  107       _findNextMatcherInList(
  108         stdout,
  109         (String line) => line.contains('Built build/app/outputs/flutter-apk/app-release.apk (') && line.contains('MB).'),
  110         'Built build/app/outputs/flutter-apk/app-release.apk',
  111       );
  112 
  113       _findNextMatcherInList(
  114         stdout,
  115         (String line) => line.startsWith('Installing build/app/outputs/flutter-apk/app.apk...'),
  116         'Installing build/app/outputs/flutter-apk/app.apk...',
  117       );
  118 
  119       _findNextMatcherInList(
  120         stdout,
  121         (String line) => line.contains('Quit (terminate the application on the device).'),
  122         'q Quit (terminate the application on the device)',
  123       );
  124 
  125       _findNextMatcherInList(
  126         stdout,
  127         (String line) => line == 'Application finished.',
  128         'Application finished.',
  129       );
  130     });
  131     return TaskResult.success(null);
  132   });
  133 }
  134 
  135 void _findNextMatcherInList(
  136   List<String> list,
  137   bool Function(String testLine) matcher,
  138   String errorMessageExpectedLine
  139 ) {
  140   final List<String> copyOfListForErrorMessage = List<String>.from(list);
  141 
  142   while (list.isNotEmpty) {
  143     final String nextLine = list.first;
  144     list.removeAt(0);
  145 
  146     if (matcher(nextLine)) {
  147       return;
  148     }
  149   }
  150 
  151   throw '''
  152 Did not find expected line
  153 
  154 $errorMessageExpectedLine
  155 
  156 in flutter run --release stdout
  157 
  158 $copyOfListForErrorMessage
  159   ''';
  160 }