From 4d9d72fc156025f09b480fca2721ca52f4c2da81 Mon Sep 17 00:00:00 2001 From: Sigurd Meldgaard Date: Mon, 8 Sep 2025 13:35:54 +0000 Subject: [PATCH 1/7] Handle tag_pattern in git dependencies --- pkgs/pubspec_parse/lib/src/dependency.dart | 65 +++++++++++++++----- pkgs/pubspec_parse/lib/src/dependency.g.dart | 4 ++ pkgs/pubspec_parse/test/dependency_test.dart | 26 ++++++-- 3 files changed, 76 insertions(+), 19 deletions(-) diff --git a/pkgs/pubspec_parse/lib/src/dependency.dart b/pkgs/pubspec_parse/lib/src/dependency.dart index 24c65eac1..d29292b25 100644 --- a/pkgs/pubspec_parse/lib/src/dependency.dart +++ b/pkgs/pubspec_parse/lib/src/dependency.dart @@ -75,7 +75,7 @@ Dependency? _fromJson(Object? data, String name) { final key = matchedKeys.single; return switch (key) { - 'git' => GitDependency.fromData(data[key]), + 'git' => GitDependency.fromJson(data), 'path' => PathDependency.fromData(data[key]), 'sdk' => _$SdkDependencyFromJson(data), 'hosted' => _$HostedDependencyFromJson(data) @@ -118,19 +118,56 @@ class GitDependency extends Dependency { final Uri url; final String? ref; final String? path; - - GitDependency(this.url, {this.ref, this.path}); - - factory GitDependency.fromData(Object? data) { - if (data is String) { - data = {'url': data}; - } - - if (data is Map) { - return _$GitDependencyFromJson(data); - } - - throw ArgumentError.value(data, 'git', 'Must be a String or a Map.'); + final String? tagPattern; + final VersionConstraint? version; + + GitDependency(this.url, {this.ref, this.path, this.tagPattern, this.version}); + + factory GitDependency.fromJson(Map data) { + final version = switch (data['version']) { + final String? s => _constraintFromString(s), + _ => null, + }; + final gitData = switch (data['git']) { + final String s => {'url': s}, + final Map m => m, + _ => throw ArgumentError.value( + data['git'], + 'git', + 'Must be a string or map.', + ), + }; + final url = switch (gitData['url']) { + final String s => parseGitUri(s), + _ => + throw ArgumentError.value(gitData['url'], 'url', 'Must be a String.'), + }; + final ref = switch (gitData['ref']) { + final String? s => s, + _ => + throw ArgumentError.value(gitData['ref'], 'ref', 'Must be a String.'), + }; + final path = switch (gitData['path']) { + final String? s => s, + _ => + throw ArgumentError.value(gitData['path'], 'path', 'Must be a String.'), + }; + final tagPattern = switch (gitData['tag_pattern']) { + final String? s => s, + _ => throw ArgumentError.value( + gitData['tagPattern'], + 'tagPattern', + 'Must be a String.', + ), + }; + + return GitDependency( + url, + ref: ref, + path: path, + tagPattern: tagPattern, + version: version, + ); } @override diff --git a/pkgs/pubspec_parse/lib/src/dependency.g.dart b/pkgs/pubspec_parse/lib/src/dependency.g.dart index 1a504f1fd..2429a5862 100644 --- a/pkgs/pubspec_parse/lib/src/dependency.g.dart +++ b/pkgs/pubspec_parse/lib/src/dependency.g.dart @@ -29,9 +29,13 @@ GitDependency _$GitDependencyFromJson(Map json) => $checkedCreate( $checkedConvert('url', (v) => parseGitUri(v as String)), ref: $checkedConvert('ref', (v) => v as String?), path: $checkedConvert('path', (v) => v as String?), + tagPattern: $checkedConvert('tag_pattern', (v) => v as String?), + version: $checkedConvert( + 'version', (v) => _constraintFromString(v as String?)), ); return val; }, + fieldKeyMap: const {'tagPattern': 'tag_pattern'}, ); HostedDependency _$HostedDependencyFromJson(Map json) => $checkedCreate( diff --git a/pkgs/pubspec_parse/test/dependency_test.dart b/pkgs/pubspec_parse/test/dependency_test.dart index f1e4f5776..c02400c9a 100644 --- a/pkgs/pubspec_parse/test/dependency_test.dart +++ b/pkgs/pubspec_parse/test/dependency_test.dart @@ -258,6 +258,22 @@ void _gitDependency() { expect(dep.toString(), 'GitDependency: url@url'); }); + test('tag_pattern works, and does not ignore version', () async { + final dep = await _dependency({ + 'git': { + 'url': 'url', + 'tag_pattern': 'v{{v}}', + }, + 'version': '^1.2.3', + }); + expect(dep.url.toString(), 'url'); + expect(dep.path, isNull); + expect(dep.ref, isNull); + expect(dep.tagPattern, 'v{{v}}'); + expect(dep.version.toString(), '^1.2.3'); + expect(dep.toString(), 'GitDependency: url@url'); + }); + test('string with user@ URL', () async { final skipTryParse = Platform.environment.containsKey('TRAVIS'); if (skipTryParse) { @@ -299,7 +315,7 @@ line 6, column 4: Unrecognized keys: [bob]; supported keys: [sdk, git, path, hos _expectThrows( {'git': null}, r''' -line 5, column 11: Unsupported value for "git". Must be a String or a Map. +line 5, column 11: Unsupported value for "git". Must be a string or map. ╷ 5 │ "git": null │ ┌───────────^ @@ -313,7 +329,7 @@ line 5, column 11: Unsupported value for "git". Must be a String or a Map. _expectThrows( {'git': 42}, r''' -line 5, column 11: Unsupported value for "git". Must be a String or a Map. +line 5, column 11: Unsupported value for "git". Must be a string or map. ╷ 5 │ "git": 42 │ ┌───────────^ @@ -326,7 +342,7 @@ line 5, column 11: Unsupported value for "git". Must be a String or a Map. test('git - empty map', () { _expectThrowsContaining( {'git': {}}, - r"type 'Null' is not a subtype of type 'String'", + r'Missing key "url". Must be a String', ); }); @@ -335,7 +351,7 @@ line 5, column 11: Unsupported value for "git". Must be a String or a Map. { 'git': {'url': null}, }, - r"type 'Null' is not a subtype of type 'String'", + r'Missing key "url". Must be a String', ); }); @@ -344,7 +360,7 @@ line 5, column 11: Unsupported value for "git". Must be a String or a Map. { 'git': {'url': 42}, }, - r"type 'int' is not a subtype of type 'String'", + r'Missing key "url". Must be a String', ); }); } From c295fdb2353896310ab52b01490a62004cf10166 Mon Sep 17 00:00:00 2001 From: Sigurd Meldgaard Date: Mon, 8 Sep 2025 13:40:47 +0000 Subject: [PATCH 2/7] Handle bad version constraints --- pkgs/pubspec_parse/lib/src/dependency.dart | 7 +- pkgs/pubspec_parse/lib/src/dependency.g.dart | 76 -------------------- pkgs/pubspec_parse/lib/src/pubspec.g.dart | 69 ------------------ 3 files changed, 5 insertions(+), 147 deletions(-) delete mode 100644 pkgs/pubspec_parse/lib/src/dependency.g.dart delete mode 100644 pkgs/pubspec_parse/lib/src/pubspec.g.dart diff --git a/pkgs/pubspec_parse/lib/src/dependency.dart b/pkgs/pubspec_parse/lib/src/dependency.dart index d29292b25..9cb82b58d 100644 --- a/pkgs/pubspec_parse/lib/src/dependency.dart +++ b/pkgs/pubspec_parse/lib/src/dependency.dart @@ -112,7 +112,6 @@ class SdkDependency extends Dependency { String toString() => 'SdkDependency: $sdk'; } -@JsonSerializable() class GitDependency extends Dependency { @JsonKey(fromJson: parseGitUri) final Uri url; @@ -126,7 +125,11 @@ class GitDependency extends Dependency { factory GitDependency.fromJson(Map data) { final version = switch (data['version']) { final String? s => _constraintFromString(s), - _ => null, + _ => throw ArgumentError.value( + data['version'], + 'version', + 'if present must be a string.', + ), }; final gitData = switch (data['git']) { final String s => {'url': s}, diff --git a/pkgs/pubspec_parse/lib/src/dependency.g.dart b/pkgs/pubspec_parse/lib/src/dependency.g.dart deleted file mode 100644 index 2429a5862..000000000 --- a/pkgs/pubspec_parse/lib/src/dependency.g.dart +++ /dev/null @@ -1,76 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ignore_for_file: deprecated_member_use_from_same_package, lines_longer_than_80_chars, require_trailing_commas, unnecessary_cast - -part of 'dependency.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -SdkDependency _$SdkDependencyFromJson(Map json) => $checkedCreate( - 'SdkDependency', - json, - ($checkedConvert) { - final val = SdkDependency( - $checkedConvert('sdk', (v) => v as String), - version: $checkedConvert( - 'version', (v) => _constraintFromString(v as String?)), - ); - return val; - }, - ); - -GitDependency _$GitDependencyFromJson(Map json) => $checkedCreate( - 'GitDependency', - json, - ($checkedConvert) { - final val = GitDependency( - $checkedConvert('url', (v) => parseGitUri(v as String)), - ref: $checkedConvert('ref', (v) => v as String?), - path: $checkedConvert('path', (v) => v as String?), - tagPattern: $checkedConvert('tag_pattern', (v) => v as String?), - version: $checkedConvert( - 'version', (v) => _constraintFromString(v as String?)), - ); - return val; - }, - fieldKeyMap: const {'tagPattern': 'tag_pattern'}, - ); - -HostedDependency _$HostedDependencyFromJson(Map json) => $checkedCreate( - 'HostedDependency', - json, - ($checkedConvert) { - $checkKeys( - json, - allowedKeys: const ['version', 'hosted'], - disallowNullValues: const ['hosted'], - ); - final val = HostedDependency( - version: $checkedConvert( - 'version', (v) => _constraintFromString(v as String?)), - hosted: $checkedConvert('hosted', - (v) => v == null ? null : HostedDetails.fromJson(v as Object)), - ); - return val; - }, - ); - -HostedDetails _$HostedDetailsFromJson(Map json) => $checkedCreate( - 'HostedDetails', - json, - ($checkedConvert) { - $checkKeys( - json, - allowedKeys: const ['name', 'url'], - disallowNullValues: const ['url'], - ); - final val = HostedDetails( - $checkedConvert('name', (v) => v as String?), - $checkedConvert('url', (v) => parseGitUriOrNull(v as String?)), - ); - return val; - }, - fieldKeyMap: const {'declaredName': 'name'}, - ); diff --git a/pkgs/pubspec_parse/lib/src/pubspec.g.dart b/pkgs/pubspec_parse/lib/src/pubspec.g.dart deleted file mode 100644 index 58e015a5e..000000000 --- a/pkgs/pubspec_parse/lib/src/pubspec.g.dart +++ /dev/null @@ -1,69 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ignore_for_file: deprecated_member_use_from_same_package, lines_longer_than_80_chars, require_trailing_commas, unnecessary_cast - -part of 'pubspec.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -Pubspec _$PubspecFromJson(Map json) => $checkedCreate( - 'Pubspec', - json, - ($checkedConvert) { - final val = Pubspec( - $checkedConvert('name', (v) => v as String), - version: $checkedConvert( - 'version', (v) => _versionFromString(v as String?)), - publishTo: $checkedConvert('publish_to', (v) => v as String?), - author: $checkedConvert('author', (v) => v as String?), - authors: $checkedConvert('authors', - (v) => (v as List?)?.map((e) => e as String).toList()), - environment: - $checkedConvert('environment', (v) => _environmentMap(v as Map?)), - homepage: $checkedConvert('homepage', (v) => v as String?), - repository: $checkedConvert( - 'repository', (v) => v == null ? null : Uri.parse(v as String)), - issueTracker: $checkedConvert('issue_tracker', - (v) => v == null ? null : Uri.parse(v as String)), - funding: $checkedConvert( - 'funding', - (v) => (v as List?) - ?.map((e) => Uri.parse(e as String)) - .toList()), - topics: $checkedConvert('topics', - (v) => (v as List?)?.map((e) => e as String).toList()), - ignoredAdvisories: $checkedConvert('ignored_advisories', - (v) => (v as List?)?.map((e) => e as String).toList()), - screenshots: $checkedConvert( - 'screenshots', (v) => parseScreenshots(v as List?)), - documentation: $checkedConvert('documentation', (v) => v as String?), - description: $checkedConvert('description', (v) => v as String?), - workspace: $checkedConvert('workspace', - (v) => (v as List?)?.map((e) => e as String).toList()), - resolution: $checkedConvert('resolution', (v) => v as String?), - dependencies: - $checkedConvert('dependencies', (v) => parseDeps(v as Map?)), - devDependencies: - $checkedConvert('dev_dependencies', (v) => parseDeps(v as Map?)), - dependencyOverrides: $checkedConvert( - 'dependency_overrides', (v) => parseDeps(v as Map?)), - flutter: $checkedConvert( - 'flutter', - (v) => (v as Map?)?.map( - (k, e) => MapEntry(k as String, e), - )), - executables: - $checkedConvert('executables', (v) => _executablesMap(v as Map?)), - ); - return val; - }, - fieldKeyMap: const { - 'publishTo': 'publish_to', - 'issueTracker': 'issue_tracker', - 'ignoredAdvisories': 'ignored_advisories', - 'devDependencies': 'dev_dependencies', - 'dependencyOverrides': 'dependency_overrides' - }, - ); From 4816a89cc97cb1146ab80aee91f464e12295e914 Mon Sep 17 00:00:00 2001 From: Sigurd Meldgaard Date: Mon, 8 Sep 2025 13:41:55 +0000 Subject: [PATCH 3/7] Fix tag pattern error message --- pkgs/pubspec_parse/lib/src/dependency.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/pubspec_parse/lib/src/dependency.dart b/pkgs/pubspec_parse/lib/src/dependency.dart index 9cb82b58d..093ce24fa 100644 --- a/pkgs/pubspec_parse/lib/src/dependency.dart +++ b/pkgs/pubspec_parse/lib/src/dependency.dart @@ -158,8 +158,8 @@ class GitDependency extends Dependency { final tagPattern = switch (gitData['tag_pattern']) { final String? s => s, _ => throw ArgumentError.value( - gitData['tagPattern'], - 'tagPattern', + gitData['tag_pattern'], + 'tag_pattern', 'Must be a String.', ), }; From 97f8f55cadca5ea7fc1f8afd7404ced8eda614ff Mon Sep 17 00:00:00 2001 From: Sigurd Meldgaard Date: Mon, 8 Sep 2025 13:43:54 +0000 Subject: [PATCH 4/7] Reinstate generated files --- pkgs/pubspec_parse/lib/src/dependency.g.dart | 59 +++++++++++++++++ pkgs/pubspec_parse/lib/src/pubspec.g.dart | 69 ++++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 pkgs/pubspec_parse/lib/src/dependency.g.dart create mode 100644 pkgs/pubspec_parse/lib/src/pubspec.g.dart diff --git a/pkgs/pubspec_parse/lib/src/dependency.g.dart b/pkgs/pubspec_parse/lib/src/dependency.g.dart new file mode 100644 index 000000000..11ce96af5 --- /dev/null +++ b/pkgs/pubspec_parse/lib/src/dependency.g.dart @@ -0,0 +1,59 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +// ignore_for_file: deprecated_member_use_from_same_package, lines_longer_than_80_chars, require_trailing_commas, unnecessary_cast + +part of 'dependency.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +SdkDependency _$SdkDependencyFromJson(Map json) => $checkedCreate( + 'SdkDependency', + json, + ($checkedConvert) { + final val = SdkDependency( + $checkedConvert('sdk', (v) => v as String), + version: $checkedConvert( + 'version', (v) => _constraintFromString(v as String?)), + ); + return val; + }, + ); + +HostedDependency _$HostedDependencyFromJson(Map json) => $checkedCreate( + 'HostedDependency', + json, + ($checkedConvert) { + $checkKeys( + json, + allowedKeys: const ['version', 'hosted'], + disallowNullValues: const ['hosted'], + ); + final val = HostedDependency( + version: $checkedConvert( + 'version', (v) => _constraintFromString(v as String?)), + hosted: $checkedConvert('hosted', + (v) => v == null ? null : HostedDetails.fromJson(v as Object)), + ); + return val; + }, + ); + +HostedDetails _$HostedDetailsFromJson(Map json) => $checkedCreate( + 'HostedDetails', + json, + ($checkedConvert) { + $checkKeys( + json, + allowedKeys: const ['name', 'url'], + disallowNullValues: const ['url'], + ); + final val = HostedDetails( + $checkedConvert('name', (v) => v as String?), + $checkedConvert('url', (v) => parseGitUriOrNull(v as String?)), + ); + return val; + }, + fieldKeyMap: const {'declaredName': 'name'}, + ); diff --git a/pkgs/pubspec_parse/lib/src/pubspec.g.dart b/pkgs/pubspec_parse/lib/src/pubspec.g.dart new file mode 100644 index 000000000..58e015a5e --- /dev/null +++ b/pkgs/pubspec_parse/lib/src/pubspec.g.dart @@ -0,0 +1,69 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +// ignore_for_file: deprecated_member_use_from_same_package, lines_longer_than_80_chars, require_trailing_commas, unnecessary_cast + +part of 'pubspec.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +Pubspec _$PubspecFromJson(Map json) => $checkedCreate( + 'Pubspec', + json, + ($checkedConvert) { + final val = Pubspec( + $checkedConvert('name', (v) => v as String), + version: $checkedConvert( + 'version', (v) => _versionFromString(v as String?)), + publishTo: $checkedConvert('publish_to', (v) => v as String?), + author: $checkedConvert('author', (v) => v as String?), + authors: $checkedConvert('authors', + (v) => (v as List?)?.map((e) => e as String).toList()), + environment: + $checkedConvert('environment', (v) => _environmentMap(v as Map?)), + homepage: $checkedConvert('homepage', (v) => v as String?), + repository: $checkedConvert( + 'repository', (v) => v == null ? null : Uri.parse(v as String)), + issueTracker: $checkedConvert('issue_tracker', + (v) => v == null ? null : Uri.parse(v as String)), + funding: $checkedConvert( + 'funding', + (v) => (v as List?) + ?.map((e) => Uri.parse(e as String)) + .toList()), + topics: $checkedConvert('topics', + (v) => (v as List?)?.map((e) => e as String).toList()), + ignoredAdvisories: $checkedConvert('ignored_advisories', + (v) => (v as List?)?.map((e) => e as String).toList()), + screenshots: $checkedConvert( + 'screenshots', (v) => parseScreenshots(v as List?)), + documentation: $checkedConvert('documentation', (v) => v as String?), + description: $checkedConvert('description', (v) => v as String?), + workspace: $checkedConvert('workspace', + (v) => (v as List?)?.map((e) => e as String).toList()), + resolution: $checkedConvert('resolution', (v) => v as String?), + dependencies: + $checkedConvert('dependencies', (v) => parseDeps(v as Map?)), + devDependencies: + $checkedConvert('dev_dependencies', (v) => parseDeps(v as Map?)), + dependencyOverrides: $checkedConvert( + 'dependency_overrides', (v) => parseDeps(v as Map?)), + flutter: $checkedConvert( + 'flutter', + (v) => (v as Map?)?.map( + (k, e) => MapEntry(k as String, e), + )), + executables: + $checkedConvert('executables', (v) => _executablesMap(v as Map?)), + ); + return val; + }, + fieldKeyMap: const { + 'publishTo': 'publish_to', + 'issueTracker': 'issue_tracker', + 'ignoredAdvisories': 'ignored_advisories', + 'devDependencies': 'dev_dependencies', + 'dependencyOverrides': 'dependency_overrides' + }, + ); From 23db882a735058586c19815c89807798088d8f97 Mon Sep 17 00:00:00 2001 From: Sigurd Meldgaard Date: Mon, 8 Sep 2025 13:49:42 +0000 Subject: [PATCH 5/7] Changelog --- pkgs/pubspec_parse/CHANGELOG.md | 4 ++++ pkgs/pubspec_parse/pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pkgs/pubspec_parse/CHANGELOG.md b/pkgs/pubspec_parse/CHANGELOG.md index 5aeb49802..8f3ec36bf 100644 --- a/pkgs/pubspec_parse/CHANGELOG.md +++ b/pkgs/pubspec_parse/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.6.0 + +- Supports 'tag_pattern's via `GitDependency.tagPattern`. + ## 1.5.0 - Added fields to `Pubspec`: `executables`, `resolution`, `workspace`. diff --git a/pkgs/pubspec_parse/pubspec.yaml b/pkgs/pubspec_parse/pubspec.yaml index 90741efff..4a5f4568f 100644 --- a/pkgs/pubspec_parse/pubspec.yaml +++ b/pkgs/pubspec_parse/pubspec.yaml @@ -1,5 +1,5 @@ name: pubspec_parse -version: 1.5.0 +version: 1.6.0-wip description: >- Simple package for parsing pubspec.yaml files with a type-safe API and rich error reporting. From c103e01be050ad6cf4cd371a01afcaf242a06ca9 Mon Sep 17 00:00:00 2001 From: Sigurd Meldgaard Date: Mon, 8 Sep 2025 13:52:21 +0000 Subject: [PATCH 6/7] Changelog2 --- pkgs/pubspec_parse/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/pubspec_parse/CHANGELOG.md b/pkgs/pubspec_parse/CHANGELOG.md index 8f3ec36bf..5ead924a1 100644 --- a/pkgs/pubspec_parse/CHANGELOG.md +++ b/pkgs/pubspec_parse/CHANGELOG.md @@ -1,4 +1,4 @@ -## 1.6.0 +## 1.6.0-wip - Supports 'tag_pattern's via `GitDependency.tagPattern`. From 0b3a46971a70101260ef6cb41161571b632be266 Mon Sep 17 00:00:00 2001 From: Sigurd Meldgaard Date: Mon, 8 Sep 2025 14:05:45 +0000 Subject: [PATCH 7/7] language version in test --- pkgs/pubspec_parse/test/dependency_test.dart | 20 +++--- pkgs/pubspec_parse/test/parse_test.dart | 72 ++++++++++---------- pkgs/pubspec_parse/test/test_utils.dart | 8 +-- 3 files changed, 52 insertions(+), 48 deletions(-) diff --git a/pkgs/pubspec_parse/test/dependency_test.dart b/pkgs/pubspec_parse/test/dependency_test.dart index c02400c9a..6b4f3046a 100644 --- a/pkgs/pubspec_parse/test/dependency_test.dart +++ b/pkgs/pubspec_parse/test/dependency_test.dart @@ -259,17 +259,20 @@ void _gitDependency() { }); test('tag_pattern works, and does not ignore version', () async { - final dep = await _dependency({ - 'git': { - 'url': 'url', - 'tag_pattern': 'v{{v}}', + final dep = await _dependency( + { + 'git': { + 'url': 'url', + 'tag_pattern': 'v{{version}}', + }, + 'version': '^1.2.3', }, - 'version': '^1.2.3', - }); + languageVersion: '3.9', + ); expect(dep.url.toString(), 'url'); expect(dep.path, isNull); expect(dep.ref, isNull); - expect(dep.tagPattern, 'v{{v}}'); + expect(dep.tagPattern, 'v{{version}}'); expect(dep.version.toString(), '^1.2.3'); expect(dep.toString(), 'GitDependency: url@url'); }); @@ -444,10 +447,11 @@ void _expectThrowsContaining(Object content, String errorText) { Future _dependency( Object? content, { bool skipTryPub = false, + String languageVersion = '2.12', }) async { final value = await parse( { - ...defaultPubspec, + ...defaultPubspec(languageVersion: languageVersion), 'dependencies': {'dep': content}, }, skipTryPub: skipTryPub, diff --git a/pkgs/pubspec_parse/test/parse_test.dart b/pkgs/pubspec_parse/test/parse_test.dart index e0698af16..185a6e82a 100644 --- a/pkgs/pubspec_parse/test/parse_test.dart +++ b/pkgs/pubspec_parse/test/parse_test.dart @@ -12,7 +12,7 @@ import 'test_utils.dart'; void main() { test('minimal set values', () async { - final value = await parse(defaultPubspec); + final value = await parse(defaultPubspec()); expect(value.name, 'sample'); expect(value.version, isNull); expect(value.publishTo, isNull); @@ -167,7 +167,7 @@ line 3, column 16: Unsupported value for "publish_to". Must be an http or https }.entries) { test('can be ${entry.key}', () async { final value = await parse({ - ...defaultPubspec, + ...defaultPubspec(), 'publish_to': entry.value, }); expect(value.publishTo, entry.value); @@ -178,7 +178,7 @@ line 3, column 16: Unsupported value for "publish_to". Must be an http or https group('author, authors', () { test('one author', () async { final value = await parse({ - ...defaultPubspec, + ...defaultPubspec(), 'author': 'name@example.com', }); expect(value.author, 'name@example.com'); @@ -187,7 +187,7 @@ line 3, column 16: Unsupported value for "publish_to". Must be an http or https test('one author, via authors', () async { final value = await parse({ - ...defaultPubspec, + ...defaultPubspec(), 'authors': ['name@example.com'], }); expect(value.author, 'name@example.com'); @@ -196,7 +196,7 @@ line 3, column 16: Unsupported value for "publish_to". Must be an http or https test('many authors', () async { final value = await parse({ - ...defaultPubspec, + ...defaultPubspec(), 'authors': ['name@example.com', 'name2@example.com'], }); expect(value.author, isNull); @@ -205,7 +205,7 @@ line 3, column 16: Unsupported value for "publish_to". Must be an http or https test('author and authors', () async { final value = await parse({ - ...defaultPubspec, + ...defaultPubspec(), 'author': 'name@example.com', 'authors': ['name2@example.com'], }); @@ -215,7 +215,7 @@ line 3, column 16: Unsupported value for "publish_to". Must be an http or https test('duplicate author values', () async { final value = await parse({ - ...defaultPubspec, + ...defaultPubspec(), 'author': 'name@example.com', 'authors': ['name@example.com', 'name@example.com'], }); @@ -225,7 +225,7 @@ line 3, column 16: Unsupported value for "publish_to". Must be an http or https test('flutter', () async { final value = await parse({ - ...defaultPubspec, + ...defaultPubspec(), 'flutter': {'key': 'value'}, }); expect(value.flutter, {'key': 'value'}); @@ -235,7 +235,7 @@ line 3, column 16: Unsupported value for "publish_to". Must be an http or https group('executables', () { test('one executable', () async { final value = await parse({ - ...defaultPubspec, + ...defaultPubspec(), 'executables': {'my_script': 'bin/my_script.dart'}, }); expect(value.executables, hasLength(1)); @@ -245,7 +245,7 @@ line 3, column 16: Unsupported value for "publish_to". Must be an http or https test('many executables', () async { final value = await parse({ - ...defaultPubspec, + ...defaultPubspec(), 'executables': { 'my_script': 'bin/my_script.dart', 'my_script2': 'bin/my_script2.dart', @@ -261,7 +261,7 @@ line 3, column 16: Unsupported value for "publish_to". Must be an http or https test('invalid value', () async { expectParseThrowsContaining( { - ...defaultPubspec, + ...defaultPubspec(), 'executables': { 'script': 32, }, @@ -274,7 +274,7 @@ line 3, column 16: Unsupported value for "publish_to". Must be an http or https test('invalid executable - lenient', () async { final value = await parse( { - ...defaultPubspec, + ...defaultPubspec(), 'executables': 'Invalid value', }, lenient: true, @@ -407,7 +407,7 @@ line 4, column 10: Unsupported value for "sdk". Could not parse version "silly". test('bad repository url', () { expectParseThrowsContaining( { - ...defaultPubspec, + ...defaultPubspec(), 'repository': {'x': 'y'}, }, "Unsupported value for \"repository\". type 'YamlMap' is not a subtype of type 'String'", @@ -431,7 +431,7 @@ line 4, column 10: Unsupported value for "sdk". Could not parse version "silly". test('not a list', () { expectParseThrowsContaining( { - ...defaultPubspec, + ...defaultPubspec(), 'funding': 1, }, "Unsupported value for \"funding\". type 'int' is not a subtype of type 'List?'", @@ -442,7 +442,7 @@ line 4, column 10: Unsupported value for "sdk". Could not parse version "silly". test('not an uri', () { expectParseThrowsContaining( { - ...defaultPubspec, + ...defaultPubspec(), 'funding': [1], }, "Unsupported value for \"funding\". type 'int' is not a subtype of type 'String'", @@ -453,7 +453,7 @@ line 4, column 10: Unsupported value for "sdk". Could not parse version "silly". test('not an uri', () { expectParseThrows( { - ...defaultPubspec, + ...defaultPubspec(), 'funding': ['ht tps://example.com/'], }, r''' @@ -472,7 +472,7 @@ line 6, column 13: Unsupported value for "funding". Illegal scheme character at test('not a list', () { expectParseThrowsContaining( { - ...defaultPubspec, + ...defaultPubspec(), 'topics': 1, }, "Unsupported value for \"topics\". type 'int' is not a subtype of type 'List?'", @@ -483,7 +483,7 @@ line 6, column 13: Unsupported value for "funding". Illegal scheme character at test('not a string', () { expectParseThrowsContaining( { - ...defaultPubspec, + ...defaultPubspec(), 'topics': [1], }, "Unsupported value for \"topics\". type 'int' is not a subtype of type 'String'", @@ -494,7 +494,7 @@ line 6, column 13: Unsupported value for "funding". Illegal scheme character at test('invalid data - lenient', () async { final value = await parse( { - ...defaultPubspec, + ...defaultPubspec(), 'topics': [1], }, skipTryPub: true, @@ -509,7 +509,7 @@ line 6, column 13: Unsupported value for "funding". Illegal scheme character at test('not a list', () { expectParseThrowsContaining( { - ...defaultPubspec, + ...defaultPubspec(), 'ignored_advisories': 1, }, "Unsupported value for \"ignored_advisories\". type 'int' is not a subtype of type 'List?'", @@ -520,7 +520,7 @@ line 6, column 13: Unsupported value for "funding". Illegal scheme character at test('not a string', () { expectParseThrowsContaining( { - ...defaultPubspec, + ...defaultPubspec(), 'ignored_advisories': [1], }, "Unsupported value for \"ignored_advisories\". type 'int' is not a subtype of type 'String'", @@ -531,7 +531,7 @@ line 6, column 13: Unsupported value for "funding". Illegal scheme character at test('invalid data - lenient', () async { final value = await parse( { - ...defaultPubspec, + ...defaultPubspec(), 'ignored_advisories': [1], }, skipTryPub: true, @@ -545,7 +545,7 @@ line 6, column 13: Unsupported value for "funding". Illegal scheme character at group('screenshots', () { test('one screenshot', () async { final value = await parse({ - ...defaultPubspec, + ...defaultPubspec(), 'screenshots': [ {'description': 'my screenshot', 'path': 'path/to/screenshot'}, ], @@ -557,7 +557,7 @@ line 6, column 13: Unsupported value for "funding". Illegal scheme character at test('many screenshots', () async { final value = await parse({ - ...defaultPubspec, + ...defaultPubspec(), 'screenshots': [ {'description': 'my screenshot', 'path': 'path/to/screenshot'}, { @@ -575,7 +575,7 @@ line 6, column 13: Unsupported value for "funding". Illegal scheme character at test('one screenshot plus invalid entries', () async { final value = await parse({ - ...defaultPubspec, + ...defaultPubspec(), 'screenshots': [ 42, { @@ -593,7 +593,7 @@ line 6, column 13: Unsupported value for "funding". Illegal scheme character at test('invalid entries', () async { final value = await parse({ - ...defaultPubspec, + ...defaultPubspec(), 'screenshots': [ 42, 'not a screenshot', @@ -605,7 +605,7 @@ line 6, column 13: Unsupported value for "funding". Illegal scheme character at test('missing key `dessription', () { expectParseThrows( { - ...defaultPubspec, + ...defaultPubspec(), 'screenshots': [ {'path': 'my/path'}, ], @@ -624,7 +624,7 @@ line 7, column 3: Missing key "description". Missing required key `description` test('missing key `path`', () { expectParseThrows( { - ...defaultPubspec, + ...defaultPubspec(), 'screenshots': [ {'description': 'my screenshot'}, ], @@ -643,7 +643,7 @@ line 7, column 3: Missing key "path". Missing required key `path` test('Value of description not a String`', () { expectParseThrows( { - ...defaultPubspec, + ...defaultPubspec(), 'screenshots': [ {'description': 42}, ], @@ -663,7 +663,7 @@ line 8, column 19: Unsupported value for "description". `42` is not a String test('Value of path not a String`', () { expectParseThrows( { - ...defaultPubspec, + ...defaultPubspec(), 'screenshots': [ { 'description': '', @@ -686,7 +686,7 @@ line 9, column 12: Unsupported value for "path". `42` is not a String test('invalid screenshot - lenient', () async { final value = await parse( { - ...defaultPubspec, + ...defaultPubspec(), 'screenshots': 'Invalid value', }, lenient: true, @@ -734,7 +734,7 @@ line 1, column 1: Not a map test('bad repository url', () async { final value = await parse( { - ...defaultPubspec, + ...defaultPubspec(), 'repository': {'x': 'y'}, }, lenient: true, @@ -746,7 +746,7 @@ line 1, column 1: Not a map test('bad issue_tracker url', () async { final value = await parse( { - ...defaultPubspec, + ...defaultPubspec(), 'issue_tracker': {'x': 'y'}, }, lenient: true, @@ -758,7 +758,7 @@ line 1, column 1: Not a map test('multiple bad values', () async { final value = await parse( { - ...defaultPubspec, + ...defaultPubspec(), 'repository': {'x': 'y'}, 'issue_tracker': {'x': 'y'}, }, @@ -793,7 +793,7 @@ line 1, column 1: Not a map test('workspace key must be a list', () { expectParseThrowsContaining( { - ...defaultPubspec, + ...defaultPubspec(), 'workspace': 42, }, 'Unsupported value for "workspace". type \'int\' is not a subtype of type \'List?\' in type cast', @@ -804,7 +804,7 @@ line 1, column 1: Not a map test('workspace key must be a list of strings', () { expectParseThrowsContaining( { - ...defaultPubspec, + ...defaultPubspec(), 'workspace': [42], }, 'Unsupported value for "workspace". type \'int\' is not a subtype of type \'String\' in type cast', diff --git a/pkgs/pubspec_parse/test/test_utils.dart b/pkgs/pubspec_parse/test/test_utils.dart index cc46522b7..9b3179cd8 100644 --- a/pkgs/pubspec_parse/test/test_utils.dart +++ b/pkgs/pubspec_parse/test/test_utils.dart @@ -12,10 +12,10 @@ import 'package:test/test.dart'; import 'pub_utils.dart'; -const defaultPubspec = { - 'name': 'sample', - 'environment': {'sdk': '>=2.12.0 <3.0.0'}, -}; +Map defaultPubspec({String? languageVersion = '2.12'}) => { + 'name': 'sample', + 'environment': {'sdk': '^$languageVersion.0'}, + }; String _encodeJson(Object? input) => const JsonEncoder.withIndent(' ').convert(input);