Adopt FileExceptionHandler in a few tests (#76279)

This commit is contained in:
Jenn Magder 2021-02-17 23:41:04 -08:00 committed by GitHub
parent 90531179f5
commit 5e61466794
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 14 deletions

View file

@ -116,24 +116,32 @@ void main() {
group('Windows', () {
FakePlatform windowsPlatform;
MemoryFileSystem fileSystem;
FileExceptionHandler exceptionHandler;
setUp(() {
windowsPlatform = FakePlatform(operatingSystem: 'windows');
exceptionHandler = FileExceptionHandler();
fileSystem = MemoryFileSystem.test(opHandle: exceptionHandler.opHandle);
});
testUsingContext('$CleanCommand prints a helpful error message on Windows', () async {
when(mockXcodeProjectInterpreter.isInstalled).thenReturn(false);
final MockFile mockFile = MockFile();
when(mockFile.existsSync()).thenReturn(true);
final File file = fileSystem.file('file')..createSync();
exceptionHandler.addError(
file,
FileSystemOp.delete,
const FileSystemException('Deletion failed'),
);
when(mockFile.deleteSync(recursive: true)).thenThrow(const FileSystemException('Deletion failed'));
final CleanCommand command = CleanCommand();
command.deleteFile(mockFile);
command.deleteFile(file);
expect(testLogger.errorText, contains('A program may still be using a file'));
verify(mockFile.deleteSync(recursive: true)).called(1);
}, overrides: <Type, Generator>{
Platform: () => windowsPlatform,
Xcode: () => xcode,
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('$CleanCommand handles missing permissions;', () async {

View file

@ -665,7 +665,8 @@ void main() {
});
testWithoutContext('Cache handles exception thrown if stamp file cannot be parsed', () {
final FileSystem fileSystem = MemoryFileSystem.test();
final FileExceptionHandler exceptionHandler = FileExceptionHandler();
final FileSystem fileSystem = MemoryFileSystem.test(opHandle: exceptionHandler.opHandle);
final Logger logger = BufferLogger.test();
final FakeCache cache = FakeCache(
fileSystem: fileSystem,
@ -673,19 +674,33 @@ void main() {
platform: FakePlatform(),
osUtils: MockOperatingSystemUtils()
);
final MockFile file = MockFile();
final File file = fileSystem.file('stamp');
cache.stampFile = file;
when(file.existsSync()).thenReturn(false);
expect(cache.getStampFor('foo'), null);
when(file.existsSync()).thenReturn(true);
when(file.readAsStringSync()).thenThrow(const FileSystemException());
file.createSync();
exceptionHandler.addError(
file,
FileSystemOp.read,
const FileSystemException(),
);
expect(cache.getStampFor('foo'), null);
});
when(file.existsSync()).thenReturn(true);
when(file.readAsStringSync()).thenReturn('ABC ');
testWithoutContext('Cache parses stamp file', () {
final FileSystem fileSystem = MemoryFileSystem.test();
final Logger logger = BufferLogger.test();
final FakeCache cache = FakeCache(
fileSystem: fileSystem,
logger: logger,
platform: FakePlatform(),
osUtils: MockOperatingSystemUtils()
);
final File file = fileSystem.file('stamp')..writeAsStringSync('ABC ');
cache.stampFile = file;
expect(cache.getStampFor('foo'), 'ABC');
});
@ -860,7 +875,6 @@ class FakeDownloadedArtifact extends CachedArtifact {
}
class MockArtifactUpdater extends Mock implements ArtifactUpdater {}
class MockFile extends Mock implements File {}
class MockCachedArtifact extends Mock implements CachedArtifact {}
class MockIosUsbArtifacts extends Mock implements IosUsbArtifacts {}
class MockInternetAddress extends Mock implements InternetAddress {}
@ -868,6 +882,7 @@ class MockCache extends Mock implements Cache {}
class MockOperatingSystemUtils extends Mock implements OperatingSystemUtils {}
class MockVersionedPackageResolver extends Mock implements VersionedPackageResolver {}
class MockPub extends Mock implements Pub {}
class FakeCache extends Cache {
FakeCache({
@required Logger logger,

View file

@ -356,7 +356,6 @@ void main() {
});
}
class MockFileSystemUtils extends Mock implements FileSystemUtils {}
class MockOperatingSystemUtils extends Mock implements OperatingSystemUtils {}
Future<Chromium> _testLaunchChrome(String userDataDir, FakeProcessManager processManager, ChromiumLauncher chromeLauncher) {