flutter/packages/flutter_tools/test/general.shard/ios
Chris Bracken 928bb1229b
[tool] Consistent FakeProcessManager.run/runSync (#103947)
`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]: fd312f1ccf/packages/flutter_tools/lib/src/convert.dart (L51-L60)
2022-05-17 11:15:54 -07:00
..
code_signing_test.dart add missing trailing commas in list/set/map literals (#102585) 2022-04-27 09:15:35 +02:00
devices_test.dart Remove custom unawaited, prefer dart:async version (#103212) 2022-05-07 08:49:04 -07:00
ios_deploy_test.dart [flutter_tools] add --uninstall-first flag and pipe it through to ios-deploy (#102948) 2022-05-07 11:49:07 -07:00
ios_device_install_test.dart add missing trailing commas in list/set/map literals (#102585) 2022-04-27 09:15:35 +02:00
ios_device_logger_test.dart add missing trailing commas in list/set/map literals (#102585) 2022-04-27 09:15:35 +02:00
ios_device_port_forwarder_test.dart [tool] Consistent FakeProcessManager.run/runSync (#103947) 2022-05-17 11:15:54 -07:00
ios_device_project_test.dart Migrate xcdevice and ios devices to null safety (#92056) 2021-10-19 12:23:03 -07:00
ios_device_start_nonprebuilt_test.dart add missing trailing commas in list/set/map literals (#102585) 2022-04-27 09:15:35 +02:00
ios_device_start_prebuilt_test.dart add missing trailing commas in list/set/map literals (#102585) 2022-04-27 09:15:35 +02:00
ios_project_migration_test.dart Set template and migrate apps to iOS 11 minimum (#101963) 2022-04-15 11:34:08 -07:00
ios_workflow_test.dart Enable avoid_redundant_argument_values lint (#91409) (#91462) 2021-10-08 09:25:14 -07:00
mac_test.dart add missing trailing commas in list/set/map literals (#102585) 2022-04-27 09:15:35 +02:00
simulators_test.dart add missing trailing commas in list/set/map literals (#102585) 2022-04-27 09:15:35 +02:00
xcodeproj_test.dart add missing trailing commas in list/set/map literals (#102585) 2022-04-27 09:15:35 +02:00
xcresult_test_data.dart Log XCResult before other build issues (#100787) 2022-04-08 16:27:08 -07:00
xcresult_test.dart [flutter_tools] rename local functions with _s (#102688) 2022-04-27 16:19:07 -07:00