explicitly catch ArgumentError, and add tests (#52757)

This commit is contained in:
Christopher Fujino
2020-03-17 12:55:57 -07:00
committed by GitHub
parent a4d30c1607
commit 071d4eb2c8
2 changed files with 34 additions and 0 deletions

View File

@@ -542,6 +542,9 @@ class _DefaultProcessUtils implements ProcessUtils {
} on Exception catch (error) {
_logger.printTrace('$cli failed with $error');
return false;
} on ArgumentError catch (error) {
_logger.printTrace('$cli failed with $error');
return false;
}
}
@@ -556,6 +559,9 @@ class _DefaultProcessUtils implements ProcessUtils {
} on Exception catch (error) {
_logger.printTrace('$cli failed with $error');
return false;
} on ArgumentError catch (error) {
_logger.printTrace('$cli failed with $error');
return false;
}
}

View File

@@ -360,6 +360,20 @@ void main() {
);
expect(processUtils.exitsHappySync(<String>['boohoo']), isFalse);
});
testWithoutContext('catches Exception and returns false', () {
when(mockProcessManager.runSync(<String>['boohoo'])).thenThrow(
const ProcessException('Process failed', <String>[]),
);
expect(processUtils.exitsHappySync(<String>['boohoo']), isFalse);
});
testWithoutContext('catches ArgumentError and returns false', () {
when(mockProcessManager.runSync(<String>['nonesuch'])).thenThrow(
ArgumentError('Invalid argument(s): Cannot find executable for nonesuch')
);
expect(processUtils.exitsHappySync(<String>['nonesuch']), isFalse);
});
});
group('exitsHappy', () {
@@ -387,6 +401,20 @@ void main() {
});
expect(await processUtils.exitsHappy(<String>['boohoo']), isFalse);
});
testWithoutContext('catches Exception and returns false', () async {
when(mockProcessManager.run(<String>['boohoo'])).thenThrow(
const ProcessException('Process failed', <String>[]),
);
expect(await processUtils.exitsHappy(<String>['boohoo']), isFalse);
});
testWithoutContext('catches ArgumentError and returns false', () async {
when(mockProcessManager.run(<String>['nonesuch'])).thenThrow(
ArgumentError('Invalid argument(s): Cannot find executable for nonesuch'),
);
expect(await processUtils.exitsHappy(<String>['nonesuch']), isFalse);
});
});
}