• Chris Bracken's avatar
    [tool] Consistent FakeProcessManager.run/runSync (#103947) · 928bb122
    Chris Bracken authored
    `FakeProcessManager` is a test-oriented implementation of `ProcessManager`
    that simulates launching processes and returning `ProcessResult` objects
    whose `exitCode`, `stdout`, `stderr` can be used to write platform-portable,
    hermetic tests that don't rely on actually launching processes from
    executables on disk. Its `run` and `runSync` methods provide asynchronous and
    synchronous variants of this functionality.
    
    Previously, the behaviour of `run` and `runSync` were inconsistent with
    regards to the treatment of the `stdoutEncoding` (similarly,
    `stderrEncoding`) parameters:
    
    `run`:
    * if the encoding was null, `ProcessResult.stdout` was returned as a
      String in UTF-8 encoding. This was incorrect. The behaviour as
      specified in `ProcessResult.stdout` is that in this case, a raw
      `List<int>` should be returned.
    * If the encoding was unspecified, `ProcessResult.stdout` was returned as
      a `String` in the `io.systemEncoding` encoding. This was correct.
    * If the encoding was non-null, `ProcessResult.stdout` was returned as a
      `String` in the specified encoding. This was correct.
    
    `runSync`:
    * if the encoding was null, `ProcessResult.stdout` was returned as a
      `List<int>` in UTF-8 encoding. This was incorrect. The behaviour as
      specified in `ProcessResult.stdout` is that in this case, a raw
      `List<int>` should be returned.
    * If the encoding was unspecified, `ProcessResult.stdout` was returned as
      `List<int>` in UTF-8 encoding. This was incorrect. The behaviour as
      specified in `ProcessResult.stdout` is that in this case, a String a
      `String` in the `io.systemEncoding` encoding should be returned.
    * if the encoding was non-null, `ProcessResult.stdout` was returned as a
      `String` in unknown (but probably UTF-8) encoding. This was incorrect.
      The behaviour as specified in `ProcessResult.stdout` is that in this
      case, a `String` in the specified encoding should be returned.
    
    `_FakeProcess`, from which we obtain the fake stdout and stderr values now
    holds these fields as raw `List<int>` of bytes rather than as `String`s. It
    is up to the user to supply values that can be decoded with the encoding
    passed to `run`/`runAsync`.
    
    `run` and `runAsync` have been updated to set stdout (likewise, stderr) as
    specified in the `ProcessResult` documentation.
    
    This is pre-factoring for #102451, in which the tool throws an exception
    when processing the JSON output from stdout of the `vswhere.exe` tool,
    whose output was found to include the `U+FFFD` Unicode replacement
    character during UTF-8 decoding, which triggers a `toolExit` exception
    when decoded using our [Utf8Decoder][decoder] configured with `reportErrors` =
    true. Because `FakeProcessManager.runAsync` did not previously invoke
    `utf8.decode` on its output (behaviour which differs from the non-fake
    implementation), it was impossible to write tests to verify the fix.
    
    Ref: https://api.flutter.dev/flutter/dart-io/ProcessResult/stdout.html
    
    Issue: https://github.com/flutter/flutter/issues/102451
    
    [decoder]: https://github.com/flutter/flutter/blob/fd312f1ccff909fde28d2247a489bf210bbc6c48/packages/flutter_tools/lib/src/convert.dart#L51-L60
    928bb122
Name
Last commit
Last update
..
android Loading commit data...
base Loading commit data...
build_system Loading commit data...
commands Loading commit data...
custom_devices Loading commit data...
dap Loading commit data...
dart Loading commit data...
drive Loading commit data...
fuchsia Loading commit data...
intellij Loading commit data...
ios Loading commit data...
linux Loading commit data...
macos Loading commit data...
migrate Loading commit data...
migrations Loading commit data...
proxied_devices Loading commit data...
reporting Loading commit data...
runner Loading commit data...
test Loading commit data...
tester Loading commit data...
vscode Loading commit data...
web Loading commit data...
windows Loading commit data...
analytics_test.dart Loading commit data...
android_plugin_test.dart Loading commit data...
application_package_test.dart Loading commit data...
args_test.dart Loading commit data...
artifact_updater_test.dart Loading commit data...
artifacts_test.dart Loading commit data...
asset_bundle_package_fonts_test.dart Loading commit data...
asset_bundle_package_test.dart Loading commit data...
asset_bundle_test.dart Loading commit data...
asset_bundle_variant_test.dart Loading commit data...
asset_test.dart Loading commit data...
base_utils_test.dart Loading commit data...
build_info_test.dart Loading commit data...
bundle_builder_test.dart Loading commit data...
cache_test.dart Loading commit data...
channel_test.dart Loading commit data...
cold_test.dart Loading commit data...
common_test.dart Loading commit data...
compile_batch_test.dart Loading commit data...
compile_expression_test.dart Loading commit data...
compile_incremental_test.dart Loading commit data...
compile_test.dart Loading commit data...
config_test.dart Loading commit data...
convert_test.dart Loading commit data...
coverage_collector_test.dart Loading commit data...
crash_reporting_test.dart Loading commit data...
create_config_test.dart Loading commit data...
daemon_test.dart Loading commit data...
dart_plugin_test.dart Loading commit data...
desktop_device_test.dart Loading commit data...
devfs_test.dart Loading commit data...
device_port_forwarder_test.dart Loading commit data...
device_test.dart Loading commit data...
devtools_launcher_test.dart Loading commit data...
emulator_test.dart Loading commit data...
features_test.dart Loading commit data...
flutter_manifest_test.dart Loading commit data...
flutter_platform_test.dart Loading commit data...
flutter_project_metadata_test.dart Loading commit data...
flutter_tester_device_test.dart Loading commit data...
flutter_validator_test.dart Loading commit data...
generate_localizations_test.dart Loading commit data...
github_template_test.dart Loading commit data...
hot_test.dart Loading commit data...
integration_test_device_test.dart Loading commit data...
license_collector_test.dart Loading commit data...
mdns_discovery_test.dart Loading commit data...
persistent_tool_state_test.dart Loading commit data...
plugin_parsing_test.dart Loading commit data...
plugins_test.dart Loading commit data...
preview_device_test.dart Loading commit data...
project_file_invalidator_test.dart Loading commit data...
project_test.dart Loading commit data...
project_validator_result_test.dart Loading commit data...
protocol_discovery_test.dart Loading commit data...
resident_devtools_handler_test.dart Loading commit data...
resident_runner_test.dart Loading commit data...
resident_web_runner_cold_test.dart Loading commit data...
resident_web_runner_test.dart Loading commit data...
template_test.dart Loading commit data...
terminal_handler_test.dart Loading commit data...
testbed_test.dart Loading commit data...
time_test.dart Loading commit data...
tracing_test.dart Loading commit data...
update_packages_test.dart Loading commit data...
utils_test.dart Loading commit data...
version_test.dart Loading commit data...
vmservice_test.dart Loading commit data...
xcode_backend_test.dart Loading commit data...