anchor.diff:      );
       logger.printStatus('message');
       logger.printError('error message');
  -    await stdoutCompleter.future;
  -    await stderrCompleter.future;
  -    expect(stdoutThrew, true);
  -    expect(stderrThrew, true);
  +
  +    await stdout.done;
  +    await stderr.done;
     });
   
     testWithoutContext('Logger does not throw when stdio completes done with an error', () async {
  -    final MockStdout stdout = MockStdout();
  -    final MockStdout stderr = MockStdout();
  +    final FakeStdout stdout = FakeStdout(syncError: false, completeWithError: true);
  +    final FakeStdout stderr = FakeStdout(syncError: false, completeWithError: true);
       final Stdio stdio = Stdio.test(stdout: stdout, stderr: stderr);
  -    final Completer<void> stdoutError = Completer<void>();
  -    final Completer<void> stderrError = Completer<void>();
  -    final Completer<void> stdoutCompleter = Completer<void>();
  -    final Completer<void> stderrCompleter = Completer<void>();
  -    when(stdout.write(any)).thenAnswer((_) {
  -      Zone.current.runUnaryGuarded<void>((_) {
  -        stdoutError.completeError(Exception('Some pipe error'));
  -        stdoutCompleter.complete();
  -      }, null);
  -    });
  -    when(stderr.write(any)).thenAnswer((_) {
  -      Zone.current.runUnaryGuarded<void>((_) {
  -        stderrError.completeError(Exception('Some pipe error'));
  -        stderrCompleter.complete();
  -      }, null);
  -    });
  -    when(stdout.done).thenAnswer((_) => stdoutError.future);
  -    when(stderr.done).thenAnswer((_) => stderrError.future);
       final Logger logger = StdoutLogger(
         terminal: AnsiTerminal(
           stdio: stdio,
  
positive.code:       stdio: stdio,
        outputPreferences: OutputPreferences.test(),
      );
      logger.printStatus('message');
      logger.printError('error message');
      expect(stdoutThrew, true);
      expect(stderrThrew, true);
    });
  
    testWithoutContext('Logger does not throw when stdio write throws asynchronously', () async {
      final MockStdout stdout = MockStdout();
      final MockStdout stderr = MockStdout();
      final Stdio stdio = Stdio.test(stdout: stdout, stderr: stderr);
      final Completer<void> stdoutError = Completer<void>();
      final Completer<void> stderrError = Completer<void>();
      bool stdoutThrew = false;
      bool stderrThrew = false;
      final Completer<void> stdoutCompleter = Completer<void>();
      final Completer<void> stderrCompleter = Completer<void>();
      when(stdout.write(any)).thenAnswer((_) {
        Zone.current.runUnaryGuarded<void>((_) {
          stdoutThrew = true;
          stdoutCompleter.complete();
          throw 'Error';
        }, null);
      });
      when(stderr.write(any)).thenAnswer((_) {
        Zone.current.runUnaryGuarded<void>((_) {
          stderrThrew = true;
          stderrCompleter.complete();
          throw 'Error';
        }, null);
      });
      when(stdout.done).thenAnswer((_) => stdoutError.future);
      when(stderr.done).thenAnswer((_) => stderrError.future);
      final Logger logger = StdoutLogger(
        terminal: AnsiTerminal(
          stdio: stdio,
  
negative.code:   });
  
    testWithoutContext('Logger does not throw when stdio write throws synchronously', () async {
      final FakeStdout stdout = FakeStdout(syncError: true);
      final FakeStdout stderr = FakeStdout(syncError: true);
      final Stdio stdio = Stdio.test(stdout: stdout, stderr: stderr);
      final Logger logger = StdoutLogger(
        terminal: AnsiTerminal(
          stdio: stdio,
  