diff --git a/packages/flutter_tools/test/general.shard/ios/ios_device_port_forwarder_test.dart b/packages/flutter_tools/test/general.shard/ios/ios_device_port_forwarder_test.dart index a1c2ac48e5..f8e1e0525e 100644 --- a/packages/flutter_tools/test/general.shard/ios/ios_device_port_forwarder_test.dart +++ b/packages/flutter_tools/test/general.shard/ios/ios_device_port_forwarder_test.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:flutter_tools/src/base/logger.dart'; import 'package:flutter_tools/src/ios/devices.dart'; @@ -25,8 +23,8 @@ void main() { // the FakeCommands below expect an exitCode of 0. const FakeCommand( command: ['iproxy', '12345:456', '--udid', '1234'], - stdout: null, // no stdout indicates failure. environment: kDyLdLibEntry, + // Empty stdout indicates failure. ), const FakeCommand( command: ['iproxy', '12346:456', '--udid', '1234'], diff --git a/packages/flutter_tools/test/src/fake_process_manager.dart b/packages/flutter_tools/test/src/fake_process_manager.dart index fb2bc7465c..760249ec5d 100644 --- a/packages/flutter_tools/test/src/fake_process_manager.dart +++ b/packages/flutter_tools/test/src/fake_process_manager.dart @@ -100,8 +100,8 @@ class FakeCommand { /// If provided, this exception will be thrown when the fake command is run. final Object? exception; - /// Indicates that output will only be emitted after the `exitCode` [Future] - /// on [io.Process] completes. + /// When true, stdout and stderr will only be emitted after the `exitCode` + /// [Future] on [io.Process] completes. final bool outputFollowsExit; void _matches( @@ -141,24 +141,26 @@ class _FakeProcess implements io.Process { }), stdin = stdin ?? IOSink(StreamController>().sink) { - if (_stderr == null) { + if (_stderr.isEmpty) { stderr = const Stream>.empty(); } else if (outputFollowsExit) { + // Wait for the process to exit before emitting stderr. stderr = Stream>.fromFuture(exitCode.then((_) { - return Future>(() => utf8.encode(_stderr)); + return Future>(() => _stderr); })); } else { - stderr = Stream>.value(utf8.encode(_stderr)); + stderr = Stream>.value(_stderr); } - if (_stdout == null) { + if (_stdout.isEmpty) { stdout = const Stream>.empty(); } else if (outputFollowsExit) { + // Wait for the process to exit before emitting stdout. stdout = Stream>.fromFuture(exitCode.then((_) { - return Future>(() => utf8.encode(_stdout)); + return Future>(() => _stdout); })); } else { - stdout = Stream>.value(utf8.encode(_stdout)); + stdout = Stream>.value(_stdout); } } @@ -171,7 +173,7 @@ class _FakeProcess implements io.Process { @override final int pid; - final String _stderr; + final List _stderr; @override late final Stream> stderr; @@ -182,7 +184,7 @@ class _FakeProcess implements io.Process { @override late final Stream> stdout; - final String _stdout; + final List _stdout; @override bool kill([io.ProcessSignal signal = io.ProcessSignal.sigterm]) { @@ -268,9 +270,9 @@ abstract class FakeProcessManager implements ProcessManager { fakeCommand.exitCode, fakeCommand.duration, _pid, - fakeCommand.stderr, + encoding?.encode(fakeCommand.stderr) ?? fakeCommand.stderr.codeUnits, fakeCommand.stdin, - fakeCommand.stdout, + encoding?.encode(fakeCommand.stdout) ?? fakeCommand.stdout.codeUnits, fakeCommand.completer, fakeCommand.outputFollowsExit, ); @@ -310,8 +312,8 @@ abstract class FakeProcessManager implements ProcessManager { return io.ProcessResult( process.pid, process._exitCode, - stdoutEncoding == null ? process.stdout : await stdoutEncoding.decodeStream(process.stdout), - stderrEncoding == null ? process.stderr : await stderrEncoding.decodeStream(process.stderr), + stdoutEncoding == null ? process._stdout : await stdoutEncoding.decodeStream(process.stdout), + stderrEncoding == null ? process._stderr : await stderrEncoding.decodeStream(process.stderr), ); } @@ -322,15 +324,15 @@ abstract class FakeProcessManager implements ProcessManager { Map? environment, bool includeParentEnvironment = true, // ignored bool runInShell = false, // ignored - Encoding? stdoutEncoding = io.systemEncoding, // actual encoder is ignored - Encoding? stderrEncoding = io.systemEncoding, // actual encoder is ignored + Encoding? stdoutEncoding = io.systemEncoding, + Encoding? stderrEncoding = io.systemEncoding, }) { final _FakeProcess process = _runCommand(command.cast(), workingDirectory, environment, stdoutEncoding); return io.ProcessResult( process.pid, process._exitCode, - stdoutEncoding == null ? utf8.encode(process._stdout) : process._stdout, - stderrEncoding == null ? utf8.encode(process._stderr) : process._stderr, + stdoutEncoding == null ? process._stdout : stdoutEncoding.decode(process._stdout), + stderrEncoding == null ? process._stderr : stderrEncoding.decode(process._stderr), ); }