Unverified Commit a9aea962 authored by Zachary Anderson's avatar Zachary Anderson Committed by GitHub

[flutter_tool] Catch ProcessException from 'adb devices' (#37196)

parent 99d66f27
...@@ -678,8 +678,11 @@ List<AndroidDevice> getAdbDevices() { ...@@ -678,8 +678,11 @@ List<AndroidDevice> getAdbDevices() {
try { try {
text = runSync(<String>[adbPath, 'devices', '-l']); text = runSync(<String>[adbPath, 'devices', '-l']);
} on ArgumentError catch (exception) { } on ArgumentError catch (exception) {
throwToolExit('Unable to run "adb", check your Android SDK installation and ' throwToolExit('Unable to find "adb", check your Android SDK installation and '
'ANDROID_HOME environment variable: ${exception.message}'); 'ANDROID_HOME environment variable: ${exception.message}');
} on ProcessException catch (exception) {
throwToolExit('Unable to run "adb", check your Android SDK installation and '
'ANDROID_HOME environment variable: ${exception.executable}');
} }
final List<AndroidDevice> devices = <AndroidDevice>[]; final List<AndroidDevice> devices = <AndroidDevice>[];
parseADBDeviceOutput(text, devices: devices); parseADBDeviceOutput(text, devices: devices);
......
...@@ -34,7 +34,12 @@ void main() { ...@@ -34,7 +34,12 @@ void main() {
}); });
group('getAdbDevices', () { group('getAdbDevices', () {
final MockProcessManager mockProcessManager = MockProcessManager(); MockProcessManager mockProcessManager;
setUp(() {
mockProcessManager = MockProcessManager();
});
testUsingContext('throws on missing adb path', () { testUsingContext('throws on missing adb path', () {
final Directory sdkDir = MockAndroidSdk.createSdkDirectory(); final Directory sdkDir = MockAndroidSdk.createSdkDirectory();
Config.instance.setValue('android-sdk', sdkDir.path); Config.instance.setValue('android-sdk', sdkDir.path);
...@@ -42,10 +47,22 @@ void main() { ...@@ -42,10 +47,22 @@ void main() {
final File adbExe = fs.file(getAdbPath(androidSdk)); final File adbExe = fs.file(getAdbPath(androidSdk));
when(mockProcessManager.runSync( when(mockProcessManager.runSync(
<String>[adbExe.path, 'devices', '-l'], <String>[adbExe.path, 'devices', '-l'],
)) )).thenThrow(ArgumentError(adbExe.path));
.thenAnswer( expect(() => getAdbDevices(), throwsToolExit(message: RegExp('Unable to find "adb".*${adbExe.path}')));
(_) => throw ArgumentError(adbExe.path), }, overrides: <Type, Generator>{
); AndroidSdk: () => MockAndroidSdk(),
FileSystem: () => MemoryFileSystem(),
ProcessManager: () => mockProcessManager,
});
testUsingContext('throws on failing adb', () {
final Directory sdkDir = MockAndroidSdk.createSdkDirectory();
Config.instance.setValue('android-sdk', sdkDir.path);
final File adbExe = fs.file(getAdbPath(androidSdk));
when(mockProcessManager.runSync(
<String>[adbExe.path, 'devices', '-l'],
)).thenThrow(ProcessException(adbExe.path, <String>['devices', '-l']));
expect(() => getAdbDevices(), throwsToolExit(message: RegExp('Unable to run "adb".*${adbExe.path}'))); expect(() => getAdbDevices(), throwsToolExit(message: RegExp('Unable to run "adb".*${adbExe.path}')));
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
AndroidSdk: () => MockAndroidSdk(), AndroidSdk: () => MockAndroidSdk(),
......
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