diff --git a/script/tool/lib/src/update_dependency_command.dart b/script/tool/lib/src/update_dependency_command.dart index d28e1031938..02c118e0d20 100644 --- a/script/tool/lib/src/update_dependency_command.dart +++ b/script/tool/lib/src/update_dependency_command.dart @@ -138,12 +138,16 @@ ${response.httpResponse.body} printError('A version must be provided to update this dependency.'); throw ToolExit(_exitNoTargetVersion); } else if (_targetAndroidDependency == _AndroidDepdencyType.gradle) { - final RegExp validGradleVersionPattern = RegExp(r'^\d+(?:\.\d+){1,2}$'); + final RegExp validGradleVersionPattern = + RegExp(r'^\d{1,2}\.\d{1,2}(?:\.\d)?$'); final bool isValidGradleVersion = validGradleVersionPattern.stringMatch(version) == version; if (!isValidGradleVersion) { - printError( - 'A version with a valid format (maximum 2-3 numbers separated by period) must be provided.'); + printError(''' +A version with a valid format (maximum 2-3 numbers separated by 1-2 periods) must be provided. + 1. The first number must have one or two digits + 2. The second number must have one or two digits + 3. If present, the third number must have a single digit'''); throw ToolExit(_exitInvalidTargetVersion); } } else if (_targetAndroidDependency == _AndroidDepdencyType.compileSdk || diff --git a/script/tool/test/update_dependency_command_test.dart b/script/tool/test/update_dependency_command_test.dart index 2770e3e7d1f..6488c673fe4 100644 --- a/script/tool/test/update_dependency_command_test.dart +++ b/script/tool/test/update_dependency_command_test.dart @@ -608,27 +608,40 @@ dev_dependencies: group('Android dependencies', () { group('gradle', () { - test('throws if version format is invalid', () async { - Error? commandError; - final List output = await runCapturingPrint(runner, [ - 'update-dependency', - '--android-dependency', - 'gradle', - '--version', - '83', - ], errorHandler: (Error e) { - commandError = e; - }); + final List invalidGradleVersionsFormat = [ + '81', + '811.1', + '8.123', + '8.12.12' + ]; - expect(commandError, isA()); - expect( - output, - containsAllInOrder([ - contains( - 'A version with a valid format (maximum 2-3 numbers separated by period) must be provided.'), - ]), - ); - }); + for (final String gradleVersion in invalidGradleVersionsFormat) { + test('throws because gradleVersion: $gradleVersion is invalid', + () async { + Error? commandError; + final List output = await runCapturingPrint(runner, [ + 'update-dependency', + '--android-dependency', + 'gradle', + '--version', + gradleVersion, + ], errorHandler: (Error e) { + commandError = e; + }); + + expect(commandError, isA()); + expect( + output, + containsAllInOrder([ + contains(''' +A version with a valid format (maximum 2-3 numbers separated by 1-2 periods) must be provided. + 1. The first number must have one or two digits + 2. The second number must have one or two digits + 3. If present, the third number must have a single digit'''), + ]), + ); + }); + } test('skips if example app does not run on Android', () async { final RepositoryPackage package =