mirror of
https://github.com/flutter/flutter
synced 2024-10-13 03:32:55 +00:00
Adopt FileExceptionHandler in a few tests (#76279)
This commit is contained in:
parent
90531179f5
commit
5e61466794
|
@ -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 {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue