Unverified Commit 207efd4c authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Convert idevicescreenshot and upgradePbxProjWithFlutterAssets tests to testWithoutContext (#53208)

parent 52e4011a
...@@ -66,7 +66,7 @@ class IMobileDevice { ...@@ -66,7 +66,7 @@ class IMobileDevice {
/// Captures a screenshot to the specified outputFile. /// Captures a screenshot to the specified outputFile.
Future<void> takeScreenshot(File outputFile) { Future<void> takeScreenshot(File outputFile) {
return processUtils.run( return _processUtils.run(
<String>[ <String>[
_idevicescreenshotPath, _idevicescreenshotPath,
outputFile.path, outputFile.path,
...@@ -87,7 +87,7 @@ Future<XcodeBuildResult> buildXcodeProject({ ...@@ -87,7 +87,7 @@ Future<XcodeBuildResult> buildXcodeProject({
DarwinArch activeArch, DarwinArch activeArch,
bool codesign = true, bool codesign = true,
}) async { }) async {
if (!upgradePbxProjWithFlutterAssets(app.project)) { if (!upgradePbxProjWithFlutterAssets(app.project, globals.logger)) {
return XcodeBuildResult(success: false); return XcodeBuildResult(success: false);
} }
...@@ -562,7 +562,7 @@ bool _checkXcodeVersion() { ...@@ -562,7 +562,7 @@ bool _checkXcodeVersion() {
} }
// TODO(jmagman): Refactor to IOSMigrator. // TODO(jmagman): Refactor to IOSMigrator.
bool upgradePbxProjWithFlutterAssets(IosProject project) { bool upgradePbxProjWithFlutterAssets(IosProject project, Logger logger) {
final File xcodeProjectFile = project.xcodeProjectInfoFile; final File xcodeProjectFile = project.xcodeProjectInfoFile;
assert(xcodeProjectFile.existsSync()); assert(xcodeProjectFile.existsSync());
final List<String> lines = xcodeProjectFile.readAsLinesSync(); final List<String> lines = xcodeProjectFile.readAsLinesSync();
...@@ -575,7 +575,7 @@ bool upgradePbxProjWithFlutterAssets(IosProject project) { ...@@ -575,7 +575,7 @@ bool upgradePbxProjWithFlutterAssets(IosProject project) {
final Match match = oldAssets.firstMatch(line); final Match match = oldAssets.firstMatch(line);
if (match != null) { if (match != null) {
if (printedStatuses.add(match.group(1))) { if (printedStatuses.add(match.group(1))) {
globals.printStatus('Removing obsolete reference to ${match.group(1)} from ${project.hostAppBundleName}'); logger.printStatus('Removing obsolete reference to ${match.group(1)} from ${project.hostAppBundleName}');
} }
} else { } else {
buffer.writeln(line); buffer.writeln(line);
......
...@@ -36,15 +36,19 @@ class MockXcodeProjectInterpreter extends Mock implements XcodeProjectInterprete ...@@ -36,15 +36,19 @@ class MockXcodeProjectInterpreter extends Mock implements XcodeProjectInterprete
class MockIosProject extends Mock implements IosProject {} class MockIosProject extends Mock implements IosProject {}
void main() { void main() {
BufferLogger logger;
setUp(() {
logger = BufferLogger.test();
});
group('IMobileDevice', () { group('IMobileDevice', () {
final String libimobiledevicePath = globals.fs.path.join('bin', 'cache', 'artifacts', 'libimobiledevice'); final String libimobiledevicePath = globals.fs.path.join('bin', 'cache', 'artifacts', 'libimobiledevice');
final String idevicescreenshotPath = globals.fs.path.join(libimobiledevicePath, 'idevicescreenshot'); final String idevicescreenshotPath = globals.fs.path.join(libimobiledevicePath, 'idevicescreenshot');
MockArtifacts mockArtifacts; MockArtifacts mockArtifacts;
MockCache mockCache; MockCache mockCache;
Logger logger;
setUp(() { setUp(() {
logger = BufferLogger.test();
mockCache = MockCache(); mockCache = MockCache();
mockArtifacts = MockArtifacts(); mockArtifacts = MockArtifacts();
when(mockArtifacts.getArtifactPath(Artifact.idevicescreenshot, platform: anyNamed('platform'))).thenReturn(idevicescreenshotPath); when(mockArtifacts.getArtifactPath(Artifact.idevicescreenshot, platform: anyNamed('platform'))).thenReturn(idevicescreenshotPath);
...@@ -83,7 +87,7 @@ void main() { ...@@ -83,7 +87,7 @@ void main() {
expect(() async => await iMobileDevice.takeScreenshot(mockOutputFile), throwsA(anything)); expect(() async => await iMobileDevice.takeScreenshot(mockOutputFile), throwsA(anything));
}); });
testUsingContext('idevicescreenshot captures and returns screenshot', () async { testWithoutContext('idevicescreenshot captures and returns screenshot', () async {
when(mockOutputFile.path).thenReturn(outputPath); when(mockOutputFile.path).thenReturn(outputPath);
when(mockProcessManager.run(any, environment: anyNamed('environment'), workingDirectory: null)).thenAnswer( when(mockProcessManager.run(any, environment: anyNamed('environment'), workingDirectory: null)).thenAnswer(
(Invocation invocation) => Future<ProcessResult>.value(ProcessResult(4, 0, '', ''))); (Invocation invocation) => Future<ProcessResult>.value(ProcessResult(4, 0, '', '')));
...@@ -100,8 +104,6 @@ void main() { ...@@ -100,8 +104,6 @@ void main() {
environment: <String, String>{'DYLD_LIBRARY_PATH': libimobiledevicePath}, environment: <String, String>{'DYLD_LIBRARY_PATH': libimobiledevicePath},
workingDirectory: null, workingDirectory: null,
)); ));
}, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
}); });
}); });
}); });
...@@ -389,7 +391,7 @@ Exited (sigterm)''', ...@@ -389,7 +391,7 @@ Exited (sigterm)''',
'another line', 'another line',
]; ];
testUsingContext('upgradePbxProjWithFlutterAssets', () async { testWithoutContext('upgradePbxProjWithFlutterAssets', () async {
final MockIosProject project = MockIosProject(); final MockIosProject project = MockIosProject();
final MockFile pbxprojFile = MockFile(); final MockFile pbxprojFile = MockFile();
...@@ -400,30 +402,30 @@ Exited (sigterm)''', ...@@ -400,30 +402,30 @@ Exited (sigterm)''',
when(pbxprojFile.existsSync()) when(pbxprojFile.existsSync())
.thenAnswer((_) => true); .thenAnswer((_) => true);
bool result = upgradePbxProjWithFlutterAssets(project); bool result = upgradePbxProjWithFlutterAssets(project, logger);
expect(result, true); expect(result, true);
expect( expect(
testLogger.statusText, logger.statusText,
contains('Removing obsolete reference to flutter_assets'), contains('Removing obsolete reference to flutter_assets'),
); );
testLogger.clear(); logger.clear();
when(pbxprojFile.readAsLinesSync()) when(pbxprojFile.readAsLinesSync())
.thenAnswer((_) => appFlxPbxProjLines); .thenAnswer((_) => appFlxPbxProjLines);
result = upgradePbxProjWithFlutterAssets(project); result = upgradePbxProjWithFlutterAssets(project, logger);
expect(result, true); expect(result, true);
expect( expect(
testLogger.statusText, logger.statusText,
contains('Removing obsolete reference to app.flx'), contains('Removing obsolete reference to app.flx'),
); );
testLogger.clear(); logger.clear();
when(pbxprojFile.readAsLinesSync()) when(pbxprojFile.readAsLinesSync())
.thenAnswer((_) => cleanPbxProjLines); .thenAnswer((_) => cleanPbxProjLines);
result = upgradePbxProjWithFlutterAssets(project); result = upgradePbxProjWithFlutterAssets(project, logger);
expect(result, true); expect(result, true);
expect( expect(
testLogger.statusText, logger.statusText,
isEmpty, isEmpty,
); );
}); });
......
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