Drop usage of waitFor (dart-lang/pubspec_parse#114)
diff --git a/pkgs/pubspec_parse/test/dependency_test.dart b/pkgs/pubspec_parse/test/dependency_test.dart index 71b148c..f1e4f57 100644 --- a/pkgs/pubspec_parse/test/dependency_test.dart +++ b/pkgs/pubspec_parse/test/dependency_test.dart
@@ -70,21 +70,21 @@ } void _hostedDependency() { - test('null', () { - final dep = _dependency<HostedDependency>(null); + test('null', () async { + final dep = await _dependency<HostedDependency>(null); expect(dep.version.toString(), 'any'); expect(dep.hosted, isNull); expect(dep.toString(), 'HostedDependency: any'); }); - test('empty map', () { - final dep = _dependency<HostedDependency>({}); + test('empty map', () async { + final dep = await _dependency<HostedDependency>({}); expect(dep.hosted, isNull); expect(dep.toString(), 'HostedDependency: any'); }); - test('string version', () { - final dep = _dependency<HostedDependency>('^1.0.0'); + test('string version', () async { + final dep = await _dependency<HostedDependency>('^1.0.0'); expect(dep.version.toString(), '^1.0.0'); expect(dep.hosted, isNull); expect(dep.toString(), 'HostedDependency: ^1.0.0'); @@ -102,15 +102,15 @@ ); }); - test('map w/ just version', () { - final dep = _dependency<HostedDependency>({'version': '^1.0.0'}); + test('map w/ just version', () async { + final dep = await _dependency<HostedDependency>({'version': '^1.0.0'}); expect(dep.version.toString(), '^1.0.0'); expect(dep.hosted, isNull); expect(dep.toString(), 'HostedDependency: ^1.0.0'); }); - test('map w/ version and hosted as Map', () { - final dep = _dependency<HostedDependency>({ + test('map w/ version and hosted as Map', () async { + final dep = await _dependency<HostedDependency>({ 'version': '^1.0.0', 'hosted': {'name': 'hosted_name', 'url': 'https://hosted_url'}, }); @@ -120,8 +120,8 @@ expect(dep.toString(), 'HostedDependency: ^1.0.0'); }); - test('map /w hosted as a map without name', () { - final dep = _dependency<HostedDependency>( + test('map /w hosted as a map without name', () async { + final dep = await _dependency<HostedDependency>( { 'version': '^1.0.0', 'hosted': {'url': 'https://hosted_url'}, @@ -166,8 +166,8 @@ ); }); - test('map w/ version and hosted as String', () { - final dep = _dependency<HostedDependency>( + test('map w/ version and hosted as String', () async { + final dep = await _dependency<HostedDependency>( {'version': '^1.0.0', 'hosted': 'hosted_url'}, skipTryPub: true, // todo: Unskip once put supports this ); @@ -178,8 +178,8 @@ expect(dep.toString(), 'HostedDependency: ^1.0.0'); }); - test('map w/ hosted as String', () { - final dep = _dependency<HostedDependency>({'hosted': 'hosted_url'}); + test('map w/ hosted as String', () async { + final dep = await _dependency<HostedDependency>({'hosted': 'hosted_url'}); expect(dep.version, VersionConstraint.any); expect(dep.hosted!.declaredName, isNull); expect(dep.hosted!.name, 'dep'); @@ -199,8 +199,8 @@ ); }); - test('map w/ null version is fine', () { - final dep = _dependency<HostedDependency>({'version': null}); + test('map w/ null version is fine', () async { + final dep = await _dependency<HostedDependency>({'version': null}); expect(dep.version, VersionConstraint.any); expect(dep.hosted, isNull); expect(dep.toString(), 'HostedDependency: any'); @@ -208,15 +208,15 @@ } void _sdkDependency() { - test('without version', () { - final dep = _dependency<SdkDependency>({'sdk': 'flutter'}); + test('without version', () async { + final dep = await _dependency<SdkDependency>({'sdk': 'flutter'}); expect(dep.sdk, 'flutter'); expect(dep.version, VersionConstraint.any); expect(dep.toString(), 'SdkDependency: flutter'); }); - test('with version', () { - final dep = _dependency<SdkDependency>( + test('with version', () async { + final dep = await _dependency<SdkDependency>( {'sdk': 'flutter', 'version': '>=1.2.3 <2.0.0'}, ); expect(dep.sdk, 'flutter'); @@ -240,29 +240,30 @@ } void _gitDependency() { - test('string', () { - final dep = _dependency<GitDependency>({'git': 'url'}); + test('string', () async { + final dep = await _dependency<GitDependency>({'git': 'url'}); expect(dep.url.toString(), 'url'); expect(dep.path, isNull); expect(dep.ref, isNull); expect(dep.toString(), 'GitDependency: url@url'); }); - test('string with version key is ignored', () { + test('string with version key is ignored', () async { // Regression test for https://github.com/dart-lang/pubspec_parse/issues/13 - final dep = _dependency<GitDependency>({'git': 'url', 'version': '^1.2.3'}); + final dep = + await _dependency<GitDependency>({'git': 'url', 'version': '^1.2.3'}); expect(dep.url.toString(), 'url'); expect(dep.path, isNull); expect(dep.ref, isNull); expect(dep.toString(), 'GitDependency: url@url'); }); - test('string with user@ URL', () { + test('string with user@ URL', () async { final skipTryParse = Platform.environment.containsKey('TRAVIS'); if (skipTryParse) { print('FYI: not validating git@ URI on travis due to failure'); } - final dep = _dependency<GitDependency>( + final dep = await _dependency<GitDependency>( {'git': 'git@localhost:dep.git'}, skipTryPub: skipTryParse, ); @@ -284,8 +285,8 @@ ); }); - test('map', () { - final dep = _dependency<GitDependency>({ + test('map', () async { + final dep = await _dependency<GitDependency>({ 'git': {'url': 'url', 'path': 'path', 'ref': 'ref'}, }); expect(dep.url.toString(), 'url'); @@ -349,15 +350,16 @@ } void _pathDependency() { - test('valid', () { - final dep = _dependency<PathDependency>({'path': '../path'}); + test('valid', () async { + final dep = await _dependency<PathDependency>({'path': '../path'}); expect(dep.path, '../path'); expect(dep.toString(), 'PathDependency: path@../path'); }); - test('valid with version key is ignored', () { - final dep = - _dependency<PathDependency>({'path': '../path', 'version': '^1.2.3'}); + test('valid with version key is ignored', () async { + final dep = await _dependency<PathDependency>( + {'path': '../path', 'version': '^1.2.3'}, + ); expect(dep.path, '../path'); expect(dep.toString(), 'PathDependency: path@../path'); }); @@ -423,11 +425,11 @@ ); } -T _dependency<T extends Dependency>( +Future<T> _dependency<T extends Dependency>( Object? content, { bool skipTryPub = false, -}) { - final value = parse( +}) async { + final value = await parse( { ...defaultPubspec, 'dependencies': {'dep': content},
diff --git a/pkgs/pubspec_parse/test/parse_test.dart b/pkgs/pubspec_parse/test/parse_test.dart index 99199c7..31042f1 100644 --- a/pkgs/pubspec_parse/test/parse_test.dart +++ b/pkgs/pubspec_parse/test/parse_test.dart
@@ -11,8 +11,8 @@ import 'test_utils.dart'; void main() { - test('minimal set values', () { - final value = parse(defaultPubspec); + test('minimal set values', () async { + final value = await parse(defaultPubspec); expect(value.name, 'sample'); expect(value.version, isNull); expect(value.publishTo, isNull); @@ -34,10 +34,10 @@ expect(value.screenshots, isEmpty); }); - test('all fields set', () { + test('all fields set', () async { final version = Version.parse('1.2.3'); final sdkConstraint = VersionConstraint.parse('>=2.12.0 <3.0.0'); - final value = parse({ + final value = await parse({ 'name': 'sample', 'version': version.toString(), 'publish_to': 'none', @@ -84,8 +84,8 @@ expect(value.screenshots!.first.path, 'path/to/screenshot'); }); - test('environment values can be null', () { - final value = parse( + test('environment values can be null', () async { + final value = await parse( { 'name': 'sample', 'environment': { @@ -137,8 +137,8 @@ 'https': 'https://example.com', 'none': 'none', }.entries) { - test('can be ${entry.key}', () { - final value = parse({ + test('can be ${entry.key}', () async { + final value = await parse({ ...defaultPubspec, 'publish_to': entry.value, }); @@ -148,8 +148,8 @@ }); group('author, authors', () { - test('one author', () { - final value = parse({ + test('one author', () async { + final value = await parse({ ...defaultPubspec, 'author': 'name@example.com', }); @@ -157,8 +157,8 @@ expect(value.authors, ['name@example.com']); }); - test('one author, via authors', () { - final value = parse({ + test('one author, via authors', () async { + final value = await parse({ ...defaultPubspec, 'authors': ['name@example.com'], }); @@ -166,8 +166,8 @@ expect(value.authors, ['name@example.com']); }); - test('many authors', () { - final value = parse({ + test('many authors', () async { + final value = await parse({ ...defaultPubspec, 'authors': ['name@example.com', 'name2@example.com'], }); @@ -175,8 +175,8 @@ expect(value.authors, ['name@example.com', 'name2@example.com']); }); - test('author and authors', () { - final value = parse({ + test('author and authors', () async { + final value = await parse({ ...defaultPubspec, 'author': 'name@example.com', 'authors': ['name2@example.com'], @@ -185,8 +185,8 @@ expect(value.authors, ['name@example.com', 'name2@example.com']); }); - test('duplicate author values', () { - final value = parse({ + test('duplicate author values', () async { + final value = await parse({ ...defaultPubspec, 'author': 'name@example.com', 'authors': ['name@example.com', 'name@example.com'], @@ -195,8 +195,8 @@ expect(value.authors, ['name@example.com']); }); - test('flutter', () { - final value = parse({ + test('flutter', () async { + final value = await parse({ ...defaultPubspec, 'flutter': {'key': 'value'}, }); @@ -411,8 +411,8 @@ ); }); - test('invalid data - lenient', () { - final value = parse( + test('invalid data - lenient', () async { + final value = await parse( { ...defaultPubspec, 'topics': [1], @@ -426,8 +426,8 @@ }); group('screenshots', () { - test('one screenshot', () { - final value = parse({ + test('one screenshot', () async { + final value = await parse({ ...defaultPubspec, 'screenshots': [ {'description': 'my screenshot', 'path': 'path/to/screenshot'}, @@ -438,8 +438,8 @@ expect(value.screenshots!.first.path, 'path/to/screenshot'); }); - test('many screenshots', () { - final value = parse({ + test('many screenshots', () async { + final value = await parse({ ...defaultPubspec, 'screenshots': [ {'description': 'my screenshot', 'path': 'path/to/screenshot'}, @@ -456,8 +456,8 @@ expect(value.screenshots!.last.path, 'path/to/screenshot2'); }); - test('one screenshot plus invalid entries', () { - final value = parse({ + test('one screenshot plus invalid entries', () async { + final value = await parse({ ...defaultPubspec, 'screenshots': [ 42, @@ -474,8 +474,8 @@ expect(value.screenshots!.first.path, 'path/to/screenshot'); }); - test('invalid entries', () { - final value = parse({ + test('invalid entries', () async { + final value = await parse({ ...defaultPubspec, 'screenshots': [ 42, @@ -566,8 +566,8 @@ ); }); - test('invalid screenshot - lenient', () { - final value = parse( + test('invalid screenshot - lenient', () async { + final value = await parse( { ...defaultPubspec, 'screenshots': 'Invalid value', @@ -614,8 +614,8 @@ ); }); - test('bad repository url', () { - final value = parse( + test('bad repository url', () async { + final value = await parse( { ...defaultPubspec, 'repository': {'x': 'y'}, @@ -626,8 +626,8 @@ expect(value.repository, isNull); }); - test('bad issue_tracker url', () { - final value = parse( + test('bad issue_tracker url', () async { + final value = await parse( { ...defaultPubspec, 'issue_tracker': {'x': 'y'}, @@ -638,8 +638,8 @@ expect(value.issueTracker, isNull); }); - test('multiple bad values', () { - final value = parse( + test('multiple bad values', () async { + final value = await parse( { ...defaultPubspec, 'repository': {'x': 'y'},
diff --git a/pkgs/pubspec_parse/test/test_utils.dart b/pkgs/pubspec_parse/test/test_utils.dart index b573851..cc46522 100644 --- a/pkgs/pubspec_parse/test/test_utils.dart +++ b/pkgs/pubspec_parse/test/test_utils.dart
@@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// ignore: deprecated_member_use -import 'dart:cli'; import 'dart:convert'; import 'package:checked_yaml/checked_yaml.dart'; @@ -61,18 +59,18 @@ } } -Pubspec parse( +Future<Pubspec> parse( Object? content, { bool quietOnError = false, bool skipTryPub = false, bool lenient = false, -}) { +}) async { final encoded = _encodeJson(content); ProcResult? pubResult; if (!skipTryPub) { // ignore: deprecated_member_use - pubResult = waitFor(tryPub(encoded)); + pubResult = await tryPub(encoded); expect(pubResult, isNotNull); }