[Doctor] Improve CocoaPods messages (#146701)

This tweaks the Flutter doctor messages for CocoaPods.

This also switches the "unknown version" error to link to the update instructions instead of the installation instructions; the user has already installed CocoaPods in this scenario.

Example error before:

```
    ✗ CocoaPods not installed.
        CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/platform-plugins
      To install see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.
```

Example error after:

```
    ✗ CocoaPods not installed.
        CocoaPods is a package manager for iOS or macOS platform code.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/platform-plugins
      For installation instructions, see https://guides.cocoapods.org/using/getting-started.html#installation
```
This commit is contained in:
Loïc Sharma 2024-04-15 11:45:12 -07:00 committed by GitHub
parent 2e748e8598
commit 882bcbb9aa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 27 additions and 13 deletions

View file

@ -193,19 +193,19 @@ class UserMessages {
String cocoaPodsMissing(String consequence, String installInstructions) =>
'CocoaPods not installed.\n'
'$consequence\n'
'To install $installInstructions';
'For installation instructions, $installInstructions';
String cocoaPodsUnknownVersion(String consequence, String upgradeInstructions) =>
'Unknown CocoaPods version installed.\n'
'$consequence\n'
'To upgrade $upgradeInstructions';
'To update CocoaPods, $upgradeInstructions';
String cocoaPodsOutdated(String currentVersion, String recVersion, String consequence, String upgradeInstructions) =>
'CocoaPods $currentVersion out of date ($recVersion is recommended).\n'
'$consequence\n'
'To upgrade $upgradeInstructions';
'To update CocoaPods, $upgradeInstructions';
String cocoaPodsBrokenInstall(String consequence, String reinstallInstructions) =>
'CocoaPods installed but not working.\n'
'$consequence\n'
'To re-install $reinstallInstructions';
'For re-installation instructions, $reinstallInstructions';
// Messages used in VisualStudioValidator
String visualStudioVersion(String name, String version) => '$name version $version';

View file

@ -25,7 +25,7 @@ import '../reporting/reporting.dart';
import '../xcode_project.dart';
const String noCocoaPodsConsequence = '''
CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side.
CocoaPods is a package manager for iOS or macOS platform code.
Without CocoaPods, plugins will not work on iOS or macOS.
For more info, see https://flutter.dev/platform-plugins''';
@ -47,9 +47,9 @@ const String outOfDatePluginsPodfileConsequence = '''
See https://flutter.dev/docs/development/packages-and-plugins/developing-packages#plugin-platforms for details.
If you have local Podfile edits you would like to keep, see https://github.com/flutter/flutter/issues/45197 for instructions.''';
const String cocoaPodsInstallInstructions = 'see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.';
const String cocoaPodsInstallInstructions = 'see https://guides.cocoapods.org/using/getting-started.html#installation';
const String cocoaPodsUpdateInstructions = 'see https://guides.cocoapods.org/using/getting-started.html#updating-cocoapods for instructions.';
const String cocoaPodsUpdateInstructions = 'see https://guides.cocoapods.org/using/getting-started.html#updating-cocoapods';
const String podfileIosMigrationInstructions = '''
rm ios/Podfile''';
@ -200,7 +200,7 @@ class CocoaPods {
_logger.printWarning(
'Warning: CocoaPods not installed. Skipping pod install.\n'
'$noCocoaPodsConsequence\n'
'To install $cocoaPodsInstallInstructions\n',
'For installation instructions, $cocoaPodsInstallInstructions\n',
emphasis: true,
);
return false;
@ -208,7 +208,7 @@ class CocoaPods {
_logger.printWarning(
'Warning: CocoaPods is installed but broken. Skipping pod install.\n'
'$brokenCocoaPodsConsequence\n'
'To re-install $cocoaPodsInstallInstructions\n',
'For re-installation instructions, $cocoaPodsInstallInstructions\n',
emphasis: true,
);
return false;
@ -216,14 +216,14 @@ class CocoaPods {
_logger.printWarning(
'Warning: Unknown CocoaPods version installed.\n'
'$unknownCocoaPodsConsequence\n'
'To upgrade $cocoaPodsInstallInstructions\n',
'To update CocoaPods, $cocoaPodsUpdateInstructions\n',
emphasis: true,
);
case CocoaPodsStatus.belowMinimumVersion:
_logger.printWarning(
'Warning: CocoaPods minimum required version $cocoaPodsMinimumVersion or greater not installed. Skipping pod install.\n'
'$noCocoaPodsConsequence\n'
'To upgrade $cocoaPodsInstallInstructions\n',
'To update CocoaPods, $cocoaPodsUpdateInstructions\n',
emphasis: true,
);
return false;
@ -231,7 +231,7 @@ class CocoaPods {
_logger.printWarning(
'Warning: CocoaPods recommended version $cocoaPodsRecommendedVersion or greater not installed.\n'
'Pods handling may fail on some projects involving plugins.\n'
'To upgrade $cocoaPodsInstallInstructions\n',
'To update CocoaPods, $cocoaPodsUpdateInstructions\n',
emphasis: true,
);
case CocoaPodsStatus.recommended:

View file

@ -43,7 +43,7 @@ class CocoaPodsValidator extends DoctorValidator {
case CocoaPodsStatus.unknownVersion:
status = ValidationType.partial;
messages.add(ValidationMessage.hint(
_userMessages.cocoaPodsUnknownVersion(unknownCocoaPodsConsequence, cocoaPodsInstallInstructions)));
_userMessages.cocoaPodsUnknownVersion(unknownCocoaPodsConsequence, cocoaPodsUpdateInstructions)));
case CocoaPodsStatus.belowMinimumVersion:
case CocoaPodsStatus.belowRecommendedVersion:
status = ValidationType.partial;

View file

@ -16,18 +16,32 @@ void main() {
final CocoaPodsValidator workflow = CocoaPodsValidator(FakeCocoaPods(CocoaPodsStatus.recommended, '1000.0.0'), UserMessages());
final ValidationResult result = await workflow.validate();
expect(result.type, ValidationType.success);
expect(result.messages.length, 1);
final ValidationMessage message = result.messages.first;
expect(message.type, ValidationMessageType.information);
expect(message.message, contains('CocoaPods version 1000.0.0'));
});
testWithoutContext('Emits missing status when CocoaPods is not installed', () async {
final CocoaPodsValidator workflow = CocoaPodsValidator(FakeCocoaPods(CocoaPodsStatus.notInstalled), UserMessages());
final ValidationResult result = await workflow.validate();
expect(result.type, ValidationType.missing);
expect(result.messages.length, 1);
final ValidationMessage message = result.messages.first;
expect(message.type, ValidationMessageType.error);
expect(message.message, contains('CocoaPods not installed'));
expect(message.message, contains('getting-started.html#installation'));
});
testWithoutContext('Emits partial status when CocoaPods is installed with unknown version', () async {
final CocoaPodsValidator workflow = CocoaPodsValidator(FakeCocoaPods(CocoaPodsStatus.unknownVersion), UserMessages());
final ValidationResult result = await workflow.validate();
expect(result.type, ValidationType.partial);
expect(result.messages.length, 1);
final ValidationMessage message = result.messages.first;
expect(message.type, ValidationMessageType.hint);
expect(message.message, contains('Unknown CocoaPods version installed'));
expect(message.message, contains('getting-started.html#updating-cocoapods'));
});
testWithoutContext('Emits partial status when CocoaPods version is too low', () async {