run_release_test.dart 3.51 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
// Copyright (c) 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:path/path.dart' as path;

import 'package:flutter_devicelab/framework/adb.dart';
import 'package:flutter_devicelab/framework/framework.dart';
import 'package:flutter_devicelab/framework/utils.dart';

void main() {
  task(() async {
    final Device device = await devices.workingDevice;
    await device.unlock();
    final Directory appDir = dir(path.join(flutterDirectory.path, 'dev/integration_tests/ui'));
    await inDirectory(appDir, () async {
21
      final Completer<void> ready = Completer<void>();
22 23 24 25 26 27 28 29 30 31
      print('run: starting...');
      final Process run = await startProcess(
        path.join(flutterDirectory.path, 'bin', 'flutter'),
        <String>['--suppress-analytics', 'run', '--release', '-d', device.deviceId, 'lib/main.dart'],
        isBot: false, // we just want to test the output, not have any debugging info
      );
      final List<String> stdout = <String>[];
      final List<String> stderr = <String>[];
      int runExitCode;
      run.stdout
32 33
        .transform<String>(utf8.decoder)
        .transform<String>(const LineSplitter())
34 35
        .listen((String line) {
          print('run:stdout: $line');
36 37 38 39 40 41 42 43 44 45
          if (
            !line.startsWith('Building flutter tool...') &&
            !line.startsWith('Running "flutter pub get" in ui...') &&
            !line.startsWith('Initializing gradle...') &&
            !line.contains('settings_aar.gradle') &&
            !line.startsWith('Resolving dependencies...')
          ) {
            stdout.add(line);
          }
          if (line.contains('To quit, press "q".')) {
46
            ready.complete();
47
          }
48 49
        });
      run.stderr
50 51
        .transform<String>(utf8.decoder)
        .transform<String>(const LineSplitter())
52 53
        .listen((String line) {
          print('run:stderr: $line');
54
          stderr.add(line);
55
        });
56
      run.exitCode.then<void>((int exitCode) { runExitCode = exitCode; });
57
      await Future.any<dynamic>(<Future<dynamic>>[ ready.future, run.exitCode ]);
58
      if (runExitCode != null) {
59
        throw 'Failed to run test app; runner unexpected exited, with exit code $runExitCode.';
60
      }
61
      run.stdin.write('q');
62

63
      await run.exitCode;
64 65

      if (stderr.isNotEmpty) {
66
        throw 'flutter run --release had output on standard error.';
67 68
      }
      if (!(stdout.first.startsWith('Launching lib/main.dart on ') && stdout.first.endsWith(' in release mode...'))){
69
        throw 'flutter run --release had unexpected first line: ${stdout.first}';
70
      }
71
      stdout.removeAt(0);
72
      if (!stdout.first.startsWith('Running Gradle task \'assembleRelease\'...')) {
73
        throw 'flutter run --release had unexpected second line: ${stdout.first}';
74
      }
75
      stdout.removeAt(0);
76
      if (!(stdout.first.contains('Built build/app/outputs/apk/release/app-release.apk (') && stdout.first.contains('MB).'))) {
77
        throw 'flutter run --release had unexpected third line: ${stdout.first}';
78
      }
79
      stdout.removeAt(0);
80
      if (stdout.first.startsWith('Installing build/app/outputs/apk/app.apk...')) {
81
        stdout.removeAt(0);
82
      }
83 84 85 86
      if (stdout.join('\n') != '\nTo quit, press "q".\n\nApplication finished.') {
        throw 'flutter run --release had unexpected output after third line:\n'
            '${stdout.join('\n')}';
      }
87
    });
88
    return TaskResult.success(null);
89 90
  });
}