mirror of
https://github.com/flutter/flutter
synced 2024-09-19 08:11:56 +00:00
flutter attach should handle non-singular device gracefully (#19036)
This commit is contained in:
parent
0329f0c179
commit
b1c6224590
|
@ -71,6 +71,8 @@ class AttachCommand extends FlutterCommand {
|
|||
await _validateArguments();
|
||||
|
||||
final Device device = await findTargetDevice();
|
||||
if (device == null)
|
||||
throwToolExit(null);
|
||||
final int devicePort = observatoryPort;
|
||||
Uri observatoryUri;
|
||||
if (devicePort == null) {
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_tools/src/base/common.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/commands/attach.dart';
|
||||
import 'package:flutter_tools/src/device.dart';
|
||||
|
@ -68,6 +69,37 @@ void main() {
|
|||
|
||||
verify(portForwarder.forward(devicePort)).called(1);
|
||||
});
|
||||
|
||||
testUsingContext('exits when no device connected', () async {
|
||||
final AttachCommand command = new AttachCommand();
|
||||
await expectLater(
|
||||
createTestCommandRunner(command).run(<String>['attach']),
|
||||
throwsA(const isInstanceOf<ToolExit>()),
|
||||
);
|
||||
expect(testLogger.statusText, contains('No connected devices'));
|
||||
});
|
||||
|
||||
testUsingContext('exits when multiple devices connected', () async {
|
||||
Device aDeviceWithId(String id) {
|
||||
final MockAndroidDevice device = new MockAndroidDevice();
|
||||
when(device.name).thenReturn('d$id');
|
||||
when(device.id).thenReturn(id);
|
||||
when(device.isLocalEmulator).thenAnswer((_) async => false);
|
||||
when(device.sdkNameAndVersion).thenAnswer((_) async => 'Android 46');
|
||||
return device;
|
||||
}
|
||||
|
||||
final AttachCommand command = new AttachCommand();
|
||||
testDeviceManager.addDevice(aDeviceWithId('xx1'));
|
||||
testDeviceManager.addDevice(aDeviceWithId('yy2'));
|
||||
await expectLater(
|
||||
createTestCommandRunner(command).run(<String>['attach']),
|
||||
throwsA(const isInstanceOf<ToolExit>()),
|
||||
);
|
||||
expect(testLogger.statusText, contains('More than one device'));
|
||||
expect(testLogger.statusText, contains('xx1'));
|
||||
expect(testLogger.statusText, contains('yy2'));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue