"Fossies" - the Fresh Open Source Software Archive

Member "flutter-1.22.4/dev/devicelab/bin/tasks/build_mode_test.dart" (13 Nov 2020, 3075 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 Future<String> runFlutterAndQuit(List<String> args, Device device) async {
   16   final Completer<void> ready = Completer<void>();
   17   print('run: starting...');
   18   final Process run = await startProcess(
   19     path.join(flutterDirectory.path, 'bin', 'flutter'),
   20     <String>['run', '--suppress-analytics', ...args],
   21     isBot: false, // we just want to test the output, not have any debugging info
   22   );
   23   final List<String> stdout = <String>[];
   24   final List<String> stderr = <String>[];
   25   int runExitCode;
   26   run.stdout.transform<String>(utf8.decoder).transform<String>(const LineSplitter()).listen(
   27     (String line) {
   28       print('run:stdout: $line');
   29       stdout.add(line);
   30       if (line.contains('>>> FINISHED <<<')) {
   31         ready.complete();
   32       }
   33     },
   34   );
   35   run.stderr.transform<String>(utf8.decoder).transform<String>(const LineSplitter()).listen(
   36     (String line) {
   37       print('run:stderr: $line');
   38       stderr.add(line);
   39     },
   40   );
   41   run.exitCode.then<void>((int exitCode) {
   42     runExitCode = exitCode;
   43   });
   44   await Future.any<dynamic>(<Future<dynamic>>[ready.future, run.exitCode]);
   45   if (runExitCode != null) {
   46     throw 'Failed to run test app; runner unexpected exited, with exit code $runExitCode.';
   47   }
   48   run.stdin.write('q');
   49   await run.exitCode;
   50   if (stderr.isNotEmpty) {
   51     throw 'flutter run ${args.join(' ')} had output on standard error:\n${stderr.join('\n')}';
   52   }
   53   return stdout.join('\n');
   54 }
   55 
   56 void main() {
   57   task(() async {
   58     final Device device = await devices.workingDevice;
   59     await device.unlock();
   60     final Directory appDir = dir(path.join(flutterDirectory.path, 'dev/integration_tests/ui'));
   61     Future<void> checkMode(String mode, {bool releaseExpected = false, bool dynamic = false}) async {
   62       await inDirectory(appDir, () async {
   63         print('run: starting $mode test...');
   64         final List<String> args = <String>[
   65           '--$mode',
   66           if (dynamic) '--dynamic',
   67           '-d',
   68           device.deviceId,
   69           'lib/build_mode.dart',
   70         ];
   71         final String stdout = await runFlutterAndQuit(args, device);
   72         if (!stdout.contains('>>> Release: $releaseExpected <<<')) {
   73           throw "flutter run --$mode ${dynamic ? '--dynamic ' : ''}didn't set kReleaseMode properly";
   74         }
   75       });
   76     }
   77     await checkMode('debug', releaseExpected: false);
   78     await checkMode('profile', releaseExpected: false);
   79     await checkMode('profile', releaseExpected: false, dynamic: true);
   80     await checkMode('release', releaseExpected: true);
   81     await checkMode('release', releaseExpected: true, dynamic: true);
   82     return TaskResult.success(null);
   83   });
   84 }