Unverified Commit 86389be6 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Convert CocoaPods tests to testWithoutContext (#53291)

parent ff20bb8c
...@@ -104,7 +104,14 @@ Future<T> runInContext<T>( ...@@ -104,7 +104,14 @@ Future<T> runInContext<T>(
operatingSystemUtils: globals.os, operatingSystemUtils: globals.os,
platform: globals.platform, platform: globals.platform,
), ),
CocoaPods: () => CocoaPods(), CocoaPods: () => CocoaPods(
fileSystem: globals.fs,
processManager: globals.processManager,
logger: globals.logger,
platform: globals.platform,
xcodeProjectInterpreter: globals.xcodeProjectInterpreter,
timeoutConfiguration: timeoutConfiguration,
),
CocoaPodsValidator: () => CocoaPodsValidator( CocoaPodsValidator: () => CocoaPodsValidator(
globals.cocoaPods, globals.cocoaPods,
globals.userMessages, globals.userMessages,
......
...@@ -6,6 +6,8 @@ import 'dart:async'; ...@@ -6,6 +6,8 @@ import 'dart:async';
import 'package:file/file.dart'; import 'package:file/file.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:platform/platform.dart';
import 'package:process/process.dart';
import '../base/common.dart'; import '../base/common.dart';
import '../base/file_system.dart'; import '../base/file_system.dart';
...@@ -14,7 +16,7 @@ import '../base/logger.dart'; ...@@ -14,7 +16,7 @@ import '../base/logger.dart';
import '../base/process.dart'; import '../base/process.dart';
import '../base/version.dart'; import '../base/version.dart';
import '../cache.dart'; import '../cache.dart';
import '../globals.dart' as globals; import '../ios/xcodeproj.dart';
import '../project.dart'; import '../project.dart';
const String noCocoaPodsConsequence = ''' const String noCocoaPodsConsequence = '''
...@@ -62,16 +64,41 @@ enum CocoaPodsStatus { ...@@ -62,16 +64,41 @@ enum CocoaPodsStatus {
} }
class CocoaPods { class CocoaPods {
CocoaPods({
@required FileSystem fileSystem,
@required ProcessManager processManager,
@required XcodeProjectInterpreter xcodeProjectInterpreter,
@required Logger logger,
@required Platform platform,
@required TimeoutConfiguration timeoutConfiguration,
}) : _fileSystem = fileSystem,
_processManager = processManager,
_xcodeProjectInterpreter = xcodeProjectInterpreter,
_logger = logger,
_platform = platform,
_processUtils = ProcessUtils(processManager: processManager, logger: logger),
_fileSystemUtils = FileSystemUtils(fileSystem: fileSystem, platform: platform),
_timeoutConfiguration = timeoutConfiguration;
final FileSystem _fileSystem;
final ProcessManager _processManager;
final FileSystemUtils _fileSystemUtils;
final ProcessUtils _processUtils;
final XcodeProjectInterpreter _xcodeProjectInterpreter;
final Logger _logger;
final Platform _platform;
final TimeoutConfiguration _timeoutConfiguration;
Future<String> _versionText; Future<String> _versionText;
String get cocoaPodsMinimumVersion => '1.6.0'; String get cocoaPodsMinimumVersion => '1.6.0';
String get cocoaPodsRecommendedVersion => '1.8.0'; String get cocoaPodsRecommendedVersion => '1.8.0';
Future<bool> get isInstalled => Future<bool> get isInstalled =>
globals.processUtils.exitsHappy(<String>['which', 'pod']); _processUtils.exitsHappy(<String>['which', 'pod']);
Future<String> get cocoaPodsVersionText { Future<String> get cocoaPodsVersionText {
_versionText ??= globals.processUtils.run( _versionText ??= _processUtils.run(
<String>['pod', '--version'], <String>['pod', '--version'],
environment: <String, String>{ environment: <String, String>{
'LANG': 'en_US.UTF-8', 'LANG': 'en_US.UTF-8',
...@@ -124,9 +151,9 @@ class CocoaPods { ...@@ -124,9 +151,9 @@ class CocoaPods {
if (installedVersion != null && installedVersion >= Version.parse('1.8.0')) { if (installedVersion != null && installedVersion >= Version.parse('1.8.0')) {
return true; return true;
} }
final String cocoapodsReposDir = globals.platform.environment['CP_REPOS_DIR'] final String cocoapodsReposDir = _platform.environment['CP_REPOS_DIR']
?? globals.fs.path.join(globals.fsUtils.homeDirPath, '.cocoapods', 'repos'); ?? _fileSystem.path.join(_fileSystemUtils.homeDirPath, '.cocoapods', 'repos');
return globals.fs.isDirectory(globals.fs.path.join(cocoapodsReposDir, 'master')); return _fileSystem.isDirectory(_fileSystem.path.join(cocoapodsReposDir, 'master'));
} }
Future<bool> processPods({ Future<bool> processPods({
...@@ -155,7 +182,7 @@ class CocoaPods { ...@@ -155,7 +182,7 @@ class CocoaPods {
final CocoaPodsStatus installation = await evaluateCocoaPodsInstallation; final CocoaPodsStatus installation = await evaluateCocoaPodsInstallation;
switch (installation) { switch (installation) {
case CocoaPodsStatus.notInstalled: case CocoaPodsStatus.notInstalled:
globals.printError( _logger.printError(
'Warning: CocoaPods not installed. Skipping pod install.\n' 'Warning: CocoaPods not installed. Skipping pod install.\n'
'$noCocoaPodsConsequence\n' '$noCocoaPodsConsequence\n'
'To install:\n' 'To install:\n'
...@@ -164,7 +191,7 @@ class CocoaPods { ...@@ -164,7 +191,7 @@ class CocoaPods {
); );
return false; return false;
case CocoaPodsStatus.brokenInstall: case CocoaPodsStatus.brokenInstall:
globals.printError( _logger.printError(
'Warning: CocoaPods is installed but broken. Skipping pod install.\n' 'Warning: CocoaPods is installed but broken. Skipping pod install.\n'
'$brokenCocoaPodsConsequence\n' '$brokenCocoaPodsConsequence\n'
'To re-install:\n' 'To re-install:\n'
...@@ -173,7 +200,7 @@ class CocoaPods { ...@@ -173,7 +200,7 @@ class CocoaPods {
); );
return false; return false;
case CocoaPodsStatus.unknownVersion: case CocoaPodsStatus.unknownVersion:
globals.printError( _logger.printError(
'Warning: Unknown CocoaPods version installed.\n' 'Warning: Unknown CocoaPods version installed.\n'
'$unknownCocoaPodsConsequence\n' '$unknownCocoaPodsConsequence\n'
'To upgrade:\n' 'To upgrade:\n'
...@@ -182,7 +209,7 @@ class CocoaPods { ...@@ -182,7 +209,7 @@ class CocoaPods {
); );
break; break;
case CocoaPodsStatus.belowMinimumVersion: case CocoaPodsStatus.belowMinimumVersion:
globals.printError( _logger.printError(
'Warning: CocoaPods minimum required version $cocoaPodsMinimumVersion or greater not installed. Skipping pod install.\n' 'Warning: CocoaPods minimum required version $cocoaPodsMinimumVersion or greater not installed. Skipping pod install.\n'
'$noCocoaPodsConsequence\n' '$noCocoaPodsConsequence\n'
'To upgrade:\n' 'To upgrade:\n'
...@@ -191,7 +218,7 @@ class CocoaPods { ...@@ -191,7 +218,7 @@ class CocoaPods {
); );
return false; return false;
case CocoaPodsStatus.belowRecommendedVersion: case CocoaPodsStatus.belowRecommendedVersion:
globals.printError( _logger.printError(
'Warning: CocoaPods recommended version $cocoaPodsRecommendedVersion or greater not installed.\n' 'Warning: CocoaPods recommended version $cocoaPodsRecommendedVersion or greater not installed.\n'
'Pods handling may fail on some projects involving plugins.\n' 'Pods handling may fail on some projects involving plugins.\n'
'To upgrade:\n' 'To upgrade:\n'
...@@ -203,7 +230,7 @@ class CocoaPods { ...@@ -203,7 +230,7 @@ class CocoaPods {
break; break;
} }
if (!await isCocoaPodsInitialized) { if (!await isCocoaPodsInitialized) {
globals.printError( _logger.printError(
'Warning: CocoaPods installed but not initialized. Skipping pod install.\n' 'Warning: CocoaPods installed but not initialized. Skipping pod install.\n'
'$noCocoaPodsConsequence\n' '$noCocoaPodsConsequence\n'
'To initialize CocoaPods, run:\n' 'To initialize CocoaPods, run:\n'
...@@ -221,7 +248,7 @@ class CocoaPods { ...@@ -221,7 +248,7 @@ class CocoaPods {
/// contains a suitable `Podfile` and that its `Flutter/Xxx.xcconfig` files /// contains a suitable `Podfile` and that its `Flutter/Xxx.xcconfig` files
/// include pods configuration. /// include pods configuration.
Future<void> setupPodfile(XcodeBasedProject xcodeProject) async { Future<void> setupPodfile(XcodeBasedProject xcodeProject) async {
if (!globals.xcodeProjectInterpreter.isInstalled) { if (!_xcodeProjectInterpreter.isInstalled) {
// Don't do anything for iOS when host platform doesn't support it. // Don't do anything for iOS when host platform doesn't support it.
return; return;
} }
...@@ -238,13 +265,13 @@ class CocoaPods { ...@@ -238,13 +265,13 @@ class CocoaPods {
if (xcodeProject is MacOSProject) { if (xcodeProject is MacOSProject) {
podfileTemplateName = 'Podfile-macos'; podfileTemplateName = 'Podfile-macos';
} else { } else {
final bool isSwift = (await globals.xcodeProjectInterpreter.getBuildSettings( final bool isSwift = (await _xcodeProjectInterpreter.getBuildSettings(
runnerProject.path, runnerProject.path,
'Runner', 'Runner',
)).containsKey('SWIFT_VERSION'); )).containsKey('SWIFT_VERSION');
podfileTemplateName = isSwift ? 'Podfile-ios-swift' : 'Podfile-ios-objc'; podfileTemplateName = isSwift ? 'Podfile-ios-swift' : 'Podfile-ios-objc';
} }
final File podfileTemplate = globals.fs.file(globals.fs.path.join( final File podfileTemplate = _fileSystem.file(_fileSystem.path.join(
Cache.flutterRoot, Cache.flutterRoot,
'packages', 'packages',
'flutter_tools', 'flutter_tools',
...@@ -305,10 +332,10 @@ class CocoaPods { ...@@ -305,10 +332,10 @@ class CocoaPods {
} }
Future<void> _runPodInstall(XcodeBasedProject xcodeProject, String engineDirectory) async { Future<void> _runPodInstall(XcodeBasedProject xcodeProject, String engineDirectory) async {
final Status status = globals.logger.startProgress('Running pod install...', timeout: timeoutConfiguration.slowOperation); final Status status = _logger.startProgress('Running pod install...', timeout: _timeoutConfiguration.slowOperation);
final ProcessResult result = await globals.processManager.run( final ProcessResult result = await _processManager.run(
<String>['pod', 'install', '--verbose'], <String>['pod', 'install', '--verbose'],
workingDirectory: globals.fs.path.dirname(xcodeProject.podfile.path), workingDirectory: _fileSystem.path.dirname(xcodeProject.podfile.path),
environment: <String, String>{ environment: <String, String>{
'FLUTTER_FRAMEWORK_DIR': engineDirectory, 'FLUTTER_FRAMEWORK_DIR': engineDirectory,
// See https://github.com/flutter/flutter/issues/10873. // See https://github.com/flutter/flutter/issues/10873.
...@@ -318,16 +345,16 @@ class CocoaPods { ...@@ -318,16 +345,16 @@ class CocoaPods {
}, },
); );
status.stop(); status.stop();
if (globals.logger.isVerbose || result.exitCode != 0) { if (_logger.isVerbose || result.exitCode != 0) {
final String stdout = result.stdout as String; final String stdout = result.stdout as String;
if (stdout.isNotEmpty) { if (stdout.isNotEmpty) {
globals.printStatus("CocoaPods' output:\n↳"); _logger.printStatus("CocoaPods' output:\n↳");
globals.printStatus(stdout, indent: 4); _logger.printStatus(stdout, indent: 4);
} }
final String stderr = result.stderr as String; final String stderr = result.stderr as String;
if (stderr.isNotEmpty) { if (stderr.isNotEmpty) {
globals.printStatus('Error output from CocoaPods:\n↳'); _logger.printStatus('Error output from CocoaPods:\n↳');
globals.printStatus(stderr, indent: 4); _logger.printStatus(stderr, indent: 4);
} }
} }
if (result.exitCode != 0) { if (result.exitCode != 0) {
...@@ -340,7 +367,7 @@ class CocoaPods { ...@@ -340,7 +367,7 @@ class CocoaPods {
void _diagnosePodInstallFailure(ProcessResult result) { void _diagnosePodInstallFailure(ProcessResult result) {
final dynamic stdout = result.stdout; final dynamic stdout = result.stdout;
if (stdout is String && stdout.contains('out-of-date source repos')) { if (stdout is String && stdout.contains('out-of-date source repos')) {
globals.printError( _logger.printError(
"Error: CocoaPods's specs repository is too out-of-date to satisfy dependencies.\n" "Error: CocoaPods's specs repository is too out-of-date to satisfy dependencies.\n"
'To update the CocoaPods specs, run:\n' 'To update the CocoaPods specs, run:\n'
' pod repo update\n', ' pod repo update\n',
...@@ -360,12 +387,12 @@ class CocoaPods { ...@@ -360,12 +387,12 @@ class CocoaPods {
if (xcodeProject is! IosProject) { if (xcodeProject is! IosProject) {
return; return;
} }
final Link flutterSymlink = globals.fs.link(globals.fs.path.join( final Link flutterSymlink = _fileSystem.link(_fileSystem.path.join(
xcodeProject.symlinks.path, xcodeProject.symlinks.path,
'flutter', 'flutter',
)); ));
if (flutterSymlink.existsSync()) { if (flutterSymlink.existsSync()) {
globals.printError( _logger.printError(
'Warning: Podfile is out of date\n' 'Warning: Podfile is out of date\n'
'$outOfDatePodfileConsequence\n' '$outOfDatePodfileConsequence\n'
'To regenerate the Podfile, run:\n' 'To regenerate the Podfile, run:\n'
......
...@@ -6,6 +6,7 @@ import 'dart:async'; ...@@ -6,6 +6,7 @@ import 'dart:async';
import 'package:file/file.dart'; import 'package:file/file.dart';
import 'package:file/memory.dart'; import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:platform/platform.dart'; import 'package:platform/platform.dart';
import 'package:mockito/mockito.dart'; import 'package:mockito/mockito.dart';
import 'package:process/process.dart'; import 'package:process/process.dart';
...@@ -31,6 +32,7 @@ void main() { ...@@ -31,6 +32,7 @@ void main() {
FlutterProject projectUnderTest; FlutterProject projectUnderTest;
CocoaPods cocoaPodsUnderTest; CocoaPods cocoaPodsUnderTest;
InvokeProcess resultOfPodVersion; InvokeProcess resultOfPodVersion;
BufferLogger logger;
void pretendPodVersionFails() { void pretendPodVersionFails() {
resultOfPodVersion = () async => exitsWithError(); resultOfPodVersion = () async => exitsWithError();
...@@ -64,10 +66,18 @@ void main() { ...@@ -64,10 +66,18 @@ void main() {
Cache.flutterRoot = 'flutter'; Cache.flutterRoot = 'flutter';
fs = MemoryFileSystem(); fs = MemoryFileSystem();
mockProcessManager = MockProcessManager(); mockProcessManager = MockProcessManager();
logger = BufferLogger.test();
mockXcodeProjectInterpreter = MockXcodeProjectInterpreter(); mockXcodeProjectInterpreter = MockXcodeProjectInterpreter();
projectUnderTest = FlutterProject.fromDirectory(fs.directory('project')); projectUnderTest = FlutterProject.fromDirectory(fs.directory('project'));
projectUnderTest.ios.xcodeProject.createSync(recursive: true); projectUnderTest.ios.xcodeProject.createSync(recursive: true);
cocoaPodsUnderTest = CocoaPods(); cocoaPodsUnderTest = CocoaPods(
fileSystem: fs,
processManager: mockProcessManager,
logger: logger,
platform: FakePlatform(),
xcodeProjectInterpreter: mockXcodeProjectInterpreter,
timeoutConfiguration: const TimeoutConfiguration(),
);
pretendPodVersionIs('1.8.0'); pretendPodVersionIs('1.8.0');
fs.file(fs.path.join( fs.file(fs.path.join(
Cache.flutterRoot, 'packages', 'flutter_tools', 'templates', 'cocoapods', 'Podfile-ios-objc', Cache.flutterRoot, 'packages', 'flutter_tools', 'templates', 'cocoapods', 'Podfile-ios-objc',
...@@ -139,92 +149,74 @@ void main() { ...@@ -139,92 +149,74 @@ void main() {
when(mockProcessManager.canRun(any)).thenReturn(true); when(mockProcessManager.canRun(any)).thenReturn(true);
}); });
testUsingContext('detects not installed, if pod exec does not exist', () async { testWithoutContext('detects not installed, if pod exec does not exist', () async {
pretendPodIsNotInstalled(); pretendPodIsNotInstalled();
expect(await cocoaPodsUnderTest.evaluateCocoaPodsInstallation, CocoaPodsStatus.notInstalled); expect(await cocoaPodsUnderTest.evaluateCocoaPodsInstallation, CocoaPodsStatus.notInstalled);
}, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
}); });
testUsingContext('detects not installed, if pod is installed but version fails', () async { testWithoutContext('detects not installed, if pod is installed but version fails', () async {
pretendPodIsInstalled(); pretendPodIsInstalled();
pretendPodVersionFails(); pretendPodVersionFails();
expect(await cocoaPodsUnderTest.evaluateCocoaPodsInstallation, CocoaPodsStatus.brokenInstall); expect(await cocoaPodsUnderTest.evaluateCocoaPodsInstallation, CocoaPodsStatus.brokenInstall);
}, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
}); });
testUsingContext('detects installed', () async { testWithoutContext('detects installed', () async {
pretendPodIsInstalled(); pretendPodIsInstalled();
pretendPodVersionIs('0.0.1'); pretendPodVersionIs('0.0.1');
expect(await cocoaPodsUnderTest.evaluateCocoaPodsInstallation, isNot(CocoaPodsStatus.notInstalled)); expect(await cocoaPodsUnderTest.evaluateCocoaPodsInstallation, isNot(CocoaPodsStatus.notInstalled));
}, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
}); });
testUsingContext('detects unknown version', () async { testWithoutContext('detects unknown version', () async {
pretendPodIsInstalled(); pretendPodIsInstalled();
pretendPodVersionIs('Plugin loaded.\n1.5.3'); pretendPodVersionIs('Plugin loaded.\n1.5.3');
expect(await cocoaPodsUnderTest.evaluateCocoaPodsInstallation, CocoaPodsStatus.unknownVersion); expect(await cocoaPodsUnderTest.evaluateCocoaPodsInstallation, CocoaPodsStatus.unknownVersion);
}, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
}); });
testUsingContext('detects below minimum version', () async { testWithoutContext('detects below minimum version', () async {
pretendPodIsInstalled(); pretendPodIsInstalled();
pretendPodVersionIs('1.5.0'); pretendPodVersionIs('1.5.0');
expect(await cocoaPodsUnderTest.evaluateCocoaPodsInstallation, CocoaPodsStatus.belowMinimumVersion); expect(await cocoaPodsUnderTest.evaluateCocoaPodsInstallation, CocoaPodsStatus.belowMinimumVersion);
}, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
}); });
testUsingContext('detects below recommended version', () async { testWithoutContext('detects below recommended version', () async {
pretendPodIsInstalled(); pretendPodIsInstalled();
pretendPodVersionIs('1.6.0'); pretendPodVersionIs('1.6.0');
expect(await cocoaPodsUnderTest.evaluateCocoaPodsInstallation, CocoaPodsStatus.belowRecommendedVersion); expect(await cocoaPodsUnderTest.evaluateCocoaPodsInstallation, CocoaPodsStatus.belowRecommendedVersion);
}, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
}); });
testUsingContext('detects at recommended version', () async { testWithoutContext('detects at recommended version', () async {
pretendPodIsInstalled(); pretendPodIsInstalled();
pretendPodVersionIs('1.8.0'); pretendPodVersionIs('1.8.0');
expect(await cocoaPodsUnderTest.evaluateCocoaPodsInstallation, CocoaPodsStatus.recommended); expect(await cocoaPodsUnderTest.evaluateCocoaPodsInstallation, CocoaPodsStatus.recommended);
}, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
}); });
testUsingContext('detects above recommended version', () async { testWithoutContext('detects above recommended version', () async {
pretendPodIsInstalled(); pretendPodIsInstalled();
pretendPodVersionIs('1.8.1'); pretendPodVersionIs('1.8.1');
expect(await cocoaPodsUnderTest.evaluateCocoaPodsInstallation, CocoaPodsStatus.recommended); expect(await cocoaPodsUnderTest.evaluateCocoaPodsInstallation, CocoaPodsStatus.recommended);
}, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
}); });
testUsingContext('detects initialized over 1.8.0', () async { testWithoutContext('detects initialized over 1.8.0', () async {
pretendPodIsInstalled(); pretendPodIsInstalled();
pretendPodVersionIs('1.8.0'); pretendPodVersionIs('1.8.0');
expect(await cocoaPodsUnderTest.isCocoaPodsInitialized, isTrue); expect(await cocoaPodsUnderTest.isCocoaPodsInitialized, isTrue);
}, overrides: <Type, Generator>{
Platform: () => FakePlatform(),
FileSystem: () => fs,
ProcessManager: () => mockProcessManager,
}); });
}); });
group('Setup Podfile', () { group('Setup Podfile', () {
testUsingContext('creates objective-c Podfile when not present', () async { setUp(() {
when(mockXcodeProjectInterpreter.isInstalled).thenReturn(true);
});
testWithoutContext('creates objective-c Podfile when not present', () async {
when(mockXcodeProjectInterpreter.getBuildSettings(any, any))
.thenAnswer((_) async => <String, String>{});
await cocoaPodsUnderTest.setupPodfile(projectUnderTest.ios); await cocoaPodsUnderTest.setupPodfile(projectUnderTest.ios);
expect(projectUnderTest.ios.podfile.readAsStringSync(), 'Objective-C iOS podfile template'); expect(projectUnderTest.ios.podfile.readAsStringSync(), 'Objective-C iOS podfile template');
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
}); });
testUsingContext('creates swift Podfile if swift', () async { testUsingContext('creates swift Podfile if swift', () async {
when(mockXcodeProjectInterpreter.isInstalled).thenReturn(true);
when(mockXcodeProjectInterpreter.getBuildSettings(any, any)) when(mockXcodeProjectInterpreter.getBuildSettings(any, any))
.thenAnswer((_) async => <String, String>{ .thenAnswer((_) async => <String, String>{
'SWIFT_VERSION': '5.0', 'SWIFT_VERSION': '5.0',
...@@ -240,14 +232,11 @@ void main() { ...@@ -240,14 +232,11 @@ void main() {
XcodeProjectInterpreter: () => mockXcodeProjectInterpreter, XcodeProjectInterpreter: () => mockXcodeProjectInterpreter,
}); });
testUsingContext('creates macOS Podfile when not present', () async { testWithoutContext('creates macOS Podfile when not present', () async {
projectUnderTest.macos.xcodeProject.createSync(recursive: true); projectUnderTest.macos.xcodeProject.createSync(recursive: true);
await cocoaPodsUnderTest.setupPodfile(projectUnderTest.macos); await cocoaPodsUnderTest.setupPodfile(projectUnderTest.macos);
expect(projectUnderTest.macos.podfile.readAsStringSync(), 'macOS podfile template'); expect(projectUnderTest.macos.podfile.readAsStringSync(), 'macOS podfile template');
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
}); });
testUsingContext('does not recreate Podfile when already present', () async { testUsingContext('does not recreate Podfile when already present', () async {
...@@ -337,7 +326,7 @@ void main() { ...@@ -337,7 +326,7 @@ void main() {
when(mockProcessManager.canRun(any)).thenReturn(true); when(mockProcessManager.canRun(any)).thenReturn(true);
}); });
testUsingContext('throwsToolExit if CocoaPods is not installed', () async { testWithoutContext('throwsToolExit if CocoaPods is not installed', () async {
pretendPodIsNotInstalled(); pretendPodIsNotInstalled();
projectUnderTest.ios.podfile.createSync(); projectUnderTest.ios.podfile.createSync();
final Function invokeProcessPods = () async => await cocoaPodsUnderTest.processPods( final Function invokeProcessPods = () async => await cocoaPodsUnderTest.processPods(
...@@ -350,12 +339,9 @@ void main() { ...@@ -350,12 +339,9 @@ void main() {
workingDirectory: anyNamed('workingDirectory'), workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'), environment: anyNamed('environment'),
)); ));
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => mockProcessManager,
}); });
testUsingContext('throwsToolExit if CocoaPods install is broken', () async { testWithoutContext('throwsToolExit if CocoaPods install is broken', () async {
pretendPodIsBroken(); pretendPodIsBroken();
projectUnderTest.ios.podfile.createSync(); projectUnderTest.ios.podfile.createSync();
final Function invokeProcessPods = () async => await cocoaPodsUnderTest.processPods( final Function invokeProcessPods = () async => await cocoaPodsUnderTest.processPods(
...@@ -368,12 +354,9 @@ void main() { ...@@ -368,12 +354,9 @@ void main() {
workingDirectory: anyNamed('workingDirectory'), workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'), environment: anyNamed('environment'),
)); ));
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => mockProcessManager,
}); });
testUsingContext('prints warning, if Podfile is out of date', () async { testWithoutContext('prints warning, if Podfile is out of date', () async {
pretendPodIsInstalled(); pretendPodIsInstalled();
fs.file(fs.path.join('project', 'ios', 'Podfile')) fs.file(fs.path.join('project', 'ios', 'Podfile'))
...@@ -388,13 +371,10 @@ void main() { ...@@ -388,13 +371,10 @@ void main() {
xcodeProject: projectUnderTest.ios, xcodeProject: projectUnderTest.ios,
engineDir: 'engine/path', engineDir: 'engine/path',
); );
expect(testLogger.errorText, contains('Warning: Podfile is out of date')); expect(logger.errorText, contains('Warning: Podfile is out of date'));
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => mockProcessManager,
}); });
testUsingContext('throws, if Podfile is missing.', () async { testWithoutContext('throws, if Podfile is missing.', () async {
pretendPodIsInstalled(); pretendPodIsInstalled();
try { try {
await cocoaPodsUnderTest.processPods( await cocoaPodsUnderTest.processPods(
...@@ -410,12 +390,9 @@ void main() { ...@@ -410,12 +390,9 @@ void main() {
environment: anyNamed('environment'), environment: anyNamed('environment'),
)); ));
} }
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => mockProcessManager,
}); });
testUsingContext('throws, if specs repo is outdated.', () async { testWithoutContext('throws, if specs repo is outdated.', () async {
pretendPodIsInstalled(); pretendPodIsInstalled();
fs.file(fs.path.join('project', 'ios', 'Podfile')) fs.file(fs.path.join('project', 'ios', 'Podfile'))
..createSync() ..createSync()
...@@ -454,16 +431,13 @@ Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by ...@@ -454,16 +431,13 @@ Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by
} on Exception catch (e) { } on Exception catch (e) {
expect(e, isA<ToolExit>()); expect(e, isA<ToolExit>());
expect( expect(
testLogger.errorText, logger.errorText,
contains("CocoaPods's specs repository is too out-of-date to satisfy dependencies"), contains("CocoaPods's specs repository is too out-of-date to satisfy dependencies"),
); );
} }
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => mockProcessManager,
}); });
testUsingContext('run pod install, if Podfile.lock is missing', () async { testWithoutContext('run pod install, if Podfile.lock is missing', () async {
pretendPodIsInstalled(); pretendPodIsInstalled();
projectUnderTest.ios.podfile projectUnderTest.ios.podfile
..createSync() ..createSync()
...@@ -482,12 +456,9 @@ Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by ...@@ -482,12 +456,9 @@ Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by
workingDirectory: 'project/ios', workingDirectory: 'project/ios',
environment: <String, String>{'FLUTTER_FRAMEWORK_DIR': 'engine/path', 'COCOAPODS_DISABLE_STATS': 'true', 'LANG': 'en_US.UTF-8'}, environment: <String, String>{'FLUTTER_FRAMEWORK_DIR': 'engine/path', 'COCOAPODS_DISABLE_STATS': 'true', 'LANG': 'en_US.UTF-8'},
)); ));
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => mockProcessManager,
}); });
testUsingContext('runs pod install, if Manifest.lock is missing', () async { testWithoutContext('runs pod install, if Manifest.lock is missing', () async {
pretendPodIsInstalled(); pretendPodIsInstalled();
projectUnderTest.ios.podfile projectUnderTest.ios.podfile
..createSync() ..createSync()
...@@ -510,12 +481,9 @@ Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by ...@@ -510,12 +481,9 @@ Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by
'LANG': 'en_US.UTF-8', 'LANG': 'en_US.UTF-8',
}, },
)); ));
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => mockProcessManager,
}); });
testUsingContext('runs pod install, if Manifest.lock different from Podspec.lock', () async { testWithoutContext('runs pod install, if Manifest.lock different from Podspec.lock', () async {
pretendPodIsInstalled(); pretendPodIsInstalled();
projectUnderTest.ios.podfile projectUnderTest.ios.podfile
..createSync() ..createSync()
...@@ -541,12 +509,9 @@ Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by ...@@ -541,12 +509,9 @@ Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by
'LANG': 'en_US.UTF-8', 'LANG': 'en_US.UTF-8',
}, },
)); ));
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => mockProcessManager,
}); });
testUsingContext('runs pod install, if flutter framework changed', () async { testWithoutContext('runs pod install, if flutter framework changed', () async {
pretendPodIsInstalled(); pretendPodIsInstalled();
projectUnderTest.ios.podfile projectUnderTest.ios.podfile
..createSync() ..createSync()
...@@ -572,12 +537,9 @@ Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by ...@@ -572,12 +537,9 @@ Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by
'LANG': 'en_US.UTF-8', 'LANG': 'en_US.UTF-8',
}, },
)); ));
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => mockProcessManager,
}); });
testUsingContext('runs pod install, if Podfile.lock is older than Podfile', () async { testWithoutContext('runs pod install, if Podfile.lock is older than Podfile', () async {
pretendPodIsInstalled(); pretendPodIsInstalled();
projectUnderTest.ios.podfile projectUnderTest.ios.podfile
..createSync() ..createSync()
...@@ -605,12 +567,9 @@ Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by ...@@ -605,12 +567,9 @@ Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by
'LANG': 'en_US.UTF-8', 'LANG': 'en_US.UTF-8',
}, },
)); ));
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => mockProcessManager,
}); });
testUsingContext('skips pod install, if nothing changed', () async { testWithoutContext('skips pod install, if nothing changed', () async {
pretendPodIsInstalled(); pretendPodIsInstalled();
projectUnderTest.ios.podfile projectUnderTest.ios.podfile
..createSync() ..createSync()
...@@ -632,12 +591,9 @@ Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by ...@@ -632,12 +591,9 @@ Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by
workingDirectory: anyNamed('workingDirectory'), workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'), environment: anyNamed('environment'),
)); ));
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => mockProcessManager,
}); });
testUsingContext('a failed pod install deletes Pods/Manifest.lock', () async { testWithoutContext('a failed pod install deletes Pods/Manifest.lock', () async {
pretendPodIsInstalled(); pretendPodIsInstalled();
projectUnderTest.ios.podfile projectUnderTest.ios.podfile
..createSync() ..createSync()
...@@ -671,9 +627,6 @@ Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by ...@@ -671,9 +627,6 @@ Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by
} on ToolExit { } on ToolExit {
expect(projectUnderTest.ios.podManifestLock.existsSync(), isFalse); expect(projectUnderTest.ios.podManifestLock.existsSync(), isFalse);
} }
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => mockProcessManager,
}); });
}); });
...@@ -692,7 +645,7 @@ Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by ...@@ -692,7 +645,7 @@ Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by
}; };
}); });
testUsingContext('succeeds, if specs repo is in CP_REPOS_DIR.', () async { testWithoutContext('succeeds, if specs repo is in CP_REPOS_DIR.', () async {
pretendPodIsInstalled(); pretendPodIsInstalled();
fs.file(fs.path.join('project', 'ios', 'Podfile')) fs.file(fs.path.join('project', 'ios', 'Podfile'))
..createSync() ..createSync()
...@@ -707,10 +660,6 @@ Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by ...@@ -707,10 +660,6 @@ Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by
engineDir: 'engine/path', engineDir: 'engine/path',
); );
expect(success, true); expect(success, true);
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => mockProcessManager,
Platform: () => FakePlatform(environment: environment),
}); });
}); });
} }
......
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