[flutter_tools] consume package:process exceptions (#79657)

This commit is contained in:
Jonah Williams
2021-04-02 12:08:29 -07:00
committed by GitHub
parent d60cc08877
commit 304448af8c
3 changed files with 53 additions and 131 deletions

View File

@@ -684,25 +684,47 @@ void main() {
});
});
test('skipCommandLookup invokes Process calls directly', () async {
final ErrorHandlingProcessManager processManager = ErrorHandlingProcessManager(
delegate: const LocalProcessManager(),
platform: windowsPlatform,
);
// Throws process exception because the executable does not exist.
await ErrorHandlingProcessManager.skipCommandLookup<void>(() async {
expect(() => processManager.runSync(<String>['foo']), throwsA(isA<ProcessException>()));
expect(() => processManager.run(<String>['foo']), throwsA(isA<ProcessException>()));
expect(() => processManager.start(<String>['foo']), throwsA(isA<ProcessException>()));
});
});
group('ProcessManager on windows throws tool exit', () {
const int kDeviceFull = 112;
const int kUserMappedSectionOpened = 1224;
const int kUserPermissionDenied = 5;
test('when PackageProcess throws an exception containg non-executable bits', () {
final FakeProcessManager fakeProcessManager = FakeProcessManager.list(<FakeCommand>[
const FakeCommand(command: <String>['foo'], exception: ProcessPackageExecutableNotFoundException('', candidates: <String>['not-empty'])),
const FakeCommand(command: <String>['foo'], exception: ProcessPackageExecutableNotFoundException('', candidates: <String>['not-empty'])),
]);
final ProcessManager processManager = ErrorHandlingProcessManager(
delegate: fakeProcessManager,
platform: windowsPlatform,
);
const String expectedMessage = 'The Flutter tool could not locate an executable with suitable permissions';
expect(() async => processManager.start(<String>['foo']),
throwsToolExit(message: expectedMessage));
expect(() async => processManager.runSync(<String>['foo']),
throwsToolExit(message: expectedMessage));
});
test('when PackageProcess throws an exception without containing non-executable bits', () {
final FakeProcessManager fakeProcessManager = FakeProcessManager.list(<FakeCommand>[
const FakeCommand(command: <String>['foo'], exception: ProcessPackageExecutableNotFoundException('', candidates: <String>[])),
const FakeCommand(command: <String>['foo'], exception: ProcessPackageExecutableNotFoundException('', candidates: <String>[])),
]);
final ProcessManager processManager = ErrorHandlingProcessManager(
delegate: fakeProcessManager,
platform: windowsPlatform,
);
// If there were no located executables treat this as a programming error and rethrow the original
// exception.
expect(() async => processManager.start(<String>['foo']), throwsProcessException());
expect(() async => processManager.runSync(<String>['foo']), throwsProcessException());
});
test('when the device is full', () {
final FakeProcessManager fakeProcessManager = FakeProcessManager.list(<FakeCommand>[
const FakeCommand(command: <String>['foo'], exception: ProcessException('', <String>[], '', kDeviceFull)),