Unverified Commit 2c846af1 authored by Christopher Fujino's avatar Christopher Fujino Committed by GitHub

Fix `_checkPodCondition` not handling `CocoaPodsStatus.brokenInstall` (#51676)

parent fb953b71
...@@ -143,13 +143,14 @@ class CocoaPods { ...@@ -143,13 +143,14 @@ class CocoaPods {
throwToolExit('Podfile missing'); throwToolExit('Podfile missing');
} }
bool podsProcessed = false; bool podsProcessed = false;
if (await _checkPodCondition()) { if (_shouldRunPodInstall(xcodeProject, dependenciesChanged)) {
if (_shouldRunPodInstall(xcodeProject, dependenciesChanged)) { if (!await _checkPodCondition()) {
await _runPodInstall(xcodeProject, engineDir); throwToolExit('CocoaPods not installed or not in valid state.');
podsProcessed = true;
} }
_warnIfPodfileOutOfDate(xcodeProject); await _runPodInstall(xcodeProject, engineDir);
podsProcessed = true;
} }
_warnIfPodfileOutOfDate(xcodeProject);
return podsProcessed; return podsProcessed;
} }
...@@ -166,6 +167,15 @@ class CocoaPods { ...@@ -166,6 +167,15 @@ class CocoaPods {
emphasis: true, emphasis: true,
); );
return false; return false;
case CocoaPodsStatus.brokenInstall:
globals.printError(
'Warning: CocoaPods is installed but broken. Skipping pod install.\n'
'$brokenCocoaPodsConsequence\n'
'To re-install:\n'
'$cocoaPodsUpgradeInstructions\n',
emphasis: true,
);
return false;
case CocoaPodsStatus.unknownVersion: case CocoaPodsStatus.unknownVersion:
globals.printError( globals.printError(
'Warning: Unknown CocoaPods version installed.\n' 'Warning: Unknown CocoaPods version installed.\n'
...@@ -193,7 +203,7 @@ class CocoaPods { ...@@ -193,7 +203,7 @@ class CocoaPods {
emphasis: true, emphasis: true,
); );
break; break;
default: case CocoaPodsStatus.recommended:
break; break;
} }
if (!await isCocoaPodsInitialized) { if (!await isCocoaPodsInitialized) {
......
...@@ -109,6 +109,22 @@ void main() { ...@@ -109,6 +109,22 @@ void main() {
)).thenAnswer((_) async => exitsWithError()); )).thenAnswer((_) async => exitsWithError());
} }
void pretendPodIsBroken() {
// it is present
when(mockProcessManager.run(
<String>['which', 'pod'],
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).thenAnswer((_) async => exitsHappy());
// but is not working
when(mockProcessManager.run(
<String>['pod', '--version'],
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).thenAnswer((_) async => exitsWithError());
}
void pretendPodIsInstalled() { void pretendPodIsInstalled() {
when(mockProcessManager.run( when(mockProcessManager.run(
<String>['which', 'pod'], <String>['which', 'pod'],
...@@ -306,21 +322,37 @@ void main() { ...@@ -306,21 +322,37 @@ void main() {
podsIsInHomeDir(); podsIsInHomeDir();
}); });
testUsingContext('prints error, if CocoaPods is not installed', () async { testUsingContext('throwsToolExit if CocoaPods is not installed', () async {
pretendPodIsNotInstalled(); pretendPodIsNotInstalled();
projectUnderTest.ios.podfile.createSync(); projectUnderTest.ios.podfile.createSync();
final bool didInstall = await cocoaPodsUnderTest.processPods( final Function invokeProcessPods = () async => await cocoaPodsUnderTest.processPods(
xcodeProject: projectUnderTest.ios, xcodeProject: projectUnderTest.ios,
engineDir: 'engine/path', engineDir: 'engine/path',
); );
expect(invokeProcessPods, throwsToolExit());
verifyNever(mockProcessManager.run(
argThat(containsAllInOrder(<String>['pod', 'install'])),
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
));
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => mockProcessManager,
});
testUsingContext('throwsToolExit if CocoaPods install is broken', () async {
pretendPodIsBroken();
projectUnderTest.ios.podfile.createSync();
final Function invokeProcessPods = () async => await cocoaPodsUnderTest.processPods(
xcodeProject: projectUnderTest.ios,
engineDir: 'engine/path',
);
expect(invokeProcessPods, throwsToolExit());
verifyNever(mockProcessManager.run( verifyNever(mockProcessManager.run(
argThat(containsAllInOrder(<String>['pod', 'install'])), argThat(containsAllInOrder(<String>['pod', 'install'])),
workingDirectory: anyNamed('workingDirectory'), workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'), environment: anyNamed('environment'),
)); ));
expect(testLogger.errorText, contains('not installed'));
expect(testLogger.errorText, contains('Skipping pod install'));
expect(didInstall, isFalse);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FileSystem: () => fs, FileSystem: () => fs,
ProcessManager: () => mockProcessManager, ProcessManager: () => mockProcessManager,
......
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