TestProcess constructor

  1. @protected
TestProcess(
  1. Process process,
  2. String description,
  3. {Encoding encoding,
  4. bool forwardStdio: false}
)

Creates a TestProcess for process.

The description, encoding, and forwardStdio are the same as those to start.

This is protected, which means it should only be called by subclasses.

Implementation

@protected
TestProcess(Process process, this.description,
    {Encoding encoding, bool forwardStdio = false})
    : _process = process,
      _stdoutSplitter = StreamSplitter(process.stdout
          .transform(encoding.decoder)
          .transform(const LineSplitter())),
      _stderrSplitter = StreamSplitter(process.stderr
          .transform(encoding.decoder)
          .transform(const LineSplitter())) {
  addTearDown(_tearDown);
  expect(_process.exitCode.then((_) => _logOutput()), completes,
      reason: 'Process `$description` never exited.');

  _stdout = StreamQueue(stdoutStream());
  _stderr = StreamQueue(stderrStream());

  // Listen eagerly so that the lines are interleaved properly between the two
  // streams.
  //
  // Call [split] explicitly because we don't want to log overridden
  // [stdoutStream] or [stderrStream] output.
  _stdoutSplitter.split().listen((line) {
    _heartbeat();
    if (forwardStdio) print(line);
    _log.add('    $line');
  });

  _stderrSplitter.split().listen((line) {
    _heartbeat();
    if (forwardStdio) print(line);
    _log.add('[e] $line');
  });
}