From e8cd4827a09c095cac4bafeddd56b2d6cacf568a Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Thu, 8 Apr 2021 15:19:07 -0700 Subject: [PATCH] Migrate fake_process_manager to null safety (#80018) --- .../android/android_device_stop_test.dart | 2 +- .../android/android_device_test.dart | 2 +- .../android/android_emulator_test.dart | 1 - .../base/error_handling_io_test.dart | 2 +- .../test/general.shard/base/process_test.dart | 2 +- .../build_system/build_system_test.dart | 2 +- .../targets/icon_tree_shaker_test.dart | 2 +- .../targets/localizations_test.dart | 2 +- .../general.shard/compile_batch_test.dart | 2 +- .../compile_expression_test.dart | 2 +- .../compile_incremental_test.dart | 1 - .../general.shard/crash_reporting_test.dart | 2 +- .../generate_synthetic_packages_test.dart | 1 - .../general.shard/devtools_launcher_test.dart | 2 +- .../general.shard/flutter_validator_test.dart | 2 +- .../fuchsia/fuchsia_dev_finder_test.dart | 2 +- .../fuchsia/fuchsia_ffx_test.dart | 2 +- .../general.shard/ios/code_signing_test.dart | 2 +- .../test/general.shard/ios/devices_test.dart | 2 +- .../ios/ios_device_logger_test.dart | 2 +- .../general.shard/ios/ios_workflow_test.dart | 2 +- .../linux/linux_device_test.dart | 2 +- .../resident_devtools_handler_test.dart | 2 +- .../test/src/fake_process_manager.dart | 67 ++++++++++--------- 24 files changed, 54 insertions(+), 56 deletions(-) diff --git a/packages/flutter_tools/test/general.shard/android/android_device_stop_test.dart b/packages/flutter_tools/test/general.shard/android/android_device_stop_test.dart index 05b4c2bbda..928de3870a 100644 --- a/packages/flutter_tools/test/general.shard/android/android_device_stop_test.dart +++ b/packages/flutter_tools/test/general.shard/android/android_device_stop_test.dart @@ -12,7 +12,7 @@ import 'package:flutter_tools/src/base/platform.dart'; import 'package:test/fake.dart'; import '../../src/common.dart'; -import '../../src/context.dart'; +import '../../src/fake_process_manager.dart'; void main() { testWithoutContext('AndroidDevice.stopApp handles a null ApplicationPackage', () async { diff --git a/packages/flutter_tools/test/general.shard/android/android_device_test.dart b/packages/flutter_tools/test/general.shard/android/android_device_test.dart index f3960249a4..93266bc1cb 100644 --- a/packages/flutter_tools/test/general.shard/android/android_device_test.dart +++ b/packages/flutter_tools/test/general.shard/android/android_device_test.dart @@ -22,7 +22,7 @@ import 'package:flutter_tools/src/project.dart'; import 'package:test/fake.dart'; import '../../src/common.dart'; -import '../../src/context.dart'; +import '../../src/fake_process_manager.dart'; void main() { testWithoutContext('AndroidDevice stores the requested id', () { diff --git a/packages/flutter_tools/test/general.shard/android/android_emulator_test.dart b/packages/flutter_tools/test/general.shard/android/android_emulator_test.dart index a3cdf7ace7..1c4d501bb2 100644 --- a/packages/flutter_tools/test/general.shard/android/android_emulator_test.dart +++ b/packages/flutter_tools/test/general.shard/android/android_emulator_test.dart @@ -14,7 +14,6 @@ import 'package:mockito/mockito.dart'; import 'package:fake_async/fake_async.dart'; import '../../src/common.dart'; -import '../../src/context.dart'; import '../../src/fake_process_manager.dart'; import '../../src/mocks.dart' show MockAndroidSdk; diff --git a/packages/flutter_tools/test/general.shard/base/error_handling_io_test.dart b/packages/flutter_tools/test/general.shard/base/error_handling_io_test.dart index 4281522f68..03c05686c3 100644 --- a/packages/flutter_tools/test/general.shard/base/error_handling_io_test.dart +++ b/packages/flutter_tools/test/general.shard/base/error_handling_io_test.dart @@ -19,7 +19,7 @@ import 'package:path/path.dart' as path; // flutter_ignore: package_path_import import 'package:process/process.dart'; import '../../src/common.dart'; -import '../../src/context.dart'; +import '../../src/fake_process_manager.dart'; class MockFile extends Mock implements File {} class MockFileSystem extends Mock implements FileSystem {} diff --git a/packages/flutter_tools/test/general.shard/base/process_test.dart b/packages/flutter_tools/test/general.shard/base/process_test.dart index 03c97ea104..b95572c1a0 100644 --- a/packages/flutter_tools/test/general.shard/base/process_test.dart +++ b/packages/flutter_tools/test/general.shard/base/process_test.dart @@ -14,7 +14,7 @@ import 'package:flutter_tools/src/base/terminal.dart'; import 'package:mockito/mockito.dart'; import 'package:fake_async/fake_async.dart'; import '../../src/common.dart'; -import '../../src/context.dart'; +import '../../src/fake_process_manager.dart'; import '../../src/fakes.dart'; import '../../src/mocks.dart' show MockProcessManager, flakyProcessFactory; diff --git a/packages/flutter_tools/test/general.shard/build_system/build_system_test.dart b/packages/flutter_tools/test/general.shard/build_system/build_system_test.dart index 0681cdb35d..aa0b59f07b 100644 --- a/packages/flutter_tools/test/general.shard/build_system/build_system_test.dart +++ b/packages/flutter_tools/test/general.shard/build_system/build_system_test.dart @@ -18,7 +18,7 @@ import 'package:flutter_tools/src/build_system/exceptions.dart'; import 'package:flutter_tools/src/convert.dart'; import '../../src/common.dart'; -import '../../src/context.dart'; +import '../../src/fake_process_manager.dart'; void main() { FileSystem fileSystem; diff --git a/packages/flutter_tools/test/general.shard/build_system/targets/icon_tree_shaker_test.dart b/packages/flutter_tools/test/general.shard/build_system/targets/icon_tree_shaker_test.dart index b8e2a38ed3..b0ec631b50 100644 --- a/packages/flutter_tools/test/general.shard/build_system/targets/icon_tree_shaker_test.dart +++ b/packages/flutter_tools/test/general.shard/build_system/targets/icon_tree_shaker_test.dart @@ -21,7 +21,7 @@ import 'package:meta/meta.dart'; import 'package:mockito/mockito.dart'; import '../../../src/common.dart'; -import '../../../src/context.dart'; +import '../../../src/fake_process_manager.dart'; import '../../../src/fakes.dart'; final Platform kNoAnsiPlatform = FakePlatform(stdoutSupportsAnsi: false); diff --git a/packages/flutter_tools/test/general.shard/build_system/targets/localizations_test.dart b/packages/flutter_tools/test/general.shard/build_system/targets/localizations_test.dart index dc8b3de1d7..3bcb243249 100644 --- a/packages/flutter_tools/test/general.shard/build_system/targets/localizations_test.dart +++ b/packages/flutter_tools/test/general.shard/build_system/targets/localizations_test.dart @@ -14,7 +14,7 @@ import 'package:flutter_tools/src/localizations/localizations_utils.dart'; import 'package:mockito/mockito.dart'; import '../../../src/common.dart'; -import '../../../src/context.dart'; +import '../../../src/fake_process_manager.dart'; void main() { // Verifies that values are correctly passed through the localizations diff --git a/packages/flutter_tools/test/general.shard/compile_batch_test.dart b/packages/flutter_tools/test/general.shard/compile_batch_test.dart index aee2de2670..60ef33ca10 100644 --- a/packages/flutter_tools/test/general.shard/compile_batch_test.dart +++ b/packages/flutter_tools/test/general.shard/compile_batch_test.dart @@ -14,7 +14,7 @@ import 'package:flutter_tools/src/compile.dart'; import 'package:package_config/package_config.dart'; import '../src/common.dart'; -import '../src/context.dart'; +import '../src/fake_process_manager.dart'; void main() { testWithoutContext('StdoutHandler can parse output for successful batch compilation', () async { diff --git a/packages/flutter_tools/test/general.shard/compile_expression_test.dart b/packages/flutter_tools/test/general.shard/compile_expression_test.dart index 1be6dc26b1..7987a3939f 100644 --- a/packages/flutter_tools/test/general.shard/compile_expression_test.dart +++ b/packages/flutter_tools/test/general.shard/compile_expression_test.dart @@ -20,7 +20,7 @@ import 'package:package_config/package_config.dart'; import 'package:process/process.dart'; import '../src/common.dart'; -import '../src/context.dart'; +import '../src/fake_process_manager.dart'; import '../src/fakes.dart'; void main() { diff --git a/packages/flutter_tools/test/general.shard/compile_incremental_test.dart b/packages/flutter_tools/test/general.shard/compile_incremental_test.dart index 639e7828c4..e82744056a 100644 --- a/packages/flutter_tools/test/general.shard/compile_incremental_test.dart +++ b/packages/flutter_tools/test/general.shard/compile_incremental_test.dart @@ -17,7 +17,6 @@ import 'package:flutter_tools/src/convert.dart'; import 'package:package_config/package_config.dart'; import '../src/common.dart'; -import '../src/context.dart'; import '../src/fake_process_manager.dart'; import '../src/fakes.dart'; diff --git a/packages/flutter_tools/test/general.shard/crash_reporting_test.dart b/packages/flutter_tools/test/general.shard/crash_reporting_test.dart index b626240c05..1c9a05c2c7 100644 --- a/packages/flutter_tools/test/general.shard/crash_reporting_test.dart +++ b/packages/flutter_tools/test/general.shard/crash_reporting_test.dart @@ -20,8 +20,8 @@ import 'package:http/http.dart'; import 'package:http/testing.dart'; import '../src/common.dart'; -import '../src/context.dart'; import '../src/fake_http_client.dart'; +import '../src/fake_process_manager.dart'; void main() { BufferLogger logger; diff --git a/packages/flutter_tools/test/general.shard/dart/generate_synthetic_packages_test.dart b/packages/flutter_tools/test/general.shard/dart/generate_synthetic_packages_test.dart index 80111f0a6a..3759f04f6a 100644 --- a/packages/flutter_tools/test/general.shard/dart/generate_synthetic_packages_test.dart +++ b/packages/flutter_tools/test/general.shard/dart/generate_synthetic_packages_test.dart @@ -15,7 +15,6 @@ import 'package:flutter_tools/src/build_system/build_system.dart'; import 'package:flutter_tools/src/build_system/targets/localizations.dart'; import '../../src/common.dart'; -import '../../src/context.dart'; import '../../src/fake_process_manager.dart'; import '../../src/fakes.dart'; diff --git a/packages/flutter_tools/test/general.shard/devtools_launcher_test.dart b/packages/flutter_tools/test/general.shard/devtools_launcher_test.dart index 62b34cbde1..f2b9bc9712 100644 --- a/packages/flutter_tools/test/general.shard/devtools_launcher_test.dart +++ b/packages/flutter_tools/test/general.shard/devtools_launcher_test.dart @@ -16,8 +16,8 @@ import 'package:flutter_tools/src/persistent_tool_state.dart'; import 'package:flutter_tools/src/resident_runner.dart'; import '../src/common.dart'; -import '../src/context.dart'; import '../src/fake_http_client.dart'; +import '../src/fake_process_manager.dart'; void main() { BufferLogger logger; diff --git a/packages/flutter_tools/test/general.shard/flutter_validator_test.dart b/packages/flutter_tools/test/general.shard/flutter_validator_test.dart index 070508aea5..1bf8a26f57 100644 --- a/packages/flutter_tools/test/general.shard/flutter_validator_test.dart +++ b/packages/flutter_tools/test/general.shard/flutter_validator_test.dart @@ -15,7 +15,7 @@ import 'package:flutter_tools/src/version.dart'; import 'package:mockito/mockito.dart'; import '../src/common.dart'; -import '../src/context.dart'; +import '../src/fake_process_manager.dart'; import '../src/fakes.dart'; /// Matches a doctor validation result. diff --git a/packages/flutter_tools/test/general.shard/fuchsia/fuchsia_dev_finder_test.dart b/packages/flutter_tools/test/general.shard/fuchsia/fuchsia_dev_finder_test.dart index d096ac0eec..b2588b8b1a 100644 --- a/packages/flutter_tools/test/general.shard/fuchsia/fuchsia_dev_finder_test.dart +++ b/packages/flutter_tools/test/general.shard/fuchsia/fuchsia_dev_finder_test.dart @@ -13,7 +13,7 @@ import 'package:flutter_tools/src/fuchsia/fuchsia_sdk.dart'; import 'package:mockito/mockito.dart'; import '../../src/common.dart'; -import '../../src/context.dart'; +import '../../src/fake_process_manager.dart'; void main() { MockFuchsiaArtifacts mockFuchsiaArtifacts; diff --git a/packages/flutter_tools/test/general.shard/fuchsia/fuchsia_ffx_test.dart b/packages/flutter_tools/test/general.shard/fuchsia/fuchsia_ffx_test.dart index c107ccc4fd..10e7c0d99c 100644 --- a/packages/flutter_tools/test/general.shard/fuchsia/fuchsia_ffx_test.dart +++ b/packages/flutter_tools/test/general.shard/fuchsia/fuchsia_ffx_test.dart @@ -13,7 +13,7 @@ import 'package:flutter_tools/src/fuchsia/fuchsia_sdk.dart'; import 'package:test/fake.dart'; import '../../src/common.dart'; -import '../../src/context.dart'; +import '../../src/fake_process_manager.dart'; void main() { FakeFuchsiaArtifacts fakeFuchsiaArtifacts; diff --git a/packages/flutter_tools/test/general.shard/ios/code_signing_test.dart b/packages/flutter_tools/test/general.shard/ios/code_signing_test.dart index 82b597e92b..2e3ad5e436 100644 --- a/packages/flutter_tools/test/general.shard/ios/code_signing_test.dart +++ b/packages/flutter_tools/test/general.shard/ios/code_signing_test.dart @@ -15,7 +15,7 @@ import 'package:flutter_tools/src/ios/code_signing.dart'; import 'package:flutter_tools/src/globals_null_migrated.dart' as globals; import '../../src/common.dart'; -import '../../src/context.dart'; +import '../../src/fake_process_manager.dart'; void main() { group('Auto signing', () { diff --git a/packages/flutter_tools/test/general.shard/ios/devices_test.dart b/packages/flutter_tools/test/general.shard/ios/devices_test.dart index 4752b40e26..bd2256e293 100644 --- a/packages/flutter_tools/test/general.shard/ios/devices_test.dart +++ b/packages/flutter_tools/test/general.shard/ios/devices_test.dart @@ -28,7 +28,7 @@ import 'package:flutter_tools/src/macos/xcode.dart'; import 'package:mockito/mockito.dart'; import '../../src/common.dart'; -import '../../src/context.dart'; +import '../../src/fake_process_manager.dart'; void main() { final FakePlatform macPlatform = FakePlatform(operatingSystem: 'macos'); diff --git a/packages/flutter_tools/test/general.shard/ios/ios_device_logger_test.dart b/packages/flutter_tools/test/general.shard/ios/ios_device_logger_test.dart index 8851843222..a382f55696 100644 --- a/packages/flutter_tools/test/general.shard/ios/ios_device_logger_test.dart +++ b/packages/flutter_tools/test/general.shard/ios/ios_device_logger_test.dart @@ -20,7 +20,7 @@ import 'package:mockito/mockito.dart'; import 'package:vm_service/vm_service.dart'; import '../../src/common.dart'; -import '../../src/context.dart'; +import '../../src/fake_process_manager.dart'; import '../../src/fake_vm_services.dart'; void main() { diff --git a/packages/flutter_tools/test/general.shard/ios/ios_workflow_test.dart b/packages/flutter_tools/test/general.shard/ios/ios_workflow_test.dart index 7f742adee4..d8500ffd09 100644 --- a/packages/flutter_tools/test/general.shard/ios/ios_workflow_test.dart +++ b/packages/flutter_tools/test/general.shard/ios/ios_workflow_test.dart @@ -10,7 +10,7 @@ import 'package:flutter_tools/src/ios/xcodeproj.dart'; import 'package:flutter_tools/src/macos/xcode.dart'; import '../../src/common.dart'; -import '../../src/context.dart'; +import '../../src/fake_process_manager.dart'; import '../../src/fakes.dart'; void main() { diff --git a/packages/flutter_tools/test/general.shard/linux/linux_device_test.dart b/packages/flutter_tools/test/general.shard/linux/linux_device_test.dart index c3c4a118ef..040b69a0bc 100644 --- a/packages/flutter_tools/test/general.shard/linux/linux_device_test.dart +++ b/packages/flutter_tools/test/general.shard/linux/linux_device_test.dart @@ -17,7 +17,7 @@ import 'package:flutter_tools/src/project.dart'; import 'package:mockito/mockito.dart'; import '../../src/common.dart'; -import '../../src/context.dart'; +import '../../src/fake_process_manager.dart'; import '../../src/fakes.dart'; final FakePlatform linux = FakePlatform( diff --git a/packages/flutter_tools/test/general.shard/resident_devtools_handler_test.dart b/packages/flutter_tools/test/general.shard/resident_devtools_handler_test.dart index e090f0d6de..15537bad56 100644 --- a/packages/flutter_tools/test/general.shard/resident_devtools_handler_test.dart +++ b/packages/flutter_tools/test/general.shard/resident_devtools_handler_test.dart @@ -16,7 +16,7 @@ import 'package:flutter_tools/src/resident_runner.dart'; import 'package:test/fake.dart'; import '../src/common.dart'; -import '../src/context.dart'; +import '../src/fake_process_manager.dart'; import '../src/fake_vm_services.dart'; final vm_service.Isolate isolate = vm_service.Isolate( diff --git a/packages/flutter_tools/test/src/fake_process_manager.dart b/packages/flutter_tools/test/src/fake_process_manager.dart index 65c298f6df..480e56050b 100644 --- a/packages/flutter_tools/test/src/fake_process_manager.dart +++ b/packages/flutter_tools/test/src/fake_process_manager.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 'dart:async'; import 'dart:convert'; import 'dart:io' as io show ProcessSignal, Process, ProcessStartMode, ProcessResult, systemEncoding; @@ -22,7 +20,7 @@ typedef VoidCallback = void Function(); @immutable class FakeCommand { const FakeCommand({ - @required this.command, + required this.command, this.workingDirectory, this.environment, this.encoding, @@ -46,7 +44,7 @@ class FakeCommand { /// be considered correct. /// /// If this is null, the working directory is ignored. - final String workingDirectory; + final String? workingDirectory; /// The environment that must be matched for this [FakeCommand] to be considered correct. /// @@ -54,13 +52,13 @@ class FakeCommand { /// /// Otherwise, each key in this environment must be present and must have a /// value that matches the one given here for the [FakeCommand] to match. - final Map environment; + final Map? environment; /// The stdout and stderr encoding that must be matched for this [FakeCommand] /// to be considered correct. /// /// If this is null, then the encodings are ignored. - final Encoding encoding; + final Encoding? encoding; /// The time to allow to elapse before returning the [exitCode], if this command /// is "executed". @@ -71,7 +69,7 @@ class FakeCommand { /// A callback that is run after [duration] expires but before the [exitCode] /// (and output) are passed back. - final VoidCallback onRun; + final VoidCallback? onRun; /// The process' exit code. /// @@ -92,19 +90,19 @@ class FakeCommand { /// If provided, allows the command completion to be blocked until the future /// resolves. - final Completer completer; + final Completer? completer; /// An optional stdin sink that will be exposed through the resulting /// [FakeProcess]. - final IOSink stdin; + final IOSink? stdin; /// If provided, this exception will be thrown when the fake command is run. - final dynamic exception; + final Object? exception; void _matches( List command, - String workingDirectory, - Map environment, + String? workingDirectory, + Map? environment, Encoding encoding, ) { expect(command, equals(this.command)); @@ -126,7 +124,7 @@ class _FakeProcess implements io.Process { Duration duration, this.pid, this._stderr, - this.stdin, + IOSink? stdin, this._stdout, this._completer, ) : exitCode = Future.delayed(duration).then((void value) { @@ -135,6 +133,7 @@ class _FakeProcess implements io.Process { } return _exitCode; }), + stdin = stdin ?? IOSink(StreamController>().sink), stderr = _stderr == null ? const Stream>.empty() : Stream>.value(utf8.encode(_stderr)), @@ -143,7 +142,7 @@ class _FakeProcess implements io.Process { : Stream>.value(utf8.encode(_stdout)); final int _exitCode; - final Completer _completer; + final Completer? _completer; @override final Future exitCode; @@ -221,8 +220,8 @@ abstract class FakeProcessManager implements ProcessManager { @protected FakeCommand findCommand( List command, - String workingDirectory, - Map environment, + String? workingDirectory, + Map? environment, Encoding encoding, ); @@ -230,17 +229,17 @@ abstract class FakeProcessManager implements ProcessManager { _FakeProcess _runCommand( List command, - String workingDirectory, - Map environment, + String? workingDirectory, + Map? environment, Encoding encoding, ) { _pid += 1; final FakeCommand fakeCommand = findCommand(command, workingDirectory, environment, encoding); if (fakeCommand.exception != null) { - throw fakeCommand.exception; + throw fakeCommand.exception!; } if (fakeCommand.onRun != null) { - fakeCommand.onRun(); + fakeCommand.onRun!(); } return _FakeProcess( fakeCommand.exitCode, @@ -256,8 +255,8 @@ abstract class FakeProcessManager implements ProcessManager { @override Future start( List command, { - String workingDirectory, - Map environment, + String? workingDirectory, + Map? environment, bool includeParentEnvironment = true, // ignored bool runInShell = false, // ignored io.ProcessStartMode mode = io.ProcessStartMode.normal, // ignored @@ -275,8 +274,8 @@ abstract class FakeProcessManager implements ProcessManager { @override Future run( List command, { - String workingDirectory, - Map environment, + String? workingDirectory, + Map? environment, bool includeParentEnvironment = true, // ignored bool runInShell = false, // ignored Encoding stdoutEncoding = io.systemEncoding, @@ -295,8 +294,8 @@ abstract class FakeProcessManager implements ProcessManager { @override io.ProcessResult runSync( List command, { - String workingDirectory, - Map environment, + String? workingDirectory, + Map? environment, bool includeParentEnvironment = true, // ignored bool runInShell = false, // ignored Encoding stdoutEncoding = io.systemEncoding, // actual encoder is ignored @@ -313,18 +312,20 @@ abstract class FakeProcessManager implements ProcessManager { /// Returns false if executable in [excludedExecutables]. @override - bool canRun(dynamic executable, {String workingDirectory}) => !excludedExecutables.contains(executable); + bool canRun(dynamic executable, {String? workingDirectory}) => !excludedExecutables.contains(executable); Set excludedExecutables = {}; @override bool killPid(int pid, [io.ProcessSignal signal = io.ProcessSignal.sigterm]) { // Killing a fake process has no effect unless it has an attached completer. - final _FakeProcess fakeProcess = _fakeRunningProcesses[pid]; + final _FakeProcess? fakeProcess = _fakeRunningProcesses[pid]; if (fakeProcess == null) { return false; } - fakeProcess._completer.complete(); + if (fakeProcess._completer != null) { + fakeProcess._completer!.complete(); + } return true; } } @@ -335,8 +336,8 @@ class _FakeAnyProcessManager extends FakeProcessManager { @override FakeCommand findCommand( List command, - String workingDirectory, - Map environment, + String? workingDirectory, + Map? environment, Encoding encoding, ) { return FakeCommand( @@ -369,8 +370,8 @@ class _SequenceProcessManager extends FakeProcessManager { @override FakeCommand findCommand( List command, - String workingDirectory, - Map environment, + String? workingDirectory, + Map? environment, Encoding encoding, ) { expect(_commands, isNotEmpty,