Unverified Commit 24883e1c authored by Dan Field's avatar Dan Field Committed by GitHub

Add overrides for FileSystemUtils (#52080)

parent fc3f0388
...@@ -39,10 +39,14 @@ class MockPlistUtils extends Mock implements PlistParser {} ...@@ -39,10 +39,14 @@ class MockPlistUtils extends Mock implements PlistParser {}
void main() { void main() {
FakePlatform osx; FakePlatform osx;
FileSystemUtils fsUtils;
MemoryFileSystem fileSystem;
setUp(() { setUp(() {
osx = FakePlatform.fromPlatform(const LocalPlatform()); osx = FakePlatform.fromPlatform(const LocalPlatform());
osx.operatingSystem = 'macos'; osx.operatingSystem = 'macos';
fileSystem = MemoryFileSystem();
fsUtils = FileSystemUtils(fileSystem: fileSystem, platform: osx);
}); });
group('_IOSSimulatorDevicePortForwarder', () { group('_IOSSimulatorDevicePortForwarder', () {
...@@ -60,6 +64,8 @@ void main() { ...@@ -60,6 +64,8 @@ void main() {
expect(portForwarder.forwardedPorts.length, 0); expect(portForwarder.forwardedPorts.length, 0);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Platform: () => osx, Platform: () => osx,
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
}, testOn: 'posix'); }, testOn: 'posix');
}); });
...@@ -69,6 +75,9 @@ void main() { ...@@ -69,6 +75,9 @@ void main() {
expect(IOSSimulator('123').logFilePath, '/foo/bar/Library/Logs/CoreSimulator/123/system.log'); expect(IOSSimulator('123').logFilePath, '/foo/bar/Library/Logs/CoreSimulator/123/system.log');
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Platform: () => osx, Platform: () => osx,
FileSystemUtils: () => fsUtils,
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
}, testOn: 'posix'); }, testOn: 'posix');
testUsingContext('respects IOS_SIMULATOR_LOG_FILE_PATH', () { testUsingContext('respects IOS_SIMULATOR_LOG_FILE_PATH', () {
...@@ -77,6 +86,9 @@ void main() { ...@@ -77,6 +86,9 @@ void main() {
expect(IOSSimulator('456').logFilePath, '/baz/qux/456/system.log'); expect(IOSSimulator('456').logFilePath, '/baz/qux/456/system.log');
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Platform: () => osx, Platform: () => osx,
FileSystemUtils: () => fsUtils,
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
}); });
}); });
...@@ -155,54 +167,72 @@ void main() { ...@@ -155,54 +167,72 @@ void main() {
expect(IOSSimulator('x', name: 'Apple TV').isSupported(), false); expect(IOSSimulator('x', name: 'Apple TV').isSupported(), false);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Platform: () => osx, Platform: () => osx,
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
}); });
testUsingContext('Apple Watch is unsupported', () { testUsingContext('Apple Watch is unsupported', () {
expect(IOSSimulator('x', name: 'Apple Watch').isSupported(), false); expect(IOSSimulator('x', name: 'Apple Watch').isSupported(), false);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Platform: () => osx, Platform: () => osx,
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
}); });
testUsingContext('iPad 2 is supported', () { testUsingContext('iPad 2 is supported', () {
expect(IOSSimulator('x', name: 'iPad 2').isSupported(), true); expect(IOSSimulator('x', name: 'iPad 2').isSupported(), true);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Platform: () => osx, Platform: () => osx,
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
}); });
testUsingContext('iPad Retina is supported', () { testUsingContext('iPad Retina is supported', () {
expect(IOSSimulator('x', name: 'iPad Retina').isSupported(), true); expect(IOSSimulator('x', name: 'iPad Retina').isSupported(), true);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Platform: () => osx, Platform: () => osx,
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
}); });
testUsingContext('iPhone 5 is supported', () { testUsingContext('iPhone 5 is supported', () {
expect(IOSSimulator('x', name: 'iPhone 5').isSupported(), true); expect(IOSSimulator('x', name: 'iPhone 5').isSupported(), true);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Platform: () => osx, Platform: () => osx,
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
}); });
testUsingContext('iPhone 5s is supported', () { testUsingContext('iPhone 5s is supported', () {
expect(IOSSimulator('x', name: 'iPhone 5s').isSupported(), true); expect(IOSSimulator('x', name: 'iPhone 5s').isSupported(), true);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Platform: () => osx, Platform: () => osx,
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
}); });
testUsingContext('iPhone SE is supported', () { testUsingContext('iPhone SE is supported', () {
expect(IOSSimulator('x', name: 'iPhone SE').isSupported(), true); expect(IOSSimulator('x', name: 'iPhone SE').isSupported(), true);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Platform: () => osx, Platform: () => osx,
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
}); });
testUsingContext('iPhone 7 Plus is supported', () { testUsingContext('iPhone 7 Plus is supported', () {
expect(IOSSimulator('x', name: 'iPhone 7 Plus').isSupported(), true); expect(IOSSimulator('x', name: 'iPhone 7 Plus').isSupported(), true);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Platform: () => osx, Platform: () => osx,
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
}); });
testUsingContext('iPhone X is supported', () { testUsingContext('iPhone X is supported', () {
expect(IOSSimulator('x', name: 'iPhone X').isSupported(), true); expect(IOSSimulator('x', name: 'iPhone X').isSupported(), true);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Platform: () => osx, Platform: () => osx,
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
}); });
}); });
...@@ -224,6 +254,8 @@ void main() { ...@@ -224,6 +254,8 @@ void main() {
}); });
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
BuildSystem: () => MockBuildSystem(), BuildSystem: () => MockBuildSystem(),
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
}); });
group('Simulator screenshot', () { group('Simulator screenshot', () {
...@@ -251,7 +283,11 @@ void main() { ...@@ -251,7 +283,11 @@ void main() {
when(mockXcode.minorVersion).thenReturn(1); when(mockXcode.minorVersion).thenReturn(1);
expect(deviceUnderTest.supportsScreenshot, false); expect(deviceUnderTest.supportsScreenshot, false);
}, },
overrides: <Type, Generator>{Xcode: () => mockXcode}, overrides: <Type, Generator>{
Xcode: () => mockXcode,
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
},
); );
testUsingContext( testUsingContext(
...@@ -281,6 +317,7 @@ void main() { ...@@ -281,6 +317,7 @@ void main() {
// Test a real one. Screenshot doesn't require instance states. // Test a real one. Screenshot doesn't require instance states.
SimControl: () => SimControl(), SimControl: () => SimControl(),
Xcode: () => mockXcode, Xcode: () => mockXcode,
FileSystem: () => fileSystem,
}, },
); );
}); });
...@@ -304,6 +341,7 @@ void main() { ...@@ -304,6 +341,7 @@ void main() {
}, },
overrides: <Type, Generator>{ overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager, ProcessManager: () => mockProcessManager,
FileSystem: () => fileSystem,
}); });
testUsingContext('uses /usr/bin/log on iOS 11 and above', () async { testUsingContext('uses /usr/bin/log on iOS 11 and above', () async {
...@@ -316,6 +354,7 @@ void main() { ...@@ -316,6 +354,7 @@ void main() {
}, },
overrides: <Type, Generator>{ overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager, ProcessManager: () => mockProcessManager,
FileSystem: () => fileSystem,
}); });
}); });
...@@ -338,6 +377,7 @@ void main() { ...@@ -338,6 +377,7 @@ void main() {
}, },
overrides: <Type, Generator>{ overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager, ProcessManager: () => mockProcessManager,
FileSystem: () => fileSystem,
}); });
testUsingContext('uses /usr/bin/log on iOS 11 and above', () async { testUsingContext('uses /usr/bin/log on iOS 11 and above', () async {
...@@ -347,6 +387,7 @@ void main() { ...@@ -347,6 +387,7 @@ void main() {
}, },
overrides: <Type, Generator>{ overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager, ProcessManager: () => mockProcessManager,
FileSystem: () => fileSystem,
}); });
}); });
...@@ -392,6 +433,7 @@ void main() { ...@@ -392,6 +433,7 @@ void main() {
]); ]);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager, ProcessManager: () => mockProcessManager,
FileSystem: () => fileSystem,
}); });
}); });
...@@ -469,6 +511,7 @@ void main() { ...@@ -469,6 +511,7 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager, ProcessManager: () => mockProcessManager,
SimControl: () => simControl, SimControl: () => simControl,
FileSystem: () => fileSystem,
}); });
testUsingContext('getDevices handles bad simctl output', () async { testUsingContext('getDevices handles bad simctl output', () async {
...@@ -480,6 +523,7 @@ void main() { ...@@ -480,6 +523,7 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager, ProcessManager: () => mockProcessManager,
SimControl: () => simControl, SimControl: () => simControl,
FileSystem: () => fileSystem,
}); });
testUsingContext('sdkMajorVersion defaults to 11 when sdkNameAndVersion is junk', () async { testUsingContext('sdkMajorVersion defaults to 11 when sdkNameAndVersion is junk', () async {
...@@ -511,6 +555,8 @@ void main() { ...@@ -511,6 +555,8 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
SimControl: () => simControl, SimControl: () => simControl,
PlistParser: () => MockPlistUtils(), PlistParser: () => MockPlistUtils(),
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
}); });
}); });
...@@ -540,8 +586,8 @@ flutter: ...@@ -540,8 +586,8 @@ flutter:
expect(IOSSimulator('test').isSupportedForProject(flutterProject), true); expect(IOSSimulator('test').isSupportedForProject(flutterProject), true);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem(),
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => FakeProcessManager.any(),
FileSystem: () => fileSystem,
}); });
testUsingContext('IOSDevice.isSupportedForProject is false with no host app and no module', () async { testUsingContext('IOSDevice.isSupportedForProject is false with no host app and no module', () async {
...@@ -551,7 +597,7 @@ flutter: ...@@ -551,7 +597,7 @@ flutter:
expect(IOSSimulator('test').isSupportedForProject(flutterProject), false); expect(IOSSimulator('test').isSupportedForProject(flutterProject), false);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem(), FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => FakeProcessManager.any(),
}); });
} }
......
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