[flutter_tools] handle missing zip/unzip argument errors (#66685)

it is possible for users that download the prebuilt SDKs to run the tool without unzip installed. Rather than crashing with an unclear argument error, exit the tool with a message on how to install that mirrors the message in the update_dart_sdk.sh script.

Also applied to zip for completeness
This commit is contained in:
Jonah Williams
2020-09-29 07:58:09 -07:00
committed by GitHub
parent 5872b70b8c
commit 6f20c8a83f
2 changed files with 138 additions and 10 deletions

View File

@@ -143,6 +143,105 @@ void main() {
);
});
testWithoutContext('If unzip throws an ArgumentError, display an install message', () {
final FileSystem fileSystem = MemoryFileSystem.test();
when(mockProcessManager.runSync(
<String>['unzip', '-o', '-q', 'foo.zip', '-d', fileSystem.currentDirectory.path],
)).thenThrow(ArgumentError());
final OperatingSystemUtils linuxOsUtils = OperatingSystemUtils(
fileSystem: fileSystem,
logger: BufferLogger.test(),
platform: FakePlatform(operatingSystem: 'linux'),
processManager: mockProcessManager,
);
expect(
() => linuxOsUtils.unzip(fileSystem.file('foo.zip'), fileSystem.currentDirectory),
throwsToolExit(
message: 'Missing "unzip" tool. Unable to extract foo.zip.\n'
'Consider running "sudo apt-get install unzip".'),
);
final OperatingSystemUtils macOSUtils = OperatingSystemUtils(
fileSystem: fileSystem,
logger: BufferLogger.test(),
platform: FakePlatform(operatingSystem: 'macos'),
processManager: mockProcessManager,
);
expect(
() => macOSUtils.unzip(fileSystem.file('foo.zip'), fileSystem.currentDirectory),
throwsToolExit
(message: 'Missing "unzip" tool. Unable to extract foo.zip.\n'
'Consider running "brew install unzip".'),
);
final OperatingSystemUtils unknownOsUtils = OperatingSystemUtils(
fileSystem: fileSystem,
logger: BufferLogger.test(),
platform: FakePlatform(operatingSystem: 'fuchsia'),
processManager: mockProcessManager,
);
expect(
() => unknownOsUtils.unzip(fileSystem.file('foo.zip'), fileSystem.currentDirectory),
throwsToolExit
(message: 'Missing "unzip" tool. Unable to extract foo.zip.\n'
'Please install unzip.'),
);
});
testWithoutContext('If zip throws an ArgumentError, display an install message', () {
final FileSystem fileSystem = MemoryFileSystem.test();
when(mockProcessManager.runSync(
<String>['zip', '-r', '-q', 'foo.zip', '.'],
workingDirectory: anyNamed('workingDirectory'),
)).thenThrow(ArgumentError());
final OperatingSystemUtils linuxOsUtils = OperatingSystemUtils(
fileSystem: fileSystem,
logger: BufferLogger.test(),
platform: FakePlatform(operatingSystem: 'linux'),
processManager: mockProcessManager,
);
expect(
() => linuxOsUtils.zip(fileSystem.currentDirectory, fileSystem.file('foo.zip')),
throwsToolExit(
message: 'Missing "zip" tool. Unable to compress /.\n'
'Consider running "sudo apt-get install zip".'),
);
final OperatingSystemUtils macOSUtils = OperatingSystemUtils(
fileSystem: fileSystem,
logger: BufferLogger.test(),
platform: FakePlatform(operatingSystem: 'macos'),
processManager: mockProcessManager,
);
expect(
() => macOSUtils.zip(fileSystem.currentDirectory, fileSystem.file('foo.zip')),
throwsToolExit
(message: 'Missing "zip" tool. Unable to compress /.\n'
'Consider running "brew install zip".'),
);
final OperatingSystemUtils unknownOsUtils = OperatingSystemUtils(
fileSystem: fileSystem,
logger: BufferLogger.test(),
platform: FakePlatform(operatingSystem: 'fuchsia'),
processManager: mockProcessManager,
);
expect(
() => unknownOsUtils.zip(fileSystem.currentDirectory, fileSystem.file('foo.zip')),
throwsToolExit
(message: 'Missing "zip" tool. Unable to compress /.\n'
'Please install zip.'),
);
});
testWithoutContext('stream compression level', () {
expect(OperatingSystemUtils.gzipLevel1.level, equals(1));
});