anchor.diff:               throwsToolExit(message: expectedMessage));
       });
   
  -    testWithoutContext('When reading from a file or directory without permission', () {
  -      setupReadMocks(
  -        mockFileSystem: mockFileSystem,
  -        fs: fs,
  -        errorCode: kUserPermissionDenied,
  -      );
  -
  -      final File file = fs.file('file');
  +    testWithoutContext('When reading from a file without permission', () {
  +       final ErrorHandlingFileSystem fileSystem = ErrorHandlingFileSystem(
  +        delegate: MemoryFileSystem.test(opHandle: exceptionHandler.opHandle),
  +        platform: windowsPlatform,
  +      );
  +      final File file = fileSystem.file('file');
  +
  +      exceptionHandler.addError(
  +        file,
  +        FileSystemOp.read,
  +        FileSystemException('', file.path, const OSError('', kUserPermissionDenied)),
  +      );
   
         const String expectedMessage = 'Flutter failed to read a file at';
         expect(() => file.readAsStringSync(),
                throwsToolExit(message: expectedMessage));
  -      expect(() => fs.currentDirectory,
  +    });
  +
  +    testWithoutContext('When reading from a file or directory without permission', () {
  +       final ErrorHandlingFileSystem fileSystem = ErrorHandlingFileSystem(
  +        delegate: ThrowsOnCurrentDirectoryFileSystem()..errorCode = kUserPermissionDenied,
  +        platform: windowsPlatform,
  +      );
  +
  +      expect(() => fileSystem.currentDirectory,
                throwsToolExit(message: 'The flutter tool cannot access the file or directory'));
       });
     });
  
positive.code:   operatingSystem: 'macos',
    environment: <String, String>{}
  );
  
  void setupReadMocks({
    FileSystem mockFileSystem,
    ErrorHandlingFileSystem fs,
    int errorCode,
  }) {
    final MockFile mockFile = MockFile();
    final MockDirectory mockParentDirectory = MockDirectory();
    when(mockFileSystem.file(any)).thenReturn(mockFile);
    when(mockFile.path).thenReturn('parent/file');
    when(mockFile.parent).thenReturn(mockParentDirectory);
    when(mockParentDirectory.path).thenReturn('parent');
    when(mockFileSystem.currentDirectory).thenThrow(FileSystemException('', '', OSError('', errorCode)));
    when(mockFile.readAsStringSync(
      encoding: anyNamed('encoding'),
    )).thenThrow(FileSystemException('', '', OSError('', errorCode)));
  }
  
  void setupDirectoryMocks({
    FileSystem mockFileSystem,
  
negative.code:     throw _exception;
    }
  }
  
  class ThrowsOnCurrentDirectoryFileSystem extends Fake implements FileSystem {
    int errorCode;
  
    @override
    Directory get currentDirectory => throw FileSystemException('', '', OSError('', errorCode));
  }
  