[flutter_tools] catch errors when getting cwd (#74744)

This commit is contained in:
Jonah Williams
2021-01-26 12:49:03 -08:00
committed by GitHub
parent 384b4d1b83
commit fa8bf67cb6
2 changed files with 11 additions and 4 deletions

View File

@@ -87,6 +87,7 @@ void setupReadMocks({
}) {
final MockFile mockFile = MockFile();
when(mockFileSystem.file(any)).thenReturn(mockFile);
when(mockFileSystem.currentDirectory).thenThrow(FileSystemException('', '', OSError('', errorCode)));
when(mockFile.readAsStringSync(
encoding: anyNamed('encoding'),
)).thenThrow(FileSystemException('', '', OSError('', errorCode)));
@@ -345,7 +346,7 @@ void main() {
throwsToolExit(message: expectedMessage));
});
testWithoutContext('When reading from a file without permission', () {
testWithoutContext('When reading from a file or directory without permission', () {
setupReadMocks(
mockFileSystem: mockFileSystem,
fs: fs,
@@ -357,6 +358,8 @@ void main() {
const String expectedMessage = 'Flutter failed to read a file at';
expect(() => file.readAsStringSync(),
throwsToolExit(message: expectedMessage));
expect(() => fs.currentDirectory,
throwsToolExit(message: 'The flutter tool cannot access the file or directory'));
});
});
@@ -579,7 +582,7 @@ void main() {
throwsToolExit(message: expectedMessage));
});
testWithoutContext('When reading from a file without permission', () {
testWithoutContext('When reading from a file or directory without permission', () {
setupReadMocks(
mockFileSystem: mockFileSystem,
fs: fs,
@@ -591,6 +594,8 @@ void main() {
const String expectedMessage = 'Flutter failed to read a file at';
expect(() => file.readAsStringSync(),
throwsToolExit(message: expectedMessage));
expect(() => fs.currentDirectory,
throwsToolExit(message: 'The flutter tool cannot access the file or directory'));
});
});