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() {
try {
text = runSync(<String>[adbPath, 'devices', '-l']);
} 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}');
} 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>[];
parseADBDeviceOutput(text, devices: devices);
......
......@@ -34,7 +34,12 @@ void main() {
});
group('getAdbDevices', () {
final MockProcessManager mockProcessManager = MockProcessManager();
MockProcessManager mockProcessManager;
setUp(() {
mockProcessManager = MockProcessManager();
});
testUsingContext('throws on missing adb path', () {
final Directory sdkDir = MockAndroidSdk.createSdkDirectory();
Config.instance.setValue('android-sdk', sdkDir.path);
......@@ -42,10 +47,22 @@ void main() {
final File adbExe = fs.file(getAdbPath(androidSdk));
when(mockProcessManager.runSync(
<String>[adbExe.path, 'devices', '-l'],
))
.thenAnswer(
(_) => throw ArgumentError(adbExe.path),
);
)).thenThrow(ArgumentError(adbExe.path));
expect(() => getAdbDevices(), throwsToolExit(message: RegExp('Unable to find "adb".*${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}')));
}, overrides: <Type, Generator>{
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