anchor.diff:      });
   
       testWithoutContext('when writing to a full device', () async {
  -      setupWriteMocks(
  -        mockFileSystem: mockFileSystem,
  -        fs: fs,
  -        errorCode: enospc,
  -      );
  -
  -      final File file = fs.file('file');
  +      final ErrorHandlingFileSystem fileSystem = ErrorHandlingFileSystem(
  +        delegate: MemoryFileSystem.test(opHandle: exceptionHandler.opHandle),
  +        platform: macOSPlatform,
  +      );
  +      final File file = fileSystem.file('file');
  +
  +      exceptionHandler.addError(
  +        file,
  +        FileSystemOp.write,
  +        FileSystemException('', file.path, const OSError('', enospc)),
  +      );
   
         const String expectedMessage = 'The target device is full';
         expect(() async => file.writeAsBytes(<int>[0]),
  
positive.code: 
      // dart:io is able to clobber read-only files.
      testWithoutContext('copySync will copySync even if the destination is not writable', () {
        final MockFile source = MockFile();
        when(source.path).thenReturn('source');
        final MockDirectory parent = MockDirectory();
        when(parent.path).thenReturn('destParent');
        final MockFile dest = MockFile();
        when(dest.parent).thenReturn(parent);
  
        when(source.copySync(any)).thenReturn(dest);
        when(mockFileSystem.file('source')).thenReturn(source);
        when(source.openSync(mode: anyNamed('mode')))
          .thenReturn(MockRandomAccessFile());
        when(mockFileSystem.file('dest')).thenReturn(dest);
        when(dest.openSync(mode: FileMode.writeOnly))
          .thenThrow(const FileSystemException('', '', OSError('', eaccess)));
  
        fileSystem.file('source').copySync('dest');
  
        verify(source.copySync('dest')).called(1);
      });
  
      testWithoutContext('copySync will copySync if there are no exceptions', () {
        final MockFile source = MockFile();
        when(source.path).thenReturn('source');
        final MockDirectory parent = MockDirectory();
        when(parent.path).thenReturn('destParent');
        final MockFile dest = MockFile();
        when(dest.parent).thenReturn(parent);
  
        when(source.copySync(any)).thenReturn(dest);
        when(mockFileSystem.file('source')).thenReturn(source);
        when(source.openSync(mode: anyNamed('mode')))
          .thenReturn(MockRandomAccessFile());
        when(mockFileSystem.file('dest')).thenReturn(dest);
        when(dest.openSync(mode: anyNamed('mode')))
          .thenReturn(MockRandomAccessFile());
  
        fileSystem.file('source').copySync('dest');
  
        verify(source.copySync('dest')).called(1);
      });
  
      testWithoutContext('copySync can directly copy bytes if both files can be opened but copySync fails', () {
        final MemoryFileSystem memoryFileSystem = MemoryFileSystem.test();
        final MockFile source = MockFile();
        when(source.path).thenReturn('source');
        final MockDirectory parent = MockDirectory();
        when(parent.path).thenReturn('destParent');
        final MockFile dest = MockFile();
        when(dest.parent).thenReturn(parent);
        final List<int> expectedBytes = List<int>.generate(64 * 1024 + 3, (int i) => i.isEven ? 0 : 1);
        final File memorySource = memoryFileSystem.file('source')
          ..writeAsBytesSync(expectedBytes);
        final File memoryDest = memoryFileSystem.file('dest')
          ..createSync();
  
        when(source.copySync(any))
          .thenThrow(const FileSystemException('', '', OSError('', eaccess)));
        when(source.openSync(mode: anyNamed('mode')))
          .thenAnswer((Invocation invocation) => memorySource.openSync(mode: invocation.namedArguments[#mode] as FileMode));
        when(dest.openSync(mode: anyNamed('mode')))
          .thenAnswer((Invocation invocation) => memoryDest.openSync(mode: invocation.namedArguments[#mode] as FileMode));
        when(mockFileSystem.file('source')).thenReturn(source);
        when(mockFileSystem.file('dest')).thenReturn(dest);
  
        fileSystem.file('source').copySync('dest');
  
        expect(memoryDest.readAsBytesSync(), expectedBytes);
      });
  
      testWithoutContext('copySync deletes the result file if the fallback fails', () {
        final MemoryFileSystem memoryFileSystem = MemoryFileSystem.test();
        final MockFile source = MockFile();
        when(source.path).thenReturn('source');
  
negative.code: class MockFile extends Mock implements File {}
  class MockFileSystem extends Mock implements FileSystem {}
  class MockDirectory extends Mock implements Directory {}
  
  final Platform windowsPlatform = FakePlatform(
    operatingSystem: 'windows',
  