Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[package_config] Fix incorrect error message when validating parameters in LanguageVersion.new #2017

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkgs/package_config/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.1.2-wip

- Include correct parameter names in errors when validating
the `major` and `minor` versions in the `LanguageVersion.new` constructor.

## 2.1.1

- Require Dart 3.4
Expand Down
8 changes: 7 additions & 1 deletion pkgs/package_config/lib/src/package_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,15 @@ abstract class Package {
abstract class LanguageVersion implements Comparable<LanguageVersion> {
/// The maximal value allowed by [major] and [minor] values;
static const int maxValue = 0x7FFFFFFF;

/// Constructs a [LanguageVersion] with the specified
/// [major] and [minor] version numbers.
///
/// Both [major] and [minor] must be greater than or equal to 0
/// and less than or equal to [maxValue].
factory LanguageVersion(int major, int minor) {
RangeError.checkValueInInterval(major, 0, maxValue, 'major');
RangeError.checkValueInInterval(minor, 0, maxValue, 'major');
RangeError.checkValueInInterval(minor, 0, maxValue, 'minor');
return SimpleLanguageVersion(major, minor, null);
}

Expand Down
2 changes: 1 addition & 1 deletion pkgs/package_config/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: package_config
version: 2.1.1
version: 2.1.2-wip
description: Support for reading and writing Dart Package Configuration files.
repository: https://github.com/dart-lang/tools/tree/main/pkgs/package_config
issue_tracker: https://github.com/dart-lang/tools/labels/package%3Apackage_config
Expand Down
16 changes: 14 additions & 2 deletions pkgs/package_config/test/package_config_impl_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,23 @@ void main() {
});

test('negative major', () {
expect(() => LanguageVersion(-1, 1), throwsArgumentError);
expect(
() => LanguageVersion(-1, 1),
throwsA(isA<RangeError>().having(
(e) => e.name,
'message',
contains('major'),
)));
});

test('negative minor', () {
expect(() => LanguageVersion(1, -1), throwsArgumentError);
expect(
() => LanguageVersion(1, -1),
throwsA(isA<RangeError>().having(
(e) => e.name,
'message',
contains('minor'),
)));
});

test('minimal parse', () {
Expand Down