• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (c) 2019 The Chromium 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
5import 'dart:async';
6import 'dart:convert';
7import 'dart:io';
8
9import 'package:path/path.dart' as path;
10
11import 'package:flutter_devicelab/framework/adb.dart';
12import 'package:flutter_devicelab/framework/framework.dart';
13import 'package:flutter_devicelab/framework/utils.dart';
14
15Future<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
56void 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}
85