diff --git a/packages/shorebird_cli/lib/src/doctor.dart b/packages/shorebird_cli/lib/src/doctor.dart index f3bea7bd..5ae7062a 100644 --- a/packages/shorebird_cli/lib/src/doctor.dart +++ b/packages/shorebird_cli/lib/src/doctor.dart @@ -32,7 +32,6 @@ class Doctor { /// Validators that should run on all commands. List generalValidators = [ ShorebirdVersionValidator(), - ShorebirdFlutterValidator(), AndroidInternetPermissionValidator(), MacosNetworkEntitlementValidator(), ShorebirdYamlAssetValidator(), diff --git a/packages/shorebird_cli/lib/src/validators/shorebird_flutter_validator.dart b/packages/shorebird_cli/lib/src/validators/shorebird_flutter_validator.dart deleted file mode 100644 index 2f354847..00000000 --- a/packages/shorebird_cli/lib/src/validators/shorebird_flutter_validator.dart +++ /dev/null @@ -1,134 +0,0 @@ -import 'dart:io'; - -import 'package:pub_semver/pub_semver.dart'; -import 'package:shorebird_cli/src/platform.dart'; -import 'package:shorebird_cli/src/shorebird_env.dart'; -import 'package:shorebird_cli/src/shorebird_flutter.dart'; -import 'package:shorebird_cli/src/validators/validators.dart'; - -/// An exception thrown when a validation issue is found. -class FlutterValidationException implements Exception { - /// Creates a new [FlutterValidationException] with the provided [message]. - const FlutterValidationException(this.message); - - /// The message associated with the exception. - final String message; - - @override - String toString() => 'FlutterValidationException: $message'; -} - -/// An exception thrown when a command is not found. -class CommandNotFoundException implements Exception {} - -/// {@template shorebird_flutter_validator} -/// Compares the version of Flutter that Shorebird includes with the version -/// of Flutter on the user's path. Will error if no system Flutter is found, and -/// will warn if major or minor versions differ. -/// {@endtemplate} -class ShorebirdFlutterValidator extends Validator { - /// {@macro shorebird_flutter_validator} - ShorebirdFlutterValidator(); - - @override - String get description => 'Flutter install is correct'; - - @override - Future> validate() async { - final issues = []; - - if (!shorebirdEnv.flutterDirectory.existsSync()) { - final message = - 'No Flutter directory found at ${shorebirdEnv.flutterDirectory}'; - issues.add(ValidationIssue.error(message: message)); - } - - if (!await shorebirdFlutter.isUnmodified()) { - issues.add( - ValidationIssue.warning( - message: '${shorebirdEnv.flutterDirectory} has local modifications', - ), - ); - } - - String? shorebirdFlutterVersionString; - try { - shorebirdFlutterVersionString = await _getFlutterVersion(); - } on Exception catch (error) { - issues.add( - ValidationIssue.error( - message: 'Failed to determine Shorebird Flutter version. $error', - ), - ); - } - - String? pathFlutterVersionString; - try { - pathFlutterVersionString = await _getFlutterVersion( - useVendedFlutter: false, - ); - } on CommandNotFoundException catch (_) { - // If there is no system Flutter, we don't throw a validation exception. - } on Exception catch (error) { - issues.add( - ValidationIssue.error( - message: 'Failed to determine path Flutter version. $error', - ), - ); - } - - if (shorebirdFlutterVersionString != null && - pathFlutterVersionString != null) { - final shorebirdFlutterVersion = - Version.parse(shorebirdFlutterVersionString); - final pathFlutterVersion = Version.parse(pathFlutterVersionString); - if (shorebirdFlutterVersion.major != pathFlutterVersion.major || - shorebirdFlutterVersion.minor != pathFlutterVersion.minor) { - final message = ''' -The version of Flutter that Shorebird includes and the Flutter on your path are different. -\tShorebird Flutter: $shorebirdFlutterVersionString -\tSystem Flutter: $pathFlutterVersionString -This can cause unexpected behavior if you are switching between the tools and the version gap is wide. If you have any trouble, please let us know on Shorebird discord.'''; - - issues.add(ValidationIssue.warning(message: message)); - } - } - - final flutterStorageEnvironmentValue = - platform.environment['FLUTTER_STORAGE_BASE_URL']; - if (flutterStorageEnvironmentValue != null && - flutterStorageEnvironmentValue.isNotEmpty) { - issues.add( - ValidationIssue.warning( - message: 'Shorebird does not respect the FLUTTER_STORAGE_BASE_URL ' - 'environment variable at this time', - ), - ); - } - - return issues; - } - - Future _getFlutterVersion({bool useVendedFlutter = true}) async { - final String? version; - try { - version = useVendedFlutter - ? await shorebirdFlutter.getVersionString() - : await shorebirdFlutter.getSystemVersion(); - } on ProcessException catch (error) { - if (error.errorCode == 127) throw CommandNotFoundException(); - - throw FlutterValidationException( - 'Flutter version check did not complete successfully. ${error.message}', - ); - } - - if (version == null) { - throw const FlutterValidationException( - 'Could not detect version number in output', - ); - } - - return version; - } -} diff --git a/packages/shorebird_cli/lib/src/validators/validators.dart b/packages/shorebird_cli/lib/src/validators/validators.dart index bb782565..b97e38a3 100644 --- a/packages/shorebird_cli/lib/src/validators/validators.dart +++ b/packages/shorebird_cli/lib/src/validators/validators.dart @@ -7,7 +7,6 @@ import 'package:shorebird_cli/src/shorebird_process.dart'; export 'android_internet_permission_validator.dart'; export 'flavor_validator.dart'; export 'macos_network_entitlement_validator.dart'; -export 'shorebird_flutter_validator.dart'; export 'shorebird_version_validator.dart'; export 'shorebird_yaml_asset_validator.dart'; diff --git a/packages/shorebird_cli/test/src/commands/patch/android_patcher_test.dart b/packages/shorebird_cli/test/src/commands/patch/android_patcher_test.dart index 91e501e6..cb20549d 100644 --- a/packages/shorebird_cli/test/src/commands/patch/android_patcher_test.dart +++ b/packages/shorebird_cli/test/src/commands/patch/android_patcher_test.dart @@ -46,10 +46,10 @@ void main() { late CodeSigner codeSigner; late Doctor doctor; late Directory projectRoot; + late FlavorValidator flavorValidator; late ShorebirdLogger logger; late PatchDiffChecker patchDiffChecker; late Progress progress; - late ShorebirdFlutterValidator flutterValidator; late ShorebirdProcess shorebirdProcess; late ShorebirdEnv shorebirdEnv; late ShorebirdFlutter shorebirdFlutter; @@ -125,11 +125,11 @@ void main() { codePushClientWrapper = MockCodePushClientWrapper(); codeSigner = MockCodeSigner(); doctor = MockDoctor(); + flavorValidator = MockFlavorValidator(); patchDiffChecker = MockPatchDiffChecker(); progress = MockProgress(); projectRoot = Directory.systemTemp.createTempSync(); logger = MockShorebirdLogger(); - flutterValidator = MockShorebirdFlutterValidator(); shorebirdProcess = MockShorebirdProcess(); shorebirdEnv = MockShorebirdEnv(); shorebirdFlutter = MockShorebirdFlutter(); @@ -163,8 +163,8 @@ void main() { group('assertPreconditions', () { setUp(() { when(() => doctor.androidCommandValidators) - .thenReturn([flutterValidator]); - when(flutterValidator.validate).thenAnswer((_) async => []); + .thenReturn([flavorValidator]); + when(flavorValidator.validate).thenAnswer((_) async => []); }); group('when validation succeeds', () { @@ -220,7 +220,7 @@ void main() { () => shorebirdValidator.validatePreconditions( checkUserIsAuthenticated: true, checkShorebirdInitialized: true, - validators: [flutterValidator], + validators: [flavorValidator], ), ).called(1); }); diff --git a/packages/shorebird_cli/test/src/commands/patch/ios_framework_patcher_test.dart b/packages/shorebird_cli/test/src/commands/patch/ios_framework_patcher_test.dart index 4c6405f7..0715eaf8 100644 --- a/packages/shorebird_cli/test/src/commands/patch/ios_framework_patcher_test.dart +++ b/packages/shorebird_cli/test/src/commands/patch/ios_framework_patcher_test.dart @@ -48,15 +48,15 @@ void main() { late ArtifactManager artifactManager; late CodePushClientWrapper codePushClientWrapper; late Doctor doctor; - late EngineConfig engineConfig; late Directory flutterDirectory; late Directory projectRoot; + late EngineConfig engineConfig; + late FlavorValidator flavorValidator; late ShorebirdLogger logger; late OperatingSystemInterface operatingSystemInterface; late PatchDiffChecker patchDiffChecker; late Progress progress; late ShorebirdArtifacts shorebirdArtifacts; - late ShorebirdFlutterValidator flutterValidator; late ShorebirdProcess shorebirdProcess; late ShorebirdEnv shorebirdEnv; late ShorebirdFlutter shorebirdFlutter; @@ -105,6 +105,7 @@ void main() { codePushClientWrapper = MockCodePushClientWrapper(); doctor = MockDoctor(); engineConfig = MockEngineConfig(); + flavorValidator = MockFlavorValidator(); operatingSystemInterface = MockOperatingSystemInterface(); patchDiffChecker = MockPatchDiffChecker(); progress = MockProgress(); @@ -113,7 +114,6 @@ void main() { shorebirdArtifacts = MockShorebirdArtifacts(); shorebirdProcess = MockShorebirdProcess(); shorebirdEnv = MockShorebirdEnv(); - flutterValidator = MockShorebirdFlutterValidator(); shorebirdFlutter = MockShorebirdFlutter(); shorebirdValidator = MockShorebirdValidator(); xcodeBuild = MockXcodeBuild(); @@ -183,7 +183,7 @@ void main() { setUp(() { when( () => doctor.iosCommandValidators, - ).thenReturn([flutterValidator]); + ).thenReturn([flavorValidator]); }); group('when validation succeeds', () { @@ -249,7 +249,7 @@ void main() { () => shorebirdValidator.validatePreconditions( checkUserIsAuthenticated: true, checkShorebirdInitialized: true, - validators: [flutterValidator], + validators: [flavorValidator], supportedOperatingSystems: {Platform.macOS}, ), ).called(1); diff --git a/packages/shorebird_cli/test/src/commands/patch/ios_patcher_test.dart b/packages/shorebird_cli/test/src/commands/patch/ios_patcher_test.dart index 360e98cd..1388f83a 100644 --- a/packages/shorebird_cli/test/src/commands/patch/ios_patcher_test.dart +++ b/packages/shorebird_cli/test/src/commands/patch/ios_patcher_test.dart @@ -55,15 +55,15 @@ void main() { late CodePushClientWrapper codePushClientWrapper; late CodeSigner codeSigner; late Doctor doctor; - late EngineConfig engineConfig; late Directory flutterDirectory; late Directory projectRoot; + late EngineConfig engineConfig; + late FlavorValidator flavorValidator; late ShorebirdLogger logger; late OperatingSystemInterface operatingSystemInterface; late PatchDiffChecker patchDiffChecker; late Progress progress; late ShorebirdArtifacts shorebirdArtifacts; - late ShorebirdFlutterValidator flutterValidator; late ShorebirdProcess shorebirdProcess; late ShorebirdEnv shorebirdEnv; late ShorebirdFlutter shorebirdFlutter; @@ -117,6 +117,7 @@ void main() { codeSigner = MockCodeSigner(); doctor = MockDoctor(); engineConfig = MockEngineConfig(); + flavorValidator = MockFlavorValidator(); ios = MockIos(); operatingSystemInterface = MockOperatingSystemInterface(); patchDiffChecker = MockPatchDiffChecker(); @@ -126,7 +127,6 @@ void main() { shorebirdArtifacts = MockShorebirdArtifacts(); shorebirdProcess = MockShorebirdProcess(); shorebirdEnv = MockShorebirdEnv(); - flutterValidator = MockShorebirdFlutterValidator(); shorebirdFlutter = MockShorebirdFlutter(); shorebirdValidator = MockShorebirdValidator(); xcodeBuild = MockXcodeBuild(); @@ -195,7 +195,7 @@ void main() { setUp(() { when( () => doctor.iosCommandValidators, - ).thenReturn([flutterValidator]); + ).thenReturn([flavorValidator]); }); group('when validation succeeds', () { @@ -266,7 +266,7 @@ void main() { () => shorebirdValidator.validatePreconditions( checkUserIsAuthenticated: true, checkShorebirdInitialized: true, - validators: [flutterValidator], + validators: [flavorValidator], supportedOperatingSystems: {Platform.macOS}, ), ).called(1); diff --git a/packages/shorebird_cli/test/src/commands/patch/macos_patcher_test.dart b/packages/shorebird_cli/test/src/commands/patch/macos_patcher_test.dart index d3022393..ac6bf0aa 100644 --- a/packages/shorebird_cli/test/src/commands/patch/macos_patcher_test.dart +++ b/packages/shorebird_cli/test/src/commands/patch/macos_patcher_test.dart @@ -59,12 +59,12 @@ void main() { late Directory flutterDirectory; late Directory projectRoot; late Directory appDirectory; + late FlavorValidator flavorValidator; late ShorebirdLogger logger; late OperatingSystemInterface operatingSystemInterface; late PatchDiffChecker patchDiffChecker; late Progress progress; late ShorebirdArtifacts shorebirdArtifacts; - late ShorebirdFlutterValidator flutterValidator; late ShorebirdProcess shorebirdProcess; late ShorebirdEnv shorebirdEnv; late ShorebirdFlutter shorebirdFlutter; @@ -117,6 +117,7 @@ void main() { codeSigner = MockCodeSigner(); doctor = MockDoctor(); engineConfig = MockEngineConfig(); + flavorValidator = MockFlavorValidator(); operatingSystemInterface = MockOperatingSystemInterface(); patchDiffChecker = MockPatchDiffChecker(); progress = MockProgress(); @@ -125,7 +126,6 @@ void main() { shorebirdArtifacts = MockShorebirdArtifacts(); shorebirdProcess = MockShorebirdProcess(); shorebirdEnv = MockShorebirdEnv(); - flutterValidator = MockShorebirdFlutterValidator(); shorebirdFlutter = MockShorebirdFlutter(); shorebirdValidator = MockShorebirdValidator(); xcodeBuild = MockXcodeBuild(); @@ -222,7 +222,7 @@ void main() { setUp(() { when( () => doctor.macosCommandValidators, - ).thenReturn([flutterValidator]); + ).thenReturn([flavorValidator]); }); group('when validation succeeds', () { @@ -293,7 +293,7 @@ void main() { () => shorebirdValidator.validatePreconditions( checkUserIsAuthenticated: true, checkShorebirdInitialized: true, - validators: [flutterValidator], + validators: [flavorValidator], supportedOperatingSystems: {Platform.macOS}, ), ).called(1); diff --git a/packages/shorebird_cli/test/src/commands/release/android_releaser_test.dart b/packages/shorebird_cli/test/src/commands/release/android_releaser_test.dart index bdeef8c5..a74c007b 100644 --- a/packages/shorebird_cli/test/src/commands/release/android_releaser_test.dart +++ b/packages/shorebird_cli/test/src/commands/release/android_releaser_test.dart @@ -39,10 +39,10 @@ void main() { late CodeSigner codeSigner; late Doctor doctor; late Directory projectRoot; + late FlavorValidator flavorValidator; late ShorebirdLogger logger; late OperatingSystemInterface operatingSystemInterface; late Progress progress; - late ShorebirdFlutterValidator flutterValidator; late ShorebirdProcess shorebirdProcess; late ShorebirdEnv shorebirdEnv; late ShorebirdFlutter shorebirdFlutter; @@ -83,11 +83,11 @@ void main() { codePushClientWrapper = MockCodePushClientWrapper(); codeSigner = MockCodeSigner(); doctor = MockDoctor(); + flavorValidator = MockFlavorValidator(); operatingSystemInterface = MockOperatingSystemInterface(); progress = MockProgress(); projectRoot = Directory.systemTemp.createTempSync(); logger = MockShorebirdLogger(); - flutterValidator = MockShorebirdFlutterValidator(); shorebirdProcess = MockShorebirdProcess(); shorebirdEnv = MockShorebirdEnv(); shorebirdFlutter = MockShorebirdFlutter(); @@ -121,8 +121,8 @@ void main() { group('assertPreconditions', () { setUp(() { when(() => doctor.androidCommandValidators) - .thenReturn([flutterValidator]); - when(flutterValidator.validate).thenAnswer((_) async => []); + .thenReturn([flavorValidator]); + when(flavorValidator.validate).thenAnswer((_) async => []); }); group('when validation succeeds', () { @@ -178,7 +178,7 @@ void main() { () => shorebirdValidator.validatePreconditions( checkUserIsAuthenticated: true, checkShorebirdInitialized: true, - validators: [flutterValidator], + validators: [flavorValidator], ), ).called(1); }); diff --git a/packages/shorebird_cli/test/src/commands/release/ios_framework_releaser_test.dart b/packages/shorebird_cli/test/src/commands/release/ios_framework_releaser_test.dart index 95ffdbfb..5ebb2e25 100644 --- a/packages/shorebird_cli/test/src/commands/release/ios_framework_releaser_test.dart +++ b/packages/shorebird_cli/test/src/commands/release/ios_framework_releaser_test.dart @@ -42,10 +42,10 @@ void main() { late CodePushClientWrapper codePushClientWrapper; late Doctor doctor; late Directory projectRoot; + late FlavorValidator flavorValidator; late ShorebirdLogger logger; late OperatingSystemInterface operatingSystemInterface; late Progress progress; - late ShorebirdFlutterValidator flutterValidator; late ShorebirdProcess shorebirdProcess; late ShorebirdEnv shorebirdEnv; late ShorebirdFlutter shorebirdFlutter; @@ -83,13 +83,13 @@ void main() { artifactManager = MockArtifactManager(); codePushClientWrapper = MockCodePushClientWrapper(); doctor = MockDoctor(); + flavorValidator = MockFlavorValidator(); operatingSystemInterface = MockOperatingSystemInterface(); progress = MockProgress(); projectRoot = Directory.systemTemp.createTempSync(); logger = MockShorebirdLogger(); shorebirdProcess = MockShorebirdProcess(); shorebirdEnv = MockShorebirdEnv(); - flutterValidator = MockShorebirdFlutterValidator(); shorebirdFlutter = MockShorebirdFlutter(); shorebirdValidator = MockShorebirdValidator(); xcodeBuild = MockXcodeBuild(); @@ -159,10 +159,10 @@ void main() { setUp(() { when( () => doctor.iosCommandValidators, - ).thenReturn([flutterValidator]); + ).thenReturn([flavorValidator]); when(() => shorebirdFlutter.resolveFlutterVersion(any())) .thenAnswer((_) async => flutterVersion); - when(flutterValidator.validate).thenAnswer((_) async => []); + when(flavorValidator.validate).thenAnswer((_) async => []); }); group('when validation succeeds', () { @@ -220,7 +220,7 @@ void main() { () => shorebirdValidator.validatePreconditions( checkUserIsAuthenticated: true, checkShorebirdInitialized: true, - validators: [flutterValidator], + validators: [flavorValidator], supportedOperatingSystems: {Platform.macOS}, ), ).called(1); diff --git a/packages/shorebird_cli/test/src/commands/release/ios_releaser_test.dart b/packages/shorebird_cli/test/src/commands/release/ios_releaser_test.dart index 2c975812..a5221212 100644 --- a/packages/shorebird_cli/test/src/commands/release/ios_releaser_test.dart +++ b/packages/shorebird_cli/test/src/commands/release/ios_releaser_test.dart @@ -47,11 +47,11 @@ void main() { late CodeSigner codeSigner; late Directory projectRoot; late Doctor doctor; + late FlavorValidator flavorValidator; late Progress progress; late ShorebirdLogger logger; late Ios ios; late OperatingSystemInterface operatingSystemInterface; - late ShorebirdFlutterValidator flutterValidator; late ShorebirdProcess shorebirdProcess; late ShorebirdEnv shorebirdEnv; late ShorebirdFlutter shorebirdFlutter; @@ -93,12 +93,12 @@ void main() { codePushClientWrapper = MockCodePushClientWrapper(); codeSigner = MockCodeSigner(); doctor = MockDoctor(); + flavorValidator = MockFlavorValidator(); projectRoot = Directory.systemTemp.createTempSync(); operatingSystemInterface = MockOperatingSystemInterface(); progress = MockProgress(); logger = MockShorebirdLogger(); ios = MockIos(); - flutterValidator = MockShorebirdFlutterValidator(); shorebirdProcess = MockShorebirdProcess(); shorebirdEnv = MockShorebirdEnv(); shorebirdFlutter = MockShorebirdFlutter(); @@ -127,11 +127,10 @@ void main() { final flutterVersion = Version(3, 0, 0); setUp(() { - when(() => doctor.iosCommandValidators) - .thenReturn([flutterValidator]); + when(() => doctor.iosCommandValidators).thenReturn([flavorValidator]); when(() => shorebirdFlutter.resolveFlutterVersion(any())) .thenAnswer((_) async => flutterVersion); - when(flutterValidator.validate).thenAnswer((_) async => []); + when(flavorValidator.validate).thenAnswer((_) async => []); }); group('when validation succeeds', () { @@ -183,7 +182,7 @@ void main() { () => shorebirdValidator.validatePreconditions( checkUserIsAuthenticated: true, checkShorebirdInitialized: true, - validators: [flutterValidator], + validators: [flavorValidator], supportedOperatingSystems: {Platform.macOS}, ), ).called(1); diff --git a/packages/shorebird_cli/test/src/commands/release/macos_releaser_test.dart b/packages/shorebird_cli/test/src/commands/release/macos_releaser_test.dart index 5239298c..ea2a4e14 100644 --- a/packages/shorebird_cli/test/src/commands/release/macos_releaser_test.dart +++ b/packages/shorebird_cli/test/src/commands/release/macos_releaser_test.dart @@ -40,14 +40,11 @@ void main() { late ArtifactBuilder artifactBuilder; late ArtifactManager artifactManager; late CodePushClientWrapper codePushClientWrapper; - // late CodeSigner codeSigner; late Directory projectRoot; late Doctor doctor; + late FlavorValidator flavorValidator; late Progress progress; late ShorebirdLogger logger; - // late OperatingSystemInterface operatingSystemInterface; - late ShorebirdFlutterValidator flutterValidator; - // late ShorebirdProcess shorebirdProcess; late ShorebirdEnv shorebirdEnv; late ShorebirdFlutter shorebirdFlutter; late ShorebirdValidator shorebirdValidator; @@ -62,12 +59,8 @@ void main() { artifactBuilderRef.overrideWith(() => artifactBuilder), artifactManagerRef.overrideWith(() => artifactManager), codePushClientWrapperRef.overrideWith(() => codePushClientWrapper), - // codeSignerRef.overrideWith(() => codeSigner), doctorRef.overrideWith(() => doctor), - // iosRef.overrideWith(() => ios), loggerRef.overrideWith(() => logger), - // osInterfaceRef.overrideWith(() => operatingSystemInterface), - // processRef.overrideWith(() => shorebirdProcess), shorebirdEnvRef.overrideWith(() => shorebirdEnv), shorebirdFlutterRef.overrideWith(() => shorebirdFlutter), shorebirdValidatorRef.overrideWith(() => shorebirdValidator), @@ -81,15 +74,11 @@ void main() { artifactBuilder = MockArtifactBuilder(); artifactManager = MockArtifactManager(); codePushClientWrapper = MockCodePushClientWrapper(); - // codeSigner = MockCodeSigner(); doctor = MockDoctor(); + flavorValidator = MockFlavorValidator(); projectRoot = Directory.systemTemp.createTempSync(); - // operatingSystemInterface = MockOperatingSystemInterface(); progress = MockProgress(); logger = MockShorebirdLogger(); - // ios = MockIos(); - flutterValidator = MockShorebirdFlutterValidator(); - // shorebirdProcess = MockShorebirdProcess(); shorebirdEnv = MockShorebirdEnv(); shorebirdFlutter = MockShorebirdFlutter(); shorebirdValidator = MockShorebirdValidator(); @@ -118,10 +107,10 @@ void main() { setUp(() { when(() => doctor.macosCommandValidators) - .thenReturn([flutterValidator]); + .thenReturn([flavorValidator]); when(() => shorebirdFlutter.resolveFlutterVersion(any())) .thenAnswer((_) async => flutterVersion); - when(flutterValidator.validate).thenAnswer((_) async => []); + when(flavorValidator.validate).thenAnswer((_) async => []); }); group('when validation succeeds', () { @@ -173,7 +162,7 @@ void main() { () => shorebirdValidator.validatePreconditions( checkUserIsAuthenticated: true, checkShorebirdInitialized: true, - validators: [flutterValidator], + validators: [flavorValidator], supportedOperatingSystems: {Platform.macOS}, ), ).called(1); diff --git a/packages/shorebird_cli/test/src/mocks.dart b/packages/shorebird_cli/test/src/mocks.dart index 4038b394..87b61b20 100644 --- a/packages/shorebird_cli/test/src/mocks.dart +++ b/packages/shorebird_cli/test/src/mocks.dart @@ -95,6 +95,8 @@ class MockFile extends Mock implements File {} class MockFileSetDiff extends Mock implements FileSetDiff {} +class MockFlavorValidator extends Mock implements FlavorValidator {} + class MockGit extends Mock implements Git {} class MockGradlew extends Mock implements Gradlew {} @@ -157,9 +159,6 @@ class MockShorebirdEnv extends Mock implements ShorebirdEnv {} class MockShorebirdFlutter extends Mock implements ShorebirdFlutter {} -class MockShorebirdFlutterValidator extends Mock - implements ShorebirdFlutterValidator {} - class MockShorebirdLogger extends Mock implements ShorebirdLogger {} class MockShorebirdProcess extends Mock implements ShorebirdProcess {} diff --git a/packages/shorebird_cli/test/src/validators/shorebird_flutter_validator_test.dart b/packages/shorebird_cli/test/src/validators/shorebird_flutter_validator_test.dart deleted file mode 100644 index c38d04d6..00000000 --- a/packages/shorebird_cli/test/src/validators/shorebird_flutter_validator_test.dart +++ /dev/null @@ -1,233 +0,0 @@ -import 'dart:io' hide Platform; - -import 'package:mocktail/mocktail.dart'; -import 'package:path/path.dart' as p; -import 'package:platform/platform.dart'; -import 'package:scoped_deps/scoped_deps.dart'; -import 'package:shorebird_cli/src/platform.dart'; -import 'package:shorebird_cli/src/shorebird_env.dart'; -import 'package:shorebird_cli/src/shorebird_flutter.dart'; -import 'package:shorebird_cli/src/validators/validators.dart'; -import 'package:test/test.dart'; - -import '../mocks.dart'; - -void main() { - group(ShorebirdFlutterValidator, () { - const flutterRevision = '45fc514f1a9c347a3af76b02baf980a4d88b7879'; - const flutterVersion = '3.7.9'; - - late ShorebirdFlutterValidator validator; - late Directory tempDir; - late ShorebirdEnv shorebirdEnv; - late ShorebirdFlutter shorebirdFlutter; - late Platform platform; - - R runWithOverrides(R Function() body) { - return runScoped( - () => body(), - values: { - platformRef.overrideWith(() => platform), - shorebirdEnvRef.overrideWith(() => shorebirdEnv), - shorebirdFlutterRef.overrideWith(() => shorebirdFlutter), - }, - ); - } - - Directory flutterDirectory(Directory root) => - Directory(p.join(root.path, 'bin', 'cache', 'flutter')); - - Directory setupTempDirectory() { - final tempDir = Directory.systemTemp.createTempSync(); - flutterDirectory(tempDir).createSync(recursive: true); - return tempDir; - } - - setUp(() { - tempDir = setupTempDirectory(); - platform = MockPlatform(); - shorebirdEnv = MockShorebirdEnv(); - shorebirdFlutter = MockShorebirdFlutter(); - - when(() => shorebirdEnv.flutterRevision).thenReturn(flutterRevision); - when( - () => shorebirdEnv.flutterDirectory, - ).thenReturn(flutterDirectory(tempDir)); - when(() => platform.environment).thenReturn({}); - when( - () => shorebirdFlutter.getVersionString(), - ).thenAnswer((_) async => flutterVersion); - when( - () => shorebirdFlutter.getSystemVersion(), - ).thenAnswer((_) async => flutterVersion); - - validator = ShorebirdFlutterValidator(); - when( - () => shorebirdFlutter.isUnmodified( - revision: any(named: 'revision'), - ), - ).thenAnswer((_) async => true); - }); - - test('has a non-empty description', () { - expect(validator.description, isNotEmpty); - }); - - test('canRunInContext always returns true', () { - expect(validator.canRunInCurrentContext(), isTrue); - }); - - test('returns no issues when the Flutter install is good', () async { - final results = await runWithOverrides(validator.validate); - - expect(results, isEmpty); - }); - - test('errors when Flutter does not exist', () async { - flutterDirectory(tempDir).deleteSync(); - - final results = await runWithOverrides(validator.validate); - - expect(results, hasLength(1)); - expect(results.first.severity, ValidationIssueSeverity.error); - expect(results.first.message, contains('No Flutter directory found')); - }); - - test('warns when Flutter has local modifications', () async { - when( - () => shorebirdFlutter.isUnmodified( - revision: any(named: 'revision'), - ), - ).thenAnswer((_) async => false); - - final results = await runWithOverrides(validator.validate); - - expect(results, hasLength(1)); - expect(results.first.severity, ValidationIssueSeverity.warning); - expect(results.first.message, contains('has local modifications')); - }); - - test( - 'does not warn if system flutter does not exist', - () async { - when( - () => shorebirdFlutter.getSystemVersion(), - ).thenThrow(const ProcessException('flutter', ['--version'], '', 127)); - - final results = await runWithOverrides( - () => validator.validate(), - ); - - expect(results, isEmpty); - }, - ); - - test( - 'does not warn if flutter version and shorebird flutter version have same' - ' major and minor but different patch versions', - () async { - when( - () => shorebirdFlutter.getSystemVersion(), - ).thenAnswer((_) async => '3.7.10'); - - final results = await runWithOverrides( - () => validator.validate(), - ); - - expect(results, isEmpty); - }, - ); - - test( - 'warns when path flutter version has different major or minor version ' - 'than shorebird flutter', - () async { - when( - () => shorebirdFlutter.getSystemVersion(), - ).thenAnswer((_) async => '3.8.9'); - - final results = await runWithOverrides(validator.validate); - - expect(results, hasLength(1)); - expect(results.first.severity, ValidationIssueSeverity.warning); - expect( - results.first.message, - contains( - 'The version of Flutter that Shorebird includes and the Flutter on ' - 'your path are different', - ), - ); - }, - ); - - test( - 'warns if FLUTTER_STORAGE_BASE_URL has a non-empty value', - () async { - when(() => platform.environment).thenReturn( - {'FLUTTER_STORAGE_BASE_URL': 'https://storage.flutter-io.cn'}, - ); - - final results = await runWithOverrides(validator.validate); - - expect(results, hasLength(1)); - expect(results.first.severity, ValidationIssueSeverity.warning); - expect( - results.first.message, - contains( - 'Shorebird does not respect the FLUTTER_STORAGE_BASE_URL ' - 'environment variable', - ), - ); - }, - ); - - test('throws exception if path flutter version lookup fails', () async { - when(() => shorebirdFlutter.getSystemVersion()).thenThrow( - const ProcessException( - 'flutter', - ['--version'], - 'OH NO THERE IS NO FLUTTER VERSION HERE', - 1, - ), - ); - - final results = await runWithOverrides(validator.validate); - - expect(results, hasLength(1)); - expect( - results[0], - isA().having( - (exception) => exception.message, - 'message', - contains('Failed to determine path Flutter version'), - ), - ); - }); - - test('throws exception if shorebird flutter version lookup fails', - () async { - when( - () => shorebirdFlutter.getVersionString(), - ).thenThrow( - const ProcessException( - 'flutter', - ['--version'], - 'OH NO THERE IS NO FLUTTER VERSION HERE', - 1, - ), - ); - - final results = await runWithOverrides(validator.validate); - - expect(results, hasLength(1)); - expect( - results[0], - isA().having( - (exception) => exception.message, - 'message', - contains('Failed to determine Shorebird Flutter version'), - ), - ); - }); - }); -}