Unverified Commit 5e614667 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Adopt FileExceptionHandler in a few tests (#76279)

parent 90531179
...@@ -116,24 +116,32 @@ void main() { ...@@ -116,24 +116,32 @@ void main() {
group('Windows', () { group('Windows', () {
FakePlatform windowsPlatform; FakePlatform windowsPlatform;
MemoryFileSystem fileSystem;
FileExceptionHandler exceptionHandler;
setUp(() { setUp(() {
windowsPlatform = FakePlatform(operatingSystem: 'windows'); windowsPlatform = FakePlatform(operatingSystem: 'windows');
exceptionHandler = FileExceptionHandler();
fileSystem = MemoryFileSystem.test(opHandle: exceptionHandler.opHandle);
}); });
testUsingContext('$CleanCommand prints a helpful error message on Windows', () async { testUsingContext('$CleanCommand prints a helpful error message on Windows', () async {
when(mockXcodeProjectInterpreter.isInstalled).thenReturn(false); when(mockXcodeProjectInterpreter.isInstalled).thenReturn(false);
final MockFile mockFile = MockFile(); final File file = fileSystem.file('file')..createSync();
when(mockFile.existsSync()).thenReturn(true); exceptionHandler.addError(
file,
FileSystemOp.delete,
const FileSystemException('Deletion failed'),
);
when(mockFile.deleteSync(recursive: true)).thenThrow(const FileSystemException('Deletion failed'));
final CleanCommand command = CleanCommand(); final CleanCommand command = CleanCommand();
command.deleteFile(mockFile); command.deleteFile(file);
expect(testLogger.errorText, contains('A program may still be using a file')); expect(testLogger.errorText, contains('A program may still be using a file'));
verify(mockFile.deleteSync(recursive: true)).called(1);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Platform: () => windowsPlatform, Platform: () => windowsPlatform,
Xcode: () => xcode, Xcode: () => xcode,
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
}); });
testUsingContext('$CleanCommand handles missing permissions;', () async { testUsingContext('$CleanCommand handles missing permissions;', () async {
......
...@@ -665,7 +665,8 @@ void main() { ...@@ -665,7 +665,8 @@ void main() {
}); });
testWithoutContext('Cache handles exception thrown if stamp file cannot be parsed', () { 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 Logger logger = BufferLogger.test();
final FakeCache cache = FakeCache( final FakeCache cache = FakeCache(
fileSystem: fileSystem, fileSystem: fileSystem,
...@@ -673,19 +674,33 @@ void main() { ...@@ -673,19 +674,33 @@ void main() {
platform: FakePlatform(), platform: FakePlatform(),
osUtils: MockOperatingSystemUtils() osUtils: MockOperatingSystemUtils()
); );
final MockFile file = MockFile(); final File file = fileSystem.file('stamp');
cache.stampFile = file; cache.stampFile = file;
when(file.existsSync()).thenReturn(false);
expect(cache.getStampFor('foo'), null); expect(cache.getStampFor('foo'), null);
when(file.existsSync()).thenReturn(true); file.createSync();
when(file.readAsStringSync()).thenThrow(const FileSystemException()); exceptionHandler.addError(
file,
FileSystemOp.read,
const FileSystemException(),
);
expect(cache.getStampFor('foo'), null); expect(cache.getStampFor('foo'), null);
});
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()
);
when(file.existsSync()).thenReturn(true); final File file = fileSystem.file('stamp')..writeAsStringSync('ABC ');
when(file.readAsStringSync()).thenReturn('ABC '); cache.stampFile = file;
expect(cache.getStampFor('foo'), 'ABC'); expect(cache.getStampFor('foo'), 'ABC');
}); });
...@@ -860,7 +875,6 @@ class FakeDownloadedArtifact extends CachedArtifact { ...@@ -860,7 +875,6 @@ class FakeDownloadedArtifact extends CachedArtifact {
} }
class MockArtifactUpdater extends Mock implements ArtifactUpdater {} class MockArtifactUpdater extends Mock implements ArtifactUpdater {}
class MockFile extends Mock implements File {}
class MockCachedArtifact extends Mock implements CachedArtifact {} class MockCachedArtifact extends Mock implements CachedArtifact {}
class MockIosUsbArtifacts extends Mock implements IosUsbArtifacts {} class MockIosUsbArtifacts extends Mock implements IosUsbArtifacts {}
class MockInternetAddress extends Mock implements InternetAddress {} class MockInternetAddress extends Mock implements InternetAddress {}
...@@ -868,6 +882,7 @@ class MockCache extends Mock implements Cache {} ...@@ -868,6 +882,7 @@ class MockCache extends Mock implements Cache {}
class MockOperatingSystemUtils extends Mock implements OperatingSystemUtils {} class MockOperatingSystemUtils extends Mock implements OperatingSystemUtils {}
class MockVersionedPackageResolver extends Mock implements VersionedPackageResolver {} class MockVersionedPackageResolver extends Mock implements VersionedPackageResolver {}
class MockPub extends Mock implements Pub {} class MockPub extends Mock implements Pub {}
class FakeCache extends Cache { class FakeCache extends Cache {
FakeCache({ FakeCache({
@required Logger logger, @required Logger logger,
......
...@@ -356,7 +356,6 @@ void main() { ...@@ -356,7 +356,6 @@ void main() {
}); });
} }
class MockFileSystemUtils extends Mock implements FileSystemUtils {}
class MockOperatingSystemUtils extends Mock implements OperatingSystemUtils {} class MockOperatingSystemUtils extends Mock implements OperatingSystemUtils {}
Future<Chromium> _testLaunchChrome(String userDataDir, FakeProcessManager processManager, ChromiumLauncher chromeLauncher) { Future<Chromium> _testLaunchChrome(String userDataDir, FakeProcessManager processManager, ChromiumLauncher chromeLauncher) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment