Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.

Commit 9cebecd

Browse files
authored
fix the unit tests for Dart 3.0 (#86)
* fix the unit tests for Dart 3.0 * update the package version
1 parent 4302b85 commit 9cebecd

File tree

8 files changed

+90
-116
lines changed

8 files changed

+90
-116
lines changed

.github/workflows/test-package.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
fail-fast: false
4747
matrix:
4848
os: [ubuntu-latest]
49-
sdk: [2.14.0, dev]
49+
sdk: [2.17.0, dev]
5050
steps:
5151
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8
5252
- uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d

CHANGELOG.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
## 1.2.1-dev
1+
## 1.2.2-dev
2+
3+
- Update SDK requirement to `2.17.0`.
4+
- Fix the unit tests for Dart 3.0.0.
25

36
## 1.2.1
47

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright 2018, the Dart project authors.
1+
Copyright 2018, the Dart project authors.
22

33
Redistribution and use in source and binary forms, with or without
44
modification, are permitted provided that the following conditions are

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
[![Build Status](https://github.com/dart-lang/pubspec_parse/workflows/Dart%20CI/badge.svg)](https://github.com/dart-lang/pubspec_parse/actions?query=workflow%3A"Dart+CI"+branch%3Amaster)
1+
[![Dart CI](https://github.com/dart-lang/pubspec_parse/actions/workflows/test-package.yml/badge.svg)](https://github.com/dart-lang/pubspec_parse/actions/workflows/test-package.yml)
22
[![pub package](https://img.shields.io/pub/v/pubspec_parse.svg)](https://pub.dev/packages/pubspec_parse)
3+
[![package publisher](https://img.shields.io/pub/publisher/pubspec_parse.svg)](https://pub.dev/packages/pubspec_parse/publisher)
4+
5+
## What's this?
36

47
Supports parsing `pubspec.yaml` files with robust error reporting and support
58
for most of the documented features.
69

10+
## More information
11+
712
Read more about the [pubspec format](https://dart.dev/tools/pub/pubspec).

pubspec.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ name: pubspec_parse
22
description: >-
33
Simple package for parsing pubspec.yaml files with a type-safe API and rich
44
error reporting.
5-
version: 1.2.1
5+
version: 1.2.2-dev
66
repository: https://github.com/dart-lang/pubspec_parse
77

88
environment:
9-
sdk: '>=2.14.0 <3.0.0'
9+
sdk: '>=2.17.0 <3.0.0'
1010

1111
dependencies:
1212
checked_yaml: ^2.0.1
@@ -19,7 +19,7 @@ dev_dependencies:
1919
build_runner: ^2.0.3
2020
build_verify: '>=2.0.0 <4.0.0'
2121
json_serializable: ^6.0.0
22-
lints: ^1.0.0
22+
lints: ^2.0.0
2323
path: ^1.5.1
2424
# Needed because we are configuring `combining_builder`
2525
source_gen: ^1.0.0

test/dependency_test.dart

+20-43
Original file line numberDiff line numberDiff line change
@@ -225,30 +225,16 @@ void _sdkDependency() {
225225
});
226226

227227
test('null content', () {
228-
_expectThrows(
228+
_expectThrowsContaining(
229229
{'sdk': null},
230-
r'''
231-
line 5, column 11: Unsupported value for "sdk". type 'Null' is not a subtype of type 'String' in type cast
232-
233-
5 │ "sdk": null
234-
│ ┌───────────^
235-
6 │ │ }
236-
│ └──^
237-
╵''',
230+
r"type 'Null' is not a subtype of type 'String'",
238231
);
239232
});
240233

241234
test('number content', () {
242-
_expectThrows(
235+
_expectThrowsContaining(
243236
{'sdk': 42},
244-
r'''
245-
line 5, column 11: Unsupported value for "sdk". type 'int' is not a subtype of type 'String' in type cast
246-
247-
5 │ "sdk": 42
248-
│ ┌───────────^
249-
6 │ │ }
250-
│ └──^
251-
╵''',
237+
r"type 'int' is not a subtype of type 'String'",
252238
);
253239
});
254240
}
@@ -337,46 +323,27 @@ line 5, column 11: Unsupported value for "git". Must be a String or a Map.
337323
});
338324

339325
test('git - empty map', () {
340-
_expectThrows(
326+
_expectThrowsContaining(
341327
{'git': <String, dynamic>{}},
342-
r'''
343-
line 5, column 11: Missing key "url". type 'Null' is not a subtype of type 'String' in type cast
344-
345-
5 │ "git": {}
346-
│ ^^
347-
╵''',
328+
r"type 'Null' is not a subtype of type 'String'",
348329
);
349330
});
350331

351332
test('git - null url', () {
352-
_expectThrows(
333+
_expectThrowsContaining(
353334
{
354335
'git': {'url': null}
355336
},
356-
r'''
357-
line 6, column 12: Unsupported value for "url". type 'Null' is not a subtype of type 'String' in type cast
358-
359-
6 │ "url": null
360-
│ ┌────────────^
361-
7 │ │ }
362-
│ └───^
363-
╵''',
337+
r"type 'Null' is not a subtype of type 'String'",
364338
);
365339
});
366340

367341
test('git - int url', () {
368-
_expectThrows(
342+
_expectThrowsContaining(
369343
{
370344
'git': {'url': 42}
371345
},
372-
r'''
373-
line 6, column 12: Unsupported value for "url". type 'int' is not a subtype of type 'String' in type cast
374-
375-
6 │ "url": 42
376-
│ ┌────────────^
377-
7 │ │ }
378-
│ └───^
379-
╵''',
346+
r"type 'int' is not a subtype of type 'String'",
380347
);
381348
});
382349
}
@@ -446,6 +413,16 @@ void _expectThrows(Object content, String expectedError) {
446413
);
447414
}
448415

416+
void _expectThrowsContaining(Object content, String errorText) {
417+
expectParseThrowsContaining(
418+
{
419+
'name': 'sample',
420+
'dependencies': {'dep': content}
421+
},
422+
errorText,
423+
);
424+
}
425+
449426
T _dependency<T extends Dependency>(
450427
Object? content, {
451428
bool skipTryPub = false,

test/parse_test.dart

+21-65
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
// ignore_for_file: deprecated_member_use_from_same_package
6+
// ignore_for_file: lines_longer_than_80_chars
7+
68
library parse_test;
79

810
import 'package:pub_semver/pub_semver.dart';
@@ -22,7 +24,7 @@ void main() {
2224
expect(value.authors, isEmpty);
2325
expect(
2426
value.environment,
25-
{'sdk': VersionConstraint.parse('>=2.7.0 <3.0.0')},
27+
{'sdk': VersionConstraint.parse('>=2.12.0 <3.0.0')},
2628
);
2729
expect(value.documentation, isNull);
2830
expect(value.dependencies, isEmpty);
@@ -36,7 +38,7 @@ void main() {
3638

3739
test('all fields set', () {
3840
final version = Version.parse('1.2.3');
39-
final sdkConstraint = VersionConstraint.parse('>=2.0.0-dev.54 <3.0.0');
41+
final sdkConstraint = VersionConstraint.parse('>=2.12.0 <3.0.0');
4042
final value = parse({
4143
'name': 'sample',
4244
'version': version.toString(),
@@ -85,7 +87,7 @@ void main() {
8587
{
8688
'name': 'sample',
8789
'environment': {
88-
'sdk': '>=2.7.0 <3.0.0',
90+
'sdk': '>=2.12.0 <3.0.0',
8991
'bob': null,
9092
}
9193
},
@@ -98,12 +100,7 @@ void main() {
98100

99101
group('publish_to', () {
100102
for (var entry in {
101-
42: r'''
102-
line 3, column 16: Unsupported value for "publish_to". type 'int' is not a subtype of type 'String?' in type cast
103-
104-
3 │ "publish_to": 42
105-
│ ^^
106-
╵''',
103+
42: "Unsupported value for \"publish_to\". type 'int' is not a subtype of type 'String?'",
107104
'##not a uri!': r'''
108105
line 3, column 16: Unsupported value for "publish_to". Must be an http or https URL.
109106
@@ -124,7 +121,7 @@ line 3, column 16: Unsupported value for "publish_to". Must be an http or https
124121
╵''',
125122
}.entries) {
126123
test('cannot be `${entry.key}`', () {
127-
expectParseThrows(
124+
expectParseThrowsContaining(
128125
{'name': 'sample', 'publish_to': entry.key},
129126
entry.value,
130127
skipTryPub: true,
@@ -241,26 +238,16 @@ line 1, column 1: Not a map
241238
});
242239

243240
test('missing name', () {
244-
expectParseThrows(
241+
expectParseThrowsContaining(
245242
{},
246-
r'''
247-
line 1, column 1: Missing key "name". type 'Null' is not a subtype of type 'String' in type cast
248-
249-
1 │ {}
250-
│ ^^
251-
╵''',
243+
"Missing key \"name\". type 'Null' is not a subtype of type 'String'",
252244
);
253245
});
254246

255247
test('null name value', () {
256-
expectParseThrows(
248+
expectParseThrowsContaining(
257249
{'name': null},
258-
r'''
259-
line 2, column 10: Unsupported value for "name". type 'Null' is not a subtype of type 'String' in type cast
260-
261-
2 │ "name": null
262-
│ ^^^^
263-
╵''',
250+
"Unsupported value for \"name\". type 'Null' is not a subtype of type 'String'",
264251
);
265252
});
266253

@@ -336,73 +323,47 @@ line 4, column 10: Unsupported value for "sdk". Could not parse version "silly".
336323
});
337324

338325
test('bad repository url', () {
339-
expectParseThrows(
326+
expectParseThrowsContaining(
340327
{
341328
...defaultPubspec,
342329
'repository': {'x': 'y'},
343330
},
344-
r'''
345-
line 6, column 16: Unsupported value for "repository". type 'YamlMap' is not a subtype of type 'String' in type cast
346-
347-
6 │ "repository": {
348-
│ ┌────────────────^
349-
7 │ │ "x": "y"
350-
8 │ └ }
351-
╵''',
331+
"Unsupported value for \"repository\". type 'YamlMap' is not a subtype of type 'String'",
352332
skipTryPub: true,
353333
);
354334
});
355335

356336
test('bad issue_tracker url', () {
357-
expectParseThrows(
337+
expectParseThrowsContaining(
358338
{
359339
'name': 'sample',
360340
'issue_tracker': {'x': 'y'},
361341
},
362-
r'''
363-
line 3, column 19: Unsupported value for "issue_tracker". type 'YamlMap' is not a subtype of type 'String' in type cast
364-
365-
3 │ "issue_tracker": {
366-
│ ┌───────────────────^
367-
4 │ │ "x": "y"
368-
5 │ └ }
369-
╵''',
342+
"Unsupported value for \"issue_tracker\". type 'YamlMap' is not a subtype of type 'String'",
370343
skipTryPub: true,
371344
);
372345
});
373346
});
374347

375348
group('funding', () {
376349
test('not a list', () {
377-
expectParseThrows(
350+
expectParseThrowsContaining(
378351
{
379352
...defaultPubspec,
380353
'funding': 1,
381354
},
382-
r'''
383-
line 6, column 13: Unsupported value for "funding". type 'int' is not a subtype of type 'List<dynamic>?' in type cast
384-
385-
6 │ "funding": 1
386-
│ ^
387-
╵''',
355+
"Unsupported value for \"funding\". type 'int' is not a subtype of type 'List<dynamic>?'",
388356
skipTryPub: true,
389357
);
390358
});
391359

392360
test('not an uri', () {
393-
expectParseThrows(
361+
expectParseThrowsContaining(
394362
{
395363
...defaultPubspec,
396364
'funding': [1],
397365
},
398-
r'''
399-
line 6, column 13: Unsupported value for "funding". type 'int' is not a subtype of type 'String' in type cast
400-
401-
6 │ "funding": [
402-
│ ┌─────────────^
403-
7 │ │ 1
404-
8 │ └ ]
405-
╵''',
366+
"Unsupported value for \"funding\". type 'int' is not a subtype of type 'String'",
406367
skipTryPub: true,
407368
);
408369
});
@@ -608,14 +569,9 @@ line 1, column 1: Not a map
608569
});
609570

610571
test('name cannot be empty', () {
611-
expectParseThrows(
572+
expectParseThrowsContaining(
612573
{},
613-
r'''
614-
line 1, column 1: Missing key "name". type 'Null' is not a subtype of type 'String' in type cast
615-
616-
1 │ {}
617-
│ ^^
618-
╵''',
574+
"Missing key \"name\". type 'Null' is not a subtype of type 'String'",
619575
lenient: true,
620576
);
621577
});

0 commit comments

Comments
 (0)