TestProcess constructor

  1. @protected
TestProcess(
  1. Process process,
  2. String description, {
  3. Encoding encoding = utf8,
  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 = utf8, 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);

  _process.exitCode.whenComplete(_logOutput);

  // 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');
  });
}