Unverified Commit 22cef489 authored by Liam Appelbe's avatar Liam Appelbe Committed by GitHub

Null safety migration of packages/flutter_tools/test/commands.shard/hermetic, part 2/3 (#110708)

* Migrate packages/flutter_tools/test/commands.shard/hermetic, part 2/3

* Fix tests

* Fix analysis

* Chris's comments
parent 9dbc09de
......@@ -598,39 +598,39 @@ class CustomDevicesAddCommand extends CustomDevicesCommandBase {
inputs = StreamQueue<String>(nonClosingKeystrokes.stream);
final String id = await (askForString(
final String id = (await askForString(
'id',
description:
'Please enter the id you want to device to have. Must contain only '
'alphanumeric or underscore characters.',
example: 'pi',
validator: (String s) async => RegExp(r'^\w+$').hasMatch(s),
) as FutureOr<String>);
))!;
final String label = await (askForString(
final String label = (await askForString(
'label',
description:
'Please enter the label of the device, which is a slightly more verbose '
'name for the device.',
example: 'Raspberry Pi',
) as FutureOr<String>);
))!;
final String sdkNameAndVersion = await (askForString(
final String sdkNameAndVersion = (await askForString(
'SDK name and version',
example: 'Raspberry Pi 4 Model B+',
) as FutureOr<String>);
))!;
final bool enabled = await askForBool(
'enabled',
description: 'Should the device be enabled?',
);
final String targetStr = await (askForString(
final String targetStr = (await askForString(
'target',
description: 'Please enter the hostname or IPv4/v6 address of the device.',
example: 'raspberrypi',
validator: (String s) async => _isValidHostname(s) || _isValidIpAddr(s)
) as FutureOr<String>);
))!;
final InternetAddress? targetIp = InternetAddress.tryParse(targetStr);
final bool useIp = targetIp != null;
......@@ -639,20 +639,20 @@ class CustomDevicesAddCommand extends CustomDevicesCommandBase {
? InternetAddress.loopbackIPv6
: InternetAddress.loopbackIPv4;
final String username = await (askForString(
final String username = (await askForString(
'username',
description: 'Please enter the username used for ssh-ing into the remote device.',
example: 'pi',
defaultsTo: 'no username',
) as FutureOr<String>);
))!;
final String remoteRunDebugCommand = await (askForString(
final String remoteRunDebugCommand = (await askForString(
'run command',
description:
'Please enter the command executed on the remote device for starting '
r'the app. "/tmp/${appName}" is the path to the asset bundle.',
example: r'flutter-pi /tmp/${appName}'
) as FutureOr<String>);
))!;
final bool usePortForwarding = await askForBool(
'use port forwarding',
......@@ -663,12 +663,12 @@ class CustomDevicesAddCommand extends CustomDevicesCommandBase {
'not using port forwarding.',
);
final String screenshotCommand = await (askForString(
final String screenshotCommand = (await askForString(
'screenshot command',
description: 'Enter the command executed on the remote device for taking a screenshot.',
example: r"fbgrab /tmp/screenshot.png && cat /tmp/screenshot.png | base64 | tr -d ' \n\t'",
defaultsTo: 'no screenshotting support',
) as FutureOr<String>);
))!;
// SSH expects IPv6 addresses to use the bracket syntax like URIs do too,
// but the IPv6 the user enters is a raw IPv6 address, so we need to wrap it.
......@@ -820,8 +820,8 @@ Delete a device from the config file.
Future<FlutterCommandResult> runCommand() async {
checkFeatureEnabled();
final String id = globalResults!['device-id'] as String;
if (!customDevicesConfig.contains(id)) {
final String? id = globalResults!['device-id'] as String?;
if (id == null || !customDevicesConfig.contains(id)) {
throwToolExit('Couldn\'t find device with id "$id" in config at "${customDevicesConfig.configPath}"');
}
......
......@@ -1590,7 +1590,7 @@ class DebounceOperationQueue<T, K> {
final Map<K, Future<T>> _operationQueue = <K, Future<T>>{};
Future<void>? _inProgressAction;
Future<T>? queueAndDebounce(
Future<T> queueAndDebounce(
K operationType,
Duration debounceDuration,
Future<T> Function() action,
......@@ -1599,7 +1599,7 @@ class DebounceOperationQueue<T, K> {
// debounce timer and return its future.
if (_operationQueue[operationType] != null) {
_debounceTimers[operationType]?.reset();
return _operationQueue[operationType];
return _operationQueue[operationType]!;
}
// Otherwise, put one in the queue with a timer.
......
......@@ -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:args/command_runner.dart';
import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/file_system.dart';
......@@ -23,7 +21,7 @@ import '../../src/test_build_system.dart';
import '../../src/test_flutter_command_runner.dart';
void main() {
FileSystem fileSystem;
late FileSystem fileSystem;
final Platform fakePlatform = FakePlatform(
environment: <String, String>{
'FLUTTER_ROOT': '/',
......@@ -243,7 +241,7 @@ class TestWebBuildCommand extends FlutterCommand {
final String description = 'Build a test executable app.';
@override
Future<FlutterCommandResult> runCommand() async => null;
Future<FlutterCommandResult> runCommand() async => FlutterCommandResult.fail();
@override
bool get shouldRunPub => false;
......
......@@ -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:file/memory.dart';
import 'package:file_testing/file_testing.dart';
import 'package:flutter_tools/src/base/file_system.dart';
......@@ -43,10 +41,9 @@ final Platform notWindowsPlatform = FakePlatform(
);
void main() {
FileSystem fileSystem;
ProcessManager processManager;
TestUsage usage;
late FileSystem fileSystem;
late ProcessManager processManager;
late TestUsage usage;
setUpAll(() {
Cache.disableLocking();
......@@ -75,7 +72,7 @@ void main() {
// Returns the command matching the build_windows call to generate CMake
// files.
FakeCommand cmakeGenerationCommand({
void Function() onRun,
void Function()? onRun,
String generator = _defaultGenerator,
}) {
return FakeCommand(
......@@ -95,7 +92,7 @@ void main() {
// Returns the command matching the build_windows call to build.
FakeCommand buildCommand(String buildMode, {
bool verbose = false,
void Function() onRun,
void Function()? onRun,
String stdout = '',
}) {
return FakeCommand(
......@@ -974,7 +971,7 @@ class FakeVisualStudio extends Fake implements VisualStudio {
});
@override
final String cmakePath;
final String? cmakePath;
@override
final String cmakeGenerator;
......
......@@ -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:args/command_runner.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/cache.dart';
......@@ -28,13 +26,13 @@ class FakePub extends Fake implements Pub {
@override
Future<void> get({
PubContext context,
String directory,
PubContext? context,
String? directory,
bool skipIfAbsent = false,
bool upgrade = false,
bool offline = false,
bool generateSyntheticPackage = false,
String flutterRootOverride,
String? flutterRootOverride,
bool checkUpToDate = false,
bool shouldSkipThirdPartyGenerator = true,
bool printProgress = true,
......@@ -50,8 +48,8 @@ class FakePub extends Fake implements Pub {
void main() {
group('usageValues', () {
Testbed testbed;
FakePub fakePub;
late Testbed testbed;
late FakePub fakePub;
setUpAll(() {
Cache.disableLocking();
......
......@@ -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:typed_data';
......@@ -23,7 +21,6 @@ import 'package:flutter_tools/src/commands/custom_devices.dart';
import 'package:flutter_tools/src/custom_devices/custom_device_config.dart';
import 'package:flutter_tools/src/custom_devices/custom_devices_config.dart';
import 'package:flutter_tools/src/runner/flutter_command_runner.dart';
import 'package:meta/meta.dart';
import '../../src/common.dart';
import '../../src/context.dart';
......@@ -171,7 +168,7 @@ final Platform windowsPlatform = FakePlatform(
);
class FakeTerminal implements Terminal {
factory FakeTerminal({Platform platform}) {
factory FakeTerminal({required Platform platform}) {
return FakeTerminal._private(
stdio: FakeStdio(),
platform: platform
......@@ -179,8 +176,8 @@ class FakeTerminal implements Terminal {
}
FakeTerminal._private({
this.stdio,
Platform platform
required this.stdio,
required Platform platform
}) :
terminal = AnsiTerminal(
stdio: stdio,
......@@ -215,9 +212,9 @@ class FakeTerminal implements Terminal {
@override
Future<String> promptForCharInput(
List<String> acceptedCharacters, {
Logger logger,
String prompt,
int defaultChoiceIndex,
required Logger logger,
String? prompt,
int? defaultChoiceIndex,
bool displayAcceptedCharacters = true
}) => terminal.promptForCharInput(
acceptedCharacters,
......@@ -253,10 +250,10 @@ class FakeTerminal implements Terminal {
class FakeCommandRunner extends FlutterCommandRunner {
FakeCommandRunner({
@required Platform platform,
@required FileSystem fileSystem,
@required Logger logger,
UserMessages userMessages
required Platform platform,
required FileSystem fileSystem,
required Logger logger,
UserMessages? userMessages
}) : _platform = platform,
_fileSystem = fileSystem,
_logger = logger,
......@@ -285,7 +282,7 @@ class FakeCommandRunner extends FlutterCommandRunner {
userMessages: _userMessages,
);
// For compatibility with tests that set this to a relative path.
Cache.flutterRoot = _fileSystem.path.normalize(_fileSystem.path.absolute(Cache.flutterRoot));
Cache.flutterRoot = _fileSystem.path.normalize(_fileSystem.path.absolute(Cache.flutterRoot!));
return super.runCommand(topLevelResults);
}
);
......@@ -295,13 +292,13 @@ class FakeCommandRunner extends FlutterCommandRunner {
/// May take platform, logger, processManager and fileSystem from context if
/// not explicitly specified.
CustomDevicesCommand createCustomDevicesCommand({
CustomDevicesConfig Function(FileSystem, Logger) config,
Terminal Function(Platform) terminal,
Platform platform,
FileSystem fileSystem,
ProcessManager processManager,
Logger logger,
PrintFn usagePrintFn,
CustomDevicesConfig Function(FileSystem, Logger)? config,
Terminal Function(Platform)? terminal,
Platform? platform,
FileSystem? fileSystem,
ProcessManager? processManager,
Logger? logger,
PrintFn? usagePrintFn,
bool featureEnabled = false
}) {
platform ??= FakePlatform();
......@@ -340,13 +337,13 @@ CustomDevicesCommand createCustomDevicesCommand({
/// May take platform, logger, processManager and fileSystem from context if
/// not explicitly specified.
CommandRunner<void> createCustomDevicesCommandRunner({
CustomDevicesConfig Function(FileSystem, Logger) config,
Terminal Function(Platform) terminal,
Platform platform,
FileSystem fileSystem,
ProcessManager processManager,
Logger logger,
PrintFn usagePrintFn,
CustomDevicesConfig Function(FileSystem, Logger)? config,
Terminal Function(Platform)? terminal,
Platform? platform,
FileSystem? fileSystem,
ProcessManager? processManager,
Logger? logger,
PrintFn? usagePrintFn,
bool featureEnabled = false,
}) {
platform ??= FakePlatform();
......@@ -372,17 +369,17 @@ CommandRunner<void> createCustomDevicesCommandRunner({
}
FakeTerminal createFakeTerminalForAddingSshDevice({
@required Platform platform,
@required String id,
@required String label,
@required String sdkNameAndVersion,
@required String enabled,
@required String hostname,
@required String username,
@required String runDebug,
@required String usePortForwarding,
@required String screenshot,
@required String apply
required Platform platform,
required String id,
required String label,
required String sdkNameAndVersion,
required String enabled,
required String hostname,
required String username,
required String runDebug,
required String usePortForwarding,
required String screenshot,
required String apply
}) {
return FakeTerminal(platform: platform)
..simulateStdin(id)
......
......@@ -2,12 +2,12 @@
// 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:convert';
import 'package:flutter_tools/src/android/android_sdk.dart';
import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/base/terminal.dart';
import 'package:flutter_tools/src/base/user_messages.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/devices.dart';
import 'package:flutter_tools/src/device.dart';
......@@ -24,7 +24,7 @@ void main() {
Cache.disableLocking();
});
Cache cache;
late Cache cache;
setUp(() {
cache = Cache.test(processManager: FakeProcessManager.any());
......@@ -52,7 +52,7 @@ void main() {
testUsingContext("get devices' platform types", () async {
final List<String> platformTypes = Device.devicesPlatformTypes(
await globals.deviceManager.getAllConnectedDevices(),
await globals.deviceManager!.getAllConnectedDevices(),
);
expect(platformTypes, <String>['android', 'web']);
}, overrides: <Type, Generator>{
......@@ -133,14 +133,14 @@ webby (mobile) • webby • web-javascript • Web SDK (1.2.4) (emulato
}
class _FakeDeviceManager extends DeviceManager {
_FakeDeviceManager();
_FakeDeviceManager() : super(logger: testLogger, terminal: Terminal.test(), userMessages: userMessages);
@override
Future<List<Device>> getAllConnectedDevices() =>
Future<List<Device>>.value(fakeDevices.map((FakeDeviceJsonData d) => d.dev).toList());
@override
Future<List<Device>> refreshAllConnectedDevices({Duration timeout}) =>
Future<List<Device>> refreshAllConnectedDevices({Duration? timeout}) =>
getAllConnectedDevices();
@override
......@@ -153,11 +153,13 @@ class _FakeDeviceManager extends DeviceManager {
}
class NoDevicesManager extends DeviceManager {
NoDevicesManager() : super(logger: testLogger, terminal: Terminal.test(), userMessages: userMessages);
@override
Future<List<Device>> getAllConnectedDevices() async => <Device>[];
@override
Future<List<Device>> refreshAllConnectedDevices({Duration timeout}) =>
Future<List<Device>> refreshAllConnectedDevices({Duration? timeout}) =>
getAllConnectedDevices();
@override
......
......@@ -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:file/file.dart';
import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/io.dart';
......@@ -20,11 +18,11 @@ import '../../src/fakes.dart';
import '../../src/test_flutter_command_runner.dart';
void main() {
FileSystem fileSystem;
BufferLogger bufferLogger;
FakeTerminal terminal;
ProcessManager processManager;
FakeStdio stdio;
late FileSystem fileSystem;
late BufferLogger bufferLogger;
late FakeTerminal terminal;
late ProcessManager processManager;
late FakeStdio stdio;
setUpAll(() {
Cache.disableLocking();
......@@ -224,11 +222,11 @@ class FakeTerminal extends Fake implements Terminal {
_selected = selected;
}
List<String> _characters;
String _selected;
List<String>? _characters;
late String _selected;
@override
Future<String> promptForCharInput(List<String> acceptedCharacters, {Logger logger, String prompt, int defaultChoiceIndex, bool displayAcceptedCharacters = true}) async {
Future<String> promptForCharInput(List<String> acceptedCharacters, {Logger? logger, String? prompt, int? defaultChoiceIndex, bool displayAcceptedCharacters = true}) async {
expect(acceptedCharacters, _characters);
return _selected;
}
......
......@@ -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:file/memory.dart';
import 'package:flutter_tools/src/application_package.dart';
import 'package:flutter_tools/src/base/common.dart';
......@@ -25,10 +23,10 @@ import '../../src/context.dart';
import '../../src/test_flutter_command_runner.dart';
void main() {
FileSystem fileSystem;
BufferLogger logger;
Platform platform;
FakeDeviceManager fakeDeviceManager;
late FileSystem fileSystem;
late BufferLogger logger;
late Platform platform;
late FakeDeviceManager fakeDeviceManager;
setUp(() {
fileSystem = MemoryFileSystem.test();
......@@ -254,15 +252,15 @@ void main() {
class ThrowingScreenshotDevice extends ScreenshotDevice {
@override
Future<LaunchResult> startApp(
ApplicationPackage package, {
String mainPath,
String route,
DebuggingOptions debuggingOptions,
Map<String, dynamic> platformArgs,
ApplicationPackage? package, {
String? mainPath,
String? route,
DebuggingOptions? debuggingOptions,
Map<String, dynamic>? platformArgs,
bool prebuiltApplication = false,
bool usesTerminalUi = true,
bool ipv6 = false,
String userIdentifier,
String? userIdentifier,
}) async {
throwToolExit('cannot start app');
}
......@@ -289,15 +287,15 @@ class ScreenshotDevice extends Fake implements Device {
@override
Future<LaunchResult> startApp(
ApplicationPackage package, {
String mainPath,
String route,
DebuggingOptions debuggingOptions,
Map<String, dynamic> platformArgs,
ApplicationPackage? package, {
String? mainPath,
String? route,
DebuggingOptions? debuggingOptions,
Map<String, dynamic>? platformArgs,
bool prebuiltApplication = false,
bool usesTerminalUi = true,
bool ipv6 = false,
String userIdentifier,
String? userIdentifier,
}) async => LaunchResult.succeeded();
@override
......@@ -307,13 +305,13 @@ class ScreenshotDevice extends Fake implements Device {
class FakePub extends Fake implements Pub {
@override
Future<void> get({
PubContext context,
String directory,
PubContext? context,
String? directory,
bool skipIfAbsent = false,
bool upgrade = false,
bool offline = false,
bool generateSyntheticPackage = false,
String flutterRootOverride,
String? flutterRootOverride,
bool checkUpToDate = false,
bool shouldSkipThirdPartyGenerator = true,
bool printProgress = true,
......@@ -324,13 +322,13 @@ class FakeDeviceManager extends Fake implements DeviceManager {
List<Device> devices = <Device>[];
@override
String specifiedDeviceId;
String? specifiedDeviceId;
@override
Future<List<Device>> getDevices() async => devices;
@override
Future<List<Device>> findTargetDevices(FlutterProject flutterProject, {Duration timeout}) async => devices;
Future<List<Device>> findTargetDevices(FlutterProject? flutterProject, {Duration? timeout}) async => devices;
}
class FailingFakeFlutterDriverFactory extends Fake implements FlutterDriverFactory {
......@@ -348,13 +346,13 @@ class FailingFakeDriverService extends Fake implements DriverService {
List<String> arguments,
Map<String, String> environment,
PackageConfig packageConfig, {
bool headless,
String chromeBinary,
String browserName,
bool androidEmulator,
int driverPort,
List<String> webBrowserFlags,
List<String> browserDimension,
String profileMemory,
bool? headless,
String? chromeBinary,
String? browserName,
bool? androidEmulator,
int? driverPort,
List<String>? webBrowserFlags,
List<String>? browserDimension,
String? profileMemory,
}) async => 1;
}
......@@ -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:file/memory.dart';
import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/base/file_system.dart';
......@@ -18,10 +16,10 @@ import '../../src/fake_process_manager.dart';
import '../../src/test_flutter_command_runner.dart';
void main() {
FileSystem fileSystem;
BufferLogger logger;
Artifacts artifacts;
FakeProcessManager processManager;
late FileSystem fileSystem;
late BufferLogger logger;
late Artifacts artifacts;
late FakeProcessManager processManager;
setUpAll(() {
Cache.disableLocking();
......
......@@ -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:args/command_runner.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/cache.dart';
......@@ -17,12 +15,12 @@ import '../../src/test_flutter_command_runner.dart';
void main() {
group('ide_config', () {
Directory tempDir;
Directory templateDir;
Directory intellijDir;
Directory toolsDir;
late Directory tempDir;
late Directory templateDir;
late Directory intellijDir;
late Directory toolsDir;
Map<String, String> getFilesystemContents([ Directory root ]) {
Map<String, String> getFilesystemContents([ Directory? root ]) {
final String tempPath = tempDir.absolute.path;
final List<String> paths =
(root ?? tempDir).listSync(recursive: true).map((FileSystemEntity entity) {
......@@ -67,7 +65,7 @@ void main() {
if (manifest[key] != 'dir') {
tempDir.childFile(key)
..createSync(recursive: true)
..writeAsStringSync(manifest[key]);
..writeAsStringSync(manifest[key]!);
}
}
}
......@@ -78,7 +76,7 @@ void main() {
}
Future<void> updateIdeConfig({
Directory dir,
Directory? dir,
List<String> args = const <String>[],
Map<String, String> expectedContents = const <String, String>{},
List<String> unexpectedPaths = const <String>[],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment