Fix tests for latest pub parsing rules for environment (dart-lang/pubspec_parse#60)
Since https://github.com/dart-lang/pub/commit/656803e924eae5cf6574f5200232ef69ac3b4f92 (SDK-2.12.0-28.0.dev) pub requires an
SDK constraint.
Update tests so this requirement no longer causes failures.
Also updated test expectations for latest `pkg:json_annotation` changes
diff --git a/pkgs/pubspec_parse/test/dependency_test.dart b/pkgs/pubspec_parse/test/dependency_test.dart
index 35ac6b6..0afbf36 100644
--- a/pkgs/pubspec_parse/test/dependency_test.dart
+++ b/pkgs/pubspec_parse/test/dependency_test.dart
@@ -214,7 +214,7 @@
_expectThrows(
{'sdk': 42},
r'''
-line 5, column 11: Unsupported value for "sdk".
+line 5, column 11: Unsupported value for "sdk". type 'int' is not a subtype of type 'String' in type cast
╷
5 │ "sdk": 42
│ ┌───────────^
@@ -332,7 +332,7 @@
'git': {'url': 42}
},
r'''
-line 6, column 12: Unsupported value for "url".
+line 6, column 12: Unsupported value for "url". type 'int' is not a subtype of type 'String' in type cast
╷
6 │ "url": 42
│ ┌────────────^
@@ -404,7 +404,7 @@
T _dependency<T extends Dependency>(Object content, {bool skipTryPub = false}) {
final value = parse({
- 'name': 'sample',
+ ...defaultPubspec,
'dependencies': {'dep': content}
}, skipTryPub: skipTryPub);
expect(value.name, 'sample');
diff --git a/pkgs/pubspec_parse/test/parse_test.dart b/pkgs/pubspec_parse/test/parse_test.dart
index 75c3f83..179d0d8 100644
--- a/pkgs/pubspec_parse/test/parse_test.dart
+++ b/pkgs/pubspec_parse/test/parse_test.dart
@@ -14,7 +14,7 @@
void main() {
test('minimal set values', () {
- final value = parse({'name': 'sample'});
+ final value = parse(defaultPubspec);
expect(value.name, 'sample');
expect(value.version, isNull);
expect(value.publishTo, isNull);
@@ -23,7 +23,10 @@
// ignore: deprecated_member_use_from_same_package
expect(value.author, isNull);
expect(value.authors, isEmpty);
- expect(value.environment, isEmpty);
+ expect(
+ value.environment,
+ {'sdk': VersionConstraint.parse('>=2.7.0 <3.0.0')},
+ );
expect(value.documentation, isNull);
expect(value.dependencies, isEmpty);
expect(value.devDependencies, isEmpty);
@@ -70,17 +73,20 @@
test('environment values can be null', () {
final value = parse({
'name': 'sample',
- 'environment': {'sdk': null}
+ 'environment': {
+ 'sdk': '>=2.7.0 <3.0.0',
+ 'bob': null,
+ }
});
expect(value.name, 'sample');
- expect(value.environment, hasLength(1));
- expect(value.environment, containsPair('sdk', isNull));
+ expect(value.environment, hasLength(2));
+ expect(value.environment, containsPair('bob', isNull));
});
group('publish_to', () {
for (var entry in {
42: r'''
-line 3, column 16: Unsupported value for "publish_to".
+line 3, column 16: Unsupported value for "publish_to". type 'int' is not a subtype of type 'String' in type cast
╷
3 │ "publish_to": 42
│ ^^
@@ -120,7 +126,10 @@
'none': 'none'
}.entries) {
test('can be ${entry.key}', () {
- final value = parse({'name': 'sample', 'publish_to': entry.value});
+ final value = parse({
+ ...defaultPubspec,
+ 'publish_to': entry.value,
+ });
expect(value.publishTo, entry.value);
});
}
@@ -128,7 +137,10 @@
group('author, authors', () {
test('one author', () {
- final value = parse({'name': 'sample', 'author': 'name@example.com'});
+ final value = parse({
+ ...defaultPubspec,
+ 'author': 'name@example.com',
+ });
// ignore: deprecated_member_use_from_same_package
expect(value.author, 'name@example.com');
expect(value.authors, ['name@example.com']);
@@ -136,7 +148,7 @@
test('one author, via authors', () {
final value = parse({
- 'name': 'sample',
+ ...defaultPubspec,
'authors': ['name@example.com']
});
// ignore: deprecated_member_use_from_same_package
@@ -146,7 +158,7 @@
test('many authors', () {
final value = parse({
- 'name': 'sample',
+ ...defaultPubspec,
'authors': ['name@example.com', 'name2@example.com']
});
// ignore: deprecated_member_use_from_same_package
@@ -156,7 +168,7 @@
test('author and authors', () {
final value = parse({
- 'name': 'sample',
+ ...defaultPubspec,
'author': 'name@example.com',
'authors': ['name2@example.com']
});
@@ -167,7 +179,7 @@
test('duplicate author values', () {
final value = parse({
- 'name': 'sample',
+ ...defaultPubspec,
'author': 'name@example.com',
'authors': ['name@example.com', 'name@example.com']
});
@@ -178,7 +190,7 @@
test('flutter', () {
final value = parse({
- 'name': 'sample',
+ ...defaultPubspec,
'flutter': {'key': 'value'},
});
expect(value.flutter, {'key': 'value'});
@@ -282,16 +294,16 @@
test('bad repository url', () {
expectParseThrows(
{
- 'name': 'foo',
+ ...defaultPubspec,
'repository': {'x': 'y'},
},
r'''
-line 3, column 16: Unsupported value for "repository".
+line 6, column 16: Unsupported value for "repository". type 'YamlMap' is not a subtype of type 'String' in type cast
╷
-3 │ "repository": {
+6 │ "repository": {
│ ┌────────────────^
-4 │ │ "x": "y"
-5 │ └ }
+7 │ │ "x": "y"
+8 │ └ }
╵''',
skipTryPub: true,
);
@@ -300,11 +312,11 @@
test('bad issue_tracker url', () {
expectParseThrows(
{
- 'name': 'foo',
+ 'name': 'sample',
'issue_tracker': {'x': 'y'},
},
r'''
-line 3, column 19: Unsupported value for "issue_tracker".
+line 3, column 19: Unsupported value for "issue_tracker". type 'YamlMap' is not a subtype of type 'String' in type cast
╷
3 │ "issue_tracker": {
│ ┌───────────────────^
@@ -359,37 +371,37 @@
test('bad repository url', () {
final value = parse(
{
- 'name': 'foo',
+ ...defaultPubspec,
'repository': {'x': 'y'},
},
lenient: true,
);
- expect(value.name, 'foo');
+ expect(value.name, 'sample');
expect(value.repository, isNull);
});
test('bad issue_tracker url', () {
final value = parse(
{
- 'name': 'foo',
+ ...defaultPubspec,
'issue_tracker': {'x': 'y'},
},
lenient: true,
);
- expect(value.name, 'foo');
+ expect(value.name, 'sample');
expect(value.issueTracker, isNull);
});
test('multiple bad values', () {
final value = parse(
{
- 'name': 'foo',
+ ...defaultPubspec,
'repository': {'x': 'y'},
'issue_tracker': {'x': 'y'},
},
lenient: true,
);
- expect(value.name, 'foo');
+ expect(value.name, 'sample');
expect(value.repository, isNull);
expect(value.issueTracker, isNull);
});
@@ -397,7 +409,7 @@
test('deep error throws with lenient', () {
expect(
() => parse({
- 'name': 'foo',
+ 'name': 'sample',
'dependencies': {
'foo': {
'git': {'url': 1}
diff --git a/pkgs/pubspec_parse/test/test_utils.dart b/pkgs/pubspec_parse/test/test_utils.dart
index e51f198..ac5abba 100644
--- a/pkgs/pubspec_parse/test/test_utils.dart
+++ b/pkgs/pubspec_parse/test/test_utils.dart
@@ -13,6 +13,11 @@
import 'pub_utils.dart';
+const defaultPubspec = {
+ 'name': 'sample',
+ 'environment': {'sdk': '>=2.7.0 <3.0.0'},
+};
+
String _encodeJson(Object input) =>
const JsonEncoder.withIndent(' ').convert(input);