From a204f038fcbb3fc86641cc652bd8c6d80852ecbb Mon Sep 17 00:00:00 2001 From: Dan Field Date: Wed, 27 Jan 2021 11:44:51 -0800 Subject: [PATCH] Null safe migration for fuchsia_remote_debug_protocol (#74762) --- .../lib/src/dart/dart_vm.dart | 60 ++++++-------- .../lib/src/fuchsia_remote_connection.dart | 78 +++++++++---------- .../lib/src/runners/ssh_command_runner.dart | 8 +- .../pubspec.yaml | 2 +- .../test/fuchsia_remote_connection_test.dart | 44 +++++------ .../test/src/dart/dart_vm_test.dart | 49 +++++------- .../src/runners/ssh_command_runner_test.dart | 18 ++--- 7 files changed, 116 insertions(+), 143 deletions(-) diff --git a/packages/fuchsia_remote_debug_protocol/lib/src/dart/dart_vm.dart b/packages/fuchsia_remote_debug_protocol/lib/src/dart/dart_vm.dart index fa65aa6acc..281e082010 100644 --- a/packages/fuchsia_remote_debug_protocol/lib/src/dart/dart_vm.dart +++ b/packages/fuchsia_remote_debug_protocol/lib/src/dart/dart_vm.dart @@ -10,14 +10,13 @@ import 'package:vm_service/vm_service.dart' as vms; import '../common/logging.dart'; const Duration _kConnectTimeout = Duration(seconds: 3); -const Duration _kRpcTimeout = Duration(seconds: 5); final Logger _log = Logger('DartVm'); /// Signature of an asynchronous function for establishing a [vms.VmService] /// connection to a [Uri]. typedef RpcPeerConnectionFunction = Future Function( Uri uri, { - Duration timeout, + required Duration timeout, }); /// [DartVm] uses this function to connect to the Dart VM on Fuchsia. @@ -34,7 +33,7 @@ Future _waitAndConnect( Duration timeout = _kConnectTimeout, }) async { int attempts = 0; - WebSocket socket; + late WebSocket socket; while (true) { try { socket = await WebSocket.connect(uri.toString()); @@ -56,7 +55,7 @@ Future _waitAndConnect( await service.getVersion(); return service; } catch (e) { - await socket?.close(); + await socket.close(); if (attempts > 5) { _log.warning('It is taking an unusually long time to connect to the VM...'); } @@ -112,9 +111,6 @@ class DartVm { } final vms.VmService service = await fuchsiaVmServiceConnectionFunction(uri, timeout: timeout); - if (service == null) { - return null; - } return DartVm._(service, uri); } @@ -123,16 +119,13 @@ class DartVm { /// This is not limited to Isolates running Flutter, but to any Isolate on the /// VM. Therefore, the [pattern] argument should be written to exclude /// matching unintended isolates. - Future> getMainIsolatesByPattern( - Pattern pattern, { - Duration timeout = _kRpcTimeout, - }) async { + Future> getMainIsolatesByPattern(Pattern pattern) async { final vms.VM vmRef = await _vmService.getVM(); final List result = []; - for (final vms.IsolateRef isolateRef in vmRef.isolates) { - if (pattern.matchAsPrefix(isolateRef.name) != null) { + for (final vms.IsolateRef isolateRef in vmRef.isolates!) { + if (pattern.matchAsPrefix(isolateRef.name!) != null) { _log.fine('Found Isolate matching "$pattern": "${isolateRef.name}"'); - result.add(IsolateRef._fromJson(isolateRef.json, this)); + result.add(IsolateRef._fromJson(isolateRef.json!, this)); } } return result; @@ -145,16 +138,11 @@ class DartVm { /// the flutter view's name), then the flutter view's ID will be added /// instead. If none of these things can be found (isolate has no name or the /// flutter view has no ID), then the result will not be added to the list. - Future> getAllFlutterViews({ - Duration timeout = _kRpcTimeout, - }) async { + Future> getAllFlutterViews() async { final List views = []; final vms.Response rpcResponse = await _vmService.callMethod('_flutter.listViews'); - for (final Map jsonView in (rpcResponse.json['views'] as List).cast>()) { - final FlutterView flutterView = FlutterView._fromJson(jsonView); - if (flutterView != null) { - views.add(flutterView); - } + for (final Map jsonView in (rpcResponse.json!['views'] as List).cast>()) { + views.add(FlutterView._fromJson(jsonView)); } return views; } @@ -190,25 +178,25 @@ class FlutterView { /// All other cases return a [FlutterView] instance. The name of the /// view may be null, but the id will always be set. factory FlutterView._fromJson(Map json) { - final Map isolate = json['isolate'] as Map; - final String id = json['id'] as String; - String name; - if (isolate != null) { - name = isolate['name'] as String; - if (name == null) { - throw RpcFormatError('Unable to find name for isolate "$isolate"'); - } - } + final Map? isolate = json['isolate'] as Map?; + final String? id = json['id'] as String?; + String? name; if (id == null) { throw RpcFormatError( 'Unable to find view name for the following JSON structure "$json"'); } + if (isolate != null) { + name = isolate['name'] as String?; + if (name == null) { + throw RpcFormatError('Unable to find name for isolate "$isolate"'); + } + } return FlutterView._(name, id); } /// Determines the name of the isolate associated with this view. If there is /// no associated isolate, this will be set to the view's ID. - final String _name; + final String? _name; /// The ID of the Flutter view. final String _id; @@ -219,7 +207,7 @@ class FlutterView { /// Returns the name of the [FlutterView]. /// /// May be null if there is no associated isolate. - String get name => _name; + String? get name => _name; } /// This is a wrapper class for the `@Isolate` RPC object. @@ -233,9 +221,9 @@ class IsolateRef { IsolateRef._(this.name, this.number, this.dartVm); factory IsolateRef._fromJson(Map json, DartVm dartVm) { - final String number = json['number'] as String; - final String name = json['name'] as String; - final String type = json['type'] as String; + final String? number = json['number'] as String?; + final String? name = json['name'] as String?; + final String? type = json['type'] as String?; if (type == null) { throw RpcFormatError('Unable to find type within JSON "$json"'); } diff --git a/packages/fuchsia_remote_debug_protocol/lib/src/fuchsia_remote_connection.dart b/packages/fuchsia_remote_debug_protocol/lib/src/fuchsia_remote_connection.dart index f570d9240b..55f58c8925 100644 --- a/packages/fuchsia_remote_debug_protocol/lib/src/fuchsia_remote_connection.dart +++ b/packages/fuchsia_remote_debug_protocol/lib/src/fuchsia_remote_connection.dart @@ -34,8 +34,8 @@ final Logger _log = Logger('FuchsiaRemoteConnection'); typedef PortForwardingFunction = Future Function( String address, int remotePort, [ - String interface, - String configFile, + String? interface, + String? configFile, ]); /// The function for forwarding the local machine's ports to a remote Fuchsia @@ -83,7 +83,7 @@ enum DartVmEventType { /// Specifies the type of the event (whether the VM has started or has stopped), /// and contains the service port of the VM as well as a URL to connect to it. class DartVmEvent { - DartVmEvent._({this.eventType, this.servicePort, this.uri}); + DartVmEvent._({required this.eventType, required this.servicePort, required this.uri}); /// The URL used to connect to the Dart VM. final Uri uri; @@ -121,13 +121,13 @@ class FuchsiaRemoteConnection { /// A broadcast stream that emits events relating to Dart VM's as they update. Stream get onDartVmEvent => _onDartVmEvent; - Stream _onDartVmEvent; + late Stream _onDartVmEvent; final StreamController _dartVmEventController = StreamController(); /// VM service cache to avoid repeating handshakes across function /// calls. Keys a URI to a DartVm connection instance. - final Map _dartVmCache = {}; + final Map _dartVmCache = {}; /// Same as [FuchsiaRemoteConnection.connect] albeit with a provided /// [SshCommandRunner] instance. @@ -188,9 +188,9 @@ class FuchsiaRemoteConnection { /// In the event that `FUCHSIA_SSH_CONFIG` is set in the environment, that /// will be used when `sshConfigPath` isn't supplied. static Future connect([ - String address, + String? address, String interface = '', - String sshConfigPath, + String? sshConfigPath, ]) async { address ??= Platform.environment['FUCHSIA_DEVICE_URL']; sshConfigPath ??= Platform.environment['FUCHSIA_SSH_CONFIG']; @@ -210,7 +210,7 @@ class FuchsiaRemoteConnection { SshCommandRunner( address: address, interface: interface, - sshConfigPath: sshConfigPath, + sshConfigPath: sshConfigPath!, ), ); } @@ -225,14 +225,14 @@ class FuchsiaRemoteConnection { // Closes VM service first to ensure that the connection is closed cleanly // on the target before shutting down the forwarding itself. final Uri uri = _getDartVmUri(pf); - final DartVm vmService = _dartVmCache[uri]; + final DartVm? vmService = _dartVmCache[uri]; _dartVmCache[uri] = null; await vmService?.stop(); await pf.stop(); } for (final PortForwarder pf in _dartVmPortMap.values) { final Uri uri = _getDartVmUri(pf); - final DartVm vmService = _dartVmCache[uri]; + final DartVm? vmService = _dartVmCache[uri]; _dartVmCache[uri] = null; await vmService?.stop(); await pf.stop(); @@ -250,7 +250,7 @@ class FuchsiaRemoteConnection { /// (possible when the Isolate we're attempting to connect to is in the only /// instance of the Dart VM and its service port has not yet opened). Future> _waitForMainIsolatesByPattern([ - Pattern pattern, + Pattern? pattern, Duration timeout = _kIsolateFindTimeout, Duration vmConnectionTimeout = _kDartVmConnectionTimeout, ]) async { @@ -260,12 +260,10 @@ class FuchsiaRemoteConnection { if (event.eventType == DartVmEventType.started) { _log.fine('New VM found on port: ${event.servicePort}. Searching ' 'for Isolate: $pattern'); - final DartVm vmService = await _getDartVm(event.uri, + final DartVm? vmService = await _getDartVm(event.uri, timeout: _kDartVmConnectionTimeout); // If the VM service is null, set the result to the empty list. - final List result = await vmService - ?.getMainIsolatesByPattern(pattern, timeout: timeout) ?? - []; + final List result = await vmService?.getMainIsolatesByPattern(pattern!) ?? []; if (result.isNotEmpty) { if (!completer.isCompleted) { completer.complete(result); @@ -308,7 +306,7 @@ class FuchsiaRemoteConnection { final List>> isolates = >>[]; for (final PortForwarder fp in _dartVmPortMap.values) { - final DartVm vmService = + final DartVm? vmService = await _getDartVm(_getDartVmUri(fp), timeout: vmConnectionTimeout); if (vmService == null) { continue; @@ -393,7 +391,7 @@ class FuchsiaRemoteConnection { } for (final PortForwarder pf in _dartVmPortMap.values) { - final DartVm service = await _getDartVm(_getDartVmUri(pf)); + final DartVm? service = await _getDartVm(_getDartVmUri(pf)); if (service == null) { await shutDownPortForwarder(pf); } else { @@ -405,11 +403,11 @@ class FuchsiaRemoteConnection { } Uri _getDartVmUri(PortForwarder pf) { - String addr; + String? addr; if (pf.openPortAddress == null) { addr = _useIpV6 ? '[$_ipv6Loopback]' : _ipv4Loopback; } else { - addr = isIpV6Address(pf.openPortAddress) + addr = isIpV6Address(pf.openPortAddress!) ? '[${pf.openPortAddress}]' : pf.openPortAddress; } @@ -421,7 +419,7 @@ class FuchsiaRemoteConnection { /// /// Returns null if either there is an [HttpException] or a /// [TimeoutException], else a [DartVm] instance. - Future _getDartVm( + Future _getDartVm( Uri uri, { Duration timeout = _kDartVmConnectionTimeout, }) async { @@ -462,7 +460,7 @@ class FuchsiaRemoteConnection { _dartVmEventController.add(DartVmEvent._( eventType: DartVmEventType.started, servicePort: servicePort, - uri: _getDartVmUri(_dartVmPortMap[servicePort]), + uri: _getDartVmUri(_dartVmPortMap[servicePort]!), )); } } @@ -488,9 +486,9 @@ class FuchsiaRemoteConnection { Future _forwardOpenPortsToDeviceServicePorts() async { await stop(); final List servicePorts = await getDeviceServicePorts(); - final List forwardedVmServicePorts = - await Future.wait( - servicePorts.map>((int deviceServicePort) { + final List forwardedVmServicePorts = + await Future.wait( + servicePorts.map>((int deviceServicePort) { return fuchsiaPortForwardingFunction( _sshCommandRunner.address, deviceServicePort, @@ -498,9 +496,9 @@ class FuchsiaRemoteConnection { _sshCommandRunner.sshConfigPath); })); - for (final PortForwarder pf in forwardedVmServicePorts) { + for (final PortForwarder? pf in forwardedVmServicePorts) { // TODO(awdavies): Handle duplicates. - _dartVmPortMap[pf.remotePort] = pf; + _dartVmPortMap[pf!.remotePort] = pf; } // Don't queue events, since this is the initial forwarding. @@ -530,7 +528,7 @@ class FuchsiaRemoteConnection { if (line == '') { continue; } - final int port = int.tryParse(line); + final int? port = int.tryParse(line); if (port != null) { ports.add(port); } @@ -552,7 +550,7 @@ abstract class PortForwarder { /// The address on which the open port is accessible. Defaults to null to /// indicate local loopback. - String get openPortAddress => null; + String? get openPortAddress => null; /// The destination port on the other end of the port forwarding tunnel. int get remotePort; @@ -577,8 +575,8 @@ class _SshPortForwarder implements PortForwarder { final String _remoteAddress; final int _remotePort; final ServerSocket _localSocket; - final String _sshConfigPath; - final String _interface; + final String? _sshConfigPath; + final String? _interface; final bool _ipV6; @override @@ -595,15 +593,15 @@ class _SshPortForwarder implements PortForwarder { static Future<_SshPortForwarder> start( String address, int remotePort, [ - String interface, - String sshConfigPath, + String? interface, + String? sshConfigPath, ]) async { final bool isIpV6 = isIpV6Address(address); - final ServerSocket localSocket = await _createLocalSocket(); + final ServerSocket? localSocket = await _createLocalSocket(); if (localSocket == null || localSocket.port == 0) { _log.warning('_SshPortForwarder failed to find a local port for ' '$address:$remotePort'); - return null; + throw StateError('Unable to create a socket or no available ports.'); } // TODO(awdavies): The square-bracket enclosure for using the IPv6 loopback // didn't appear to work, but when assigning to the IPv4 loopback device, @@ -614,7 +612,7 @@ class _SshPortForwarder implements PortForwarder { final String formattedForwardingUrl = '${localSocket.port}:$_ipv4Loopback:$remotePort'; final String targetAddress = - isIpV6 && interface.isNotEmpty ? '$address%$interface' : address; + isIpV6 && interface!.isNotEmpty ? '$address%$interface' : address; const String dummyRemoteCommand = 'true'; final List command = [ 'ssh', @@ -636,7 +634,7 @@ class _SshPortForwarder implements PortForwarder { _log.fine("'${command.join(' ')}' exited with exit code " '${processResult.exitCode}'); if (processResult.exitCode != 0) { - return null; + throw StateError('Unable to start port forwarding'); } final _SshPortForwarder result = _SshPortForwarder._( address, remotePort, localSocket, interface, sshConfigPath, isIpV6); @@ -653,13 +651,13 @@ class _SshPortForwarder implements PortForwarder { // uses the IPv4 loopback. final String formattedForwardingUrl = '${_localSocket.port}:$_ipv4Loopback:$_remotePort'; - final String targetAddress = _ipV6 && _interface.isNotEmpty + final String targetAddress = _ipV6 && _interface!.isNotEmpty ? '$_remoteAddress%$_interface' : _remoteAddress; - final List command = [ + final List command = [ 'ssh', if (_sshConfigPath != null) - ...['-F', _sshConfigPath], + ...['-F', _sshConfigPath], '-O', 'cancel', '-L', @@ -680,7 +678,7 @@ class _SshPortForwarder implements PortForwarder { /// /// If successful returns a valid [ServerSocket] (which must be disconnected /// later). - static Future _createLocalSocket() async { + static Future _createLocalSocket() async { ServerSocket s; try { s = await ServerSocket.bind(_ipv4Loopback, 0); diff --git a/packages/fuchsia_remote_debug_protocol/lib/src/runners/ssh_command_runner.dart b/packages/fuchsia_remote_debug_protocol/lib/src/runners/ssh_command_runner.dart index ef18098beb..23e27ad366 100644 --- a/packages/fuchsia_remote_debug_protocol/lib/src/runners/ssh_command_runner.dart +++ b/packages/fuchsia_remote_debug_protocol/lib/src/runners/ssh_command_runner.dart @@ -44,7 +44,7 @@ class SshCommandRunner { /// IPv4 nor IPv6. When connecting to a link local address (`fe80::` is /// usually at the start of the address), an interface should be supplied. SshCommandRunner({ - this.address, + required this.address, this.interface = '', this.sshConfigPath, }) : _processManager = const LocalProcessManager() { @@ -55,7 +55,7 @@ class SshCommandRunner { @visibleForTesting SshCommandRunner.withProcessManager( this._processManager, { - this.address, + required this.address, this.interface = '', this.sshConfigPath, }) { @@ -70,7 +70,7 @@ class SshCommandRunner { final String address; /// The path to the SSH config (optional). - final String sshConfigPath; + final String? sshConfigPath; /// The name of the machine's network interface (for use with IPv6 /// connections. Ignored otherwise). @@ -84,7 +84,7 @@ class SshCommandRunner { final List args = [ 'ssh', if (sshConfigPath != null) - ...['-F', sshConfigPath], + ...['-F', sshConfigPath!], if (isIpV6Address(address)) ...['-6', if (interface.isEmpty) address else '$address%$interface'] else diff --git a/packages/fuchsia_remote_debug_protocol/pubspec.yaml b/packages/fuchsia_remote_debug_protocol/pubspec.yaml index 66d62a54f0..de1cd4353d 100644 --- a/packages/fuchsia_remote_debug_protocol/pubspec.yaml +++ b/packages/fuchsia_remote_debug_protocol/pubspec.yaml @@ -5,7 +5,7 @@ homepage: http://flutter.dev author: Flutter Authors environment: - sdk: ">=2.2.2 <3.0.0" + sdk: '>=2.12.0-0 <3.0.0' dependencies: process: 4.0.0-nullsafety.4 diff --git a/packages/fuchsia_remote_debug_protocol/test/fuchsia_remote_connection_test.dart b/packages/fuchsia_remote_debug_protocol/test/fuchsia_remote_connection_test.dart index cc9072b794..92783e5632 100644 --- a/packages/fuchsia_remote_debug_protocol/test/fuchsia_remote_connection_test.dart +++ b/packages/fuchsia_remote_debug_protocol/test/fuchsia_remote_connection_test.dart @@ -11,9 +11,9 @@ import 'common.dart'; void main() { group('FuchsiaRemoteConnection.connect', () { - List forwardedPorts; + late List forwardedPorts; List fakeVmServices; - List uriConnections; + late List uriConnections; setUp(() { final List> flutterViewCannedResponses = @@ -63,7 +63,7 @@ void main() { uriConnections = []; Future fakeVmConnectionFunction( Uri uri, { - Duration timeout, + Duration? timeout, }) { return Future(() async { final FakeVmService service = FakeVmService(); @@ -89,8 +89,8 @@ void main() { Future fakePortForwardingFunction( String address, int remotePort, [ - String interface = '', - String configFile, + String? interface = '', + String? configFile, ]) { return Future(() { final FakePortForwarder pf = FakePortForwarder(); @@ -156,8 +156,8 @@ void main() { Future fakePortForwardingFunction( String address, int remotePort, [ - String interface = '', - String configFile, + String? interface = '', + String? configFile, ]) { return Future(() { final FakePortForwarder pf = FakePortForwarder(); @@ -223,8 +223,8 @@ void main() { Future fakePortForwardingFunction( String address, int remotePort, [ - String interface = '', - String configFile, + String? interface = '', + String? configFile, ]) { return Future(() { final FakePortForwarder pf = FakePortForwarder(); @@ -296,24 +296,24 @@ void main() { } class FakeSshCommandRunner extends Fake implements SshCommandRunner { - List findResponse; - List lsResponse; + List? findResponse; + List? lsResponse; @override Future> run(String command) async { if (command.startsWith('/bin/find')) { - return findResponse; + return findResponse!; } if (command.startsWith('/bin/ls')) { - return lsResponse; + return lsResponse!; } throw UnimplementedError(command); } @override - String interface; + String interface = ''; @override - String address; + String address = ''; @override String get sshConfigPath => '~/.ssh'; @@ -321,13 +321,13 @@ class FakeSshCommandRunner extends Fake implements SshCommandRunner { class FakePortForwarder extends Fake implements PortForwarder { @override - int port; + int port = 0; @override - int remotePort; + int remotePort = 0; @override - String openPortAddress; + String? openPortAddress; bool stopped = false; @override @@ -338,7 +338,7 @@ class FakePortForwarder extends Fake implements PortForwarder { class FakeVmService extends Fake implements vms.VmService { bool disposed = false; - vms.Response flutterListViews; + vms.Response? flutterListViews; @override Future dispose() async { @@ -346,15 +346,15 @@ class FakeVmService extends Fake implements vms.VmService { } @override - Future callMethod(String method, {String isolateId, Map args}) async { + Future callMethod(String method, {String? isolateId, Map? args}) async { if (method == '_flutter.listViews') { - return flutterListViews; + return flutterListViews!; } throw UnimplementedError(method); } @override - Future onDone; + Future onDone = Future.value(); @override Future getVersion() async { diff --git a/packages/fuchsia_remote_debug_protocol/test/src/dart/dart_vm_test.dart b/packages/fuchsia_remote_debug_protocol/test/src/dart/dart_vm_test.dart index d5b95252a0..24ea869dbe 100644 --- a/packages/fuchsia_remote_debug_protocol/test/src/dart/dart_vm_test.dart +++ b/packages/fuchsia_remote_debug_protocol/test/src/dart/dart_vm_test.dart @@ -16,24 +16,11 @@ void main() { restoreVmServiceConnectionFunction(); }); - test('null connector', () async { - Future fakeServiceFunction( - Uri uri, { - Duration timeout, - }) { - return Future(() => null); - } - - fuchsiaVmServiceConnectionFunction = fakeServiceFunction; - expect(await DartVm.connect(Uri.parse('http://this.whatever/ws')), - equals(null)); - }); - test('disconnect closes peer', () async { final FakeVmService service = FakeVmService(); Future fakeServiceFunction( Uri uri, { - Duration timeout, + Duration? timeout, }) { return Future(() => service); } @@ -47,7 +34,7 @@ void main() { }); group('DartVm.getAllFlutterViews', () { - FakeVmService fakeService; + late FakeVmService fakeService; setUp(() { fakeService = FakeVmService(); @@ -91,7 +78,7 @@ void main() { Future fakeVmConnectionFunction( Uri uri, { - Duration timeout, + Duration? timeout, }) { fakeService.flutterListViews = vms.Response.parse(flutterViewCannedResponses); return Future(() => fakeService); @@ -147,7 +134,7 @@ void main() { Future fakeVmConnectionFunction( Uri uri, { - Duration timeout, + Duration? timeout, }) { fakeService.flutterListViews = vms.Response.parse(flutterViewCannedResponses); return Future(() => fakeService); @@ -194,7 +181,7 @@ void main() { Future fakeVmConnectionFunction( Uri uri, { - Duration timeout, + Duration? timeout, }) { fakeService.flutterListViews = vms.Response.parse(flutterViewCannedResponseMissingId); return Future(() => fakeService); @@ -219,33 +206,33 @@ void main() { 'id': 'isolates/1', 'name': 'file://thingThatWillNotMatch:main()', 'number': '1', - }), + })!, vms.IsolateRef.parse({ 'type': '@Isolate', 'fixedId': 'true', 'id': 'isolates/2', 'name': '0:dart_name_pattern()', 'number': '2', - }), + })!, vms.IsolateRef.parse({ 'type': '@Isolate', 'fixedId': 'true', 'id': 'isolates/3', 'name': 'flutterBinary.cmx', 'number': '3', - }), + })!, vms.IsolateRef.parse({ 'type': '@Isolate', 'fixedId': 'true', 'id': 'isolates/4', 'name': '0:some_other_dart_name_pattern()', 'number': '4', - }), + })!, ]; Future fakeVmConnectionFunction( Uri uri, { - Duration timeout, + Duration? timeout, }) { fakeService.vm = FakeVM(isolates: isolates); return Future(() => fakeService); @@ -279,7 +266,7 @@ void main() { Future fakeVmConnectionFunction( Uri uri, { - Duration timeout, + Duration? timeout, }) { fakeService.flutterListViews = vms.Response.parse(flutterViewCannedResponseMissingIsolateName); return Future(() => fakeService); @@ -300,11 +287,11 @@ void main() { class FakeVmService extends Fake implements vms.VmService { bool disposed = false; - vms.Response flutterListViews; - vms.VM vm; + vms.Response? flutterListViews; + vms.VM? vm; @override - Future getVM() async => vm; + Future getVM() async => vm!; @override Future dispose() async { @@ -312,15 +299,15 @@ class FakeVmService extends Fake implements vms.VmService { } @override - Future callMethod(String method, {String isolateId, Map args}) async { + Future callMethod(String method, {String? isolateId, Map? args}) async { if (method == '_flutter.listViews') { - return flutterListViews; + return flutterListViews!; } throw UnimplementedError(method); } @override - Future onDone; + Future onDone = Future.value(); } class FakeVM extends Fake implements vms.VM { @@ -329,5 +316,5 @@ class FakeVM extends Fake implements vms.VM { }); @override - List isolates; + List? isolates; } diff --git a/packages/fuchsia_remote_debug_protocol/test/src/runners/ssh_command_runner_test.dart b/packages/fuchsia_remote_debug_protocol/test/src/runners/ssh_command_runner_test.dart index a0b5d5c218..5f524efce5 100644 --- a/packages/fuchsia_remote_debug_protocol/test/src/runners/ssh_command_runner_test.dart +++ b/packages/fuchsia_remote_debug_protocol/test/src/runners/ssh_command_runner_test.dart @@ -33,8 +33,8 @@ void main() { }); group('SshCommandRunner.run', () { - FakeProcessManager fakeProcessManager; - FakeProcessResult fakeProcessResult; + late FakeProcessManager fakeProcessManager; + late FakeProcessResult fakeProcessResult; SshCommandRunner runner; setUp(() { @@ -103,10 +103,10 @@ void main() { ); fakeProcessResult.stdout = 'somestuff'; await runner.run('ls /whatever'); - final List passedCommand = fakeProcessManager.runCommands.single as List; + final List passedCommand = fakeProcessManager.runCommands.single as List; expect(passedCommand, contains('-F')); final int indexOfFlag = passedCommand.indexOf('-F'); - final String passedConfig = passedCommand[indexOfFlag + 1]; + final String? passedConfig = passedCommand[indexOfFlag + 1]; expect(passedConfig, config); }); @@ -118,7 +118,7 @@ void main() { ); fakeProcessResult.stdout = 'somestuff'; await runner.run('ls /whatever'); - final List passedCommand = fakeProcessManager.runCommands.single as List; + final List passedCommand = fakeProcessManager.runCommands.single as List; final int indexOfFlag = passedCommand.indexOf('-F'); expect(indexOfFlag, equals(-1)); }); @@ -126,21 +126,21 @@ void main() { } class FakeProcessManager extends Fake implements ProcessManager { - FakeProcessResult fakeResult; + FakeProcessResult? fakeResult; List> runCommands = >[]; @override Future run(List command, { - String workingDirectory, - Map environment, + String? workingDirectory, + Map? environment, bool includeParentEnvironment = true, bool runInShell = false, Encoding stdoutEncoding = systemEncoding, Encoding stderrEncoding = systemEncoding, }) async { runCommands.add(command); - return fakeResult; + return fakeResult!; } }