@@ -93,6 +93,8 @@ void setupDirectoryMocks({
93
93
.thenThrow (FileSystemException ('' , '' , OSError ('' , errorCode)));
94
94
when (mockDirectory.deleteSync ())
95
95
.thenThrow (FileSystemException ('' , '' , OSError ('' , errorCode)));
96
+ when (mockDirectory.existsSync ())
97
+ .thenThrow (FileSystemException ('' , '' , OSError ('' , errorCode)));
96
98
}
97
99
98
100
void main () {
@@ -203,6 +205,20 @@ void main() {
203
205
expect (() => directory.createSync (recursive: true ),
204
206
throwsToolExit (message: expectedMessage));
205
207
});
208
+
209
+ testWithoutContext ('when checking for directory existence with permission issues' , () async {
210
+ setupDirectoryMocks (
211
+ mockFileSystem: mockFileSystem,
212
+ fs: fs,
213
+ errorCode: kUserPermissionDenied,
214
+ );
215
+
216
+ final Directory directory = fs.directory ('directory' );
217
+
218
+ const String expectedMessage = 'Flutter failed to check for directory existence at' ;
219
+ expect (() => directory.existsSync (),
220
+ throwsToolExit (message: expectedMessage));
221
+ });
206
222
});
207
223
208
224
group ('throws ToolExit on Linux' , () {
@@ -298,6 +314,20 @@ void main() {
298
314
expect (() => directory.createTempSync ('prefix' ),
299
315
throwsToolExit (message: expectedMessage));
300
316
});
317
+
318
+ testWithoutContext ('when checking for directory existence with permission issues' , () async {
319
+ setupDirectoryMocks (
320
+ mockFileSystem: mockFileSystem,
321
+ fs: fs,
322
+ errorCode: eacces,
323
+ );
324
+
325
+ final Directory directory = fs.directory ('directory' );
326
+
327
+ const String expectedMessage = 'Flutter failed to check for directory existence at' ;
328
+ expect (() => directory.existsSync (),
329
+ throwsToolExit (message: expectedMessage));
330
+ });
301
331
});
302
332
303
333
group ('throws ToolExit on macOS' , () {
@@ -393,6 +423,20 @@ void main() {
393
423
expect (() => directory.createTempSync ('prefix' ),
394
424
throwsToolExit (message: expectedMessage));
395
425
});
426
+
427
+ testWithoutContext ('when checking for directory existence with permission issues' , () async {
428
+ setupDirectoryMocks (
429
+ mockFileSystem: mockFileSystem,
430
+ fs: fs,
431
+ errorCode: eacces,
432
+ );
433
+
434
+ final Directory directory = fs.directory ('directory' );
435
+
436
+ const String expectedMessage = 'Flutter failed to check for directory existence at' ;
437
+ expect (() => directory.existsSync (),
438
+ throwsToolExit (message: expectedMessage));
439
+ });
396
440
});
397
441
398
442
testWithoutContext ('Caches path context correctly' , () {
0 commit comments