run_without_leak.dart 1.88 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
// 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 '../framework/adb.dart';
import '../framework/framework.dart';
import '../framework/utils.dart';

TaskFunction createRunWithoutLeakTest(dynamic dir) {
  return () async {
    final Device device = await devices.workingDevice;
    await device.unlock();
    final List<String> options = <String>[
      '-d', device.deviceId, '--verbose',
    ];
    int exitCode;
    await inDirectory<void>(dir, () async {
      final Process process = await startProcess(
          path.join(flutterDirectory.path, 'bin', 'flutter'),
26
          flutterCommandArgs('run', options),
27 28 29 30 31 32 33 34
          environment: null,
      );
      final Completer<void> stdoutDone = Completer<void>();
      final Completer<void> stderrDone = Completer<void>();
      process.stdout
          .transform<String>(utf8.decoder)
          .transform<String>(const LineSplitter())
          .listen((String line) {
35
        if (line.contains('] For a more detailed help message, press "h". To detach, press "d"; to quit, press "q"')) {
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
          process.stdin.writeln('q');
        }
        print('stdout: $line');
      }, onDone: () {
        stdoutDone.complete();
      });
      process.stderr
          .transform<String>(utf8.decoder)
          .transform<String>(const LineSplitter())
          .listen((String line) {
        print('stderr: $line');
      }, onDone: () {
        stderrDone.complete();
      });

      await Future.wait<void>(
          <Future<void>>[stdoutDone.future, stderrDone.future]);
      exitCode = await process.exitCode;
    });

    return exitCode == 0
        ? TaskResultCheckProcesses()
        : TaskResult.failure('Failed to run $dir');
  };
}