Skip to content

Commit

Permalink
Null safety migration of packages/flutter_tools/test/commands.shard/h…
Browse files Browse the repository at this point in the history
…ermetic, part 2/3 (#110708)

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

* Fix tests

* Fix analysis

* Chris's comments
  • Loading branch information
liamappelbe authored Sep 6, 2022
1 parent 9dbc09d commit 22cef48
Show file tree
Hide file tree
Showing 12 changed files with 219 additions and 237 deletions.
32 changes: 16 additions & 16 deletions packages/flutter_tools/lib/src/commands/custom_devices.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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',
Expand All @@ -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.
Expand Down Expand Up @@ -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}"');
}

Expand Down
4 changes: 2 additions & 2 deletions packages/flutter_tools/lib/src/commands/daemon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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': '/',
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -974,7 +971,7 @@ class FakeVisualStudio extends Fake implements VisualStudio {
});

@override
final String cmakePath;
final String? cmakePath;

@override
final String cmakeGenerator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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';
Expand Down Expand Up @@ -171,16 +168,16 @@ final Platform windowsPlatform = FakePlatform(
);

class FakeTerminal implements Terminal {
factory FakeTerminal({Platform platform}) {
factory FakeTerminal({required Platform platform}) {
return FakeTerminal._private(
stdio: FakeStdio(),
platform: platform
);
}

FakeTerminal._private({
this.stdio,
Platform platform
required this.stdio,
required Platform platform
}) :
terminal = AnsiTerminal(
stdio: stdio,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
);
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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)
Expand Down
Loading

0 comments on commit 22cef48

Please sign in to comment.