From 207efd4ceea8120701c8ddd3c7eada47f2b78dc6 Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Wed, 25 Mar 2020 11:14:00 -0700 Subject: [PATCH] Convert idevicescreenshot and upgradePbxProjWithFlutterAssets tests to testWithoutContext (#53208) --- packages/flutter_tools/lib/src/ios/mac.dart | 8 ++--- .../test/general.shard/ios/mac_test.dart | 30 ++++++++++--------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/packages/flutter_tools/lib/src/ios/mac.dart b/packages/flutter_tools/lib/src/ios/mac.dart index 634d140e61b..3894bdb6cb9 100644 --- a/packages/flutter_tools/lib/src/ios/mac.dart +++ b/packages/flutter_tools/lib/src/ios/mac.dart @@ -66,7 +66,7 @@ class IMobileDevice { /// Captures a screenshot to the specified outputFile. Future takeScreenshot(File outputFile) { - return processUtils.run( + return _processUtils.run( [ _idevicescreenshotPath, outputFile.path, @@ -87,7 +87,7 @@ Future buildXcodeProject({ DarwinArch activeArch, bool codesign = true, }) async { - if (!upgradePbxProjWithFlutterAssets(app.project)) { + if (!upgradePbxProjWithFlutterAssets(app.project, globals.logger)) { return XcodeBuildResult(success: false); } @@ -562,7 +562,7 @@ bool _checkXcodeVersion() { } // TODO(jmagman): Refactor to IOSMigrator. -bool upgradePbxProjWithFlutterAssets(IosProject project) { +bool upgradePbxProjWithFlutterAssets(IosProject project, Logger logger) { final File xcodeProjectFile = project.xcodeProjectInfoFile; assert(xcodeProjectFile.existsSync()); final List lines = xcodeProjectFile.readAsLinesSync(); @@ -575,7 +575,7 @@ bool upgradePbxProjWithFlutterAssets(IosProject project) { final Match match = oldAssets.firstMatch(line); if (match != null) { 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 { buffer.writeln(line); diff --git a/packages/flutter_tools/test/general.shard/ios/mac_test.dart b/packages/flutter_tools/test/general.shard/ios/mac_test.dart index cec44bfe6f8..c8bcd36b668 100644 --- a/packages/flutter_tools/test/general.shard/ios/mac_test.dart +++ b/packages/flutter_tools/test/general.shard/ios/mac_test.dart @@ -36,15 +36,19 @@ class MockXcodeProjectInterpreter extends Mock implements XcodeProjectInterprete class MockIosProject extends Mock implements IosProject {} void main() { + BufferLogger logger; + + setUp(() { + logger = BufferLogger.test(); + }); + group('IMobileDevice', () { final String libimobiledevicePath = globals.fs.path.join('bin', 'cache', 'artifacts', 'libimobiledevice'); final String idevicescreenshotPath = globals.fs.path.join(libimobiledevicePath, 'idevicescreenshot'); MockArtifacts mockArtifacts; MockCache mockCache; - Logger logger; setUp(() { - logger = BufferLogger.test(); mockCache = MockCache(); mockArtifacts = MockArtifacts(); when(mockArtifacts.getArtifactPath(Artifact.idevicescreenshot, platform: anyNamed('platform'))).thenReturn(idevicescreenshotPath); @@ -83,7 +87,7 @@ void main() { 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(mockProcessManager.run(any, environment: anyNamed('environment'), workingDirectory: null)).thenAnswer( (Invocation invocation) => Future.value(ProcessResult(4, 0, '', ''))); @@ -100,8 +104,6 @@ void main() { environment: {'DYLD_LIBRARY_PATH': libimobiledevicePath}, workingDirectory: null, )); - }, overrides: { - ProcessManager: () => mockProcessManager, }); }); }); @@ -389,7 +391,7 @@ Exited (sigterm)''', 'another line', ]; - testUsingContext('upgradePbxProjWithFlutterAssets', () async { + testWithoutContext('upgradePbxProjWithFlutterAssets', () async { final MockIosProject project = MockIosProject(); final MockFile pbxprojFile = MockFile(); @@ -400,30 +402,30 @@ Exited (sigterm)''', when(pbxprojFile.existsSync()) .thenAnswer((_) => true); - bool result = upgradePbxProjWithFlutterAssets(project); + bool result = upgradePbxProjWithFlutterAssets(project, logger); expect(result, true); expect( - testLogger.statusText, + logger.statusText, contains('Removing obsolete reference to flutter_assets'), ); - testLogger.clear(); + logger.clear(); when(pbxprojFile.readAsLinesSync()) .thenAnswer((_) => appFlxPbxProjLines); - result = upgradePbxProjWithFlutterAssets(project); + result = upgradePbxProjWithFlutterAssets(project, logger); expect(result, true); expect( - testLogger.statusText, + logger.statusText, contains('Removing obsolete reference to app.flx'), ); - testLogger.clear(); + logger.clear(); when(pbxprojFile.readAsLinesSync()) .thenAnswer((_) => cleanPbxProjLines); - result = upgradePbxProjWithFlutterAssets(project); + result = upgradePbxProjWithFlutterAssets(project, logger); expect(result, true); expect( - testLogger.statusText, + logger.statusText, isEmpty, ); });