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

Start removing dynamic usages in tests #1331

Merged
merged 1 commit into from
Feb 6, 2024
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
2 changes: 1 addition & 1 deletion test/analysis_options_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void main() {

test('passthrough for empty options', () {
final content = updatePassthroughOptions(original: '', custom: '');
expect(json.decode(content), {});
expect(json.decode(content), <String, Object?>{});
});

test('passthrough for some options', () {
Expand Down
82 changes: 47 additions & 35 deletions test/license_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:pana/src/license.dart';
import 'package:test/test.dart';

void main() {
Future expectFile(String path, expected) async {
Future<void> expectFile(String path, List<String> expected) async {
final relativePath = path.substring('test/licenses/'.length);
final licenses =
await detectLicenseInFile(File(path), relativePath: relativePath);
Expand All @@ -23,20 +23,22 @@ void main() {
group('AGPL', () {
test('explicit', () async {
expect(
await detectLicenseInContent('GNU AFFERO GENERAL PUBLIC LICENSE',
relativePath: 'LICENSE'),
[]);
await detectLicenseInContent('GNU AFFERO GENERAL PUBLIC LICENSE',
relativePath: 'LICENSE'),
isEmpty,
);
await expectFile('test/licenses/agpl_v3.txt', ['AGPL-3.0']);
});
});

group('Apache', () {
test('explicit', () async {
expect(
await detectLicenseInContent(
' Apache License\n Version 2.0, January 2004\n',
relativePath: 'LICENSE'),
[]);
await detectLicenseInContent(
' Apache License\n Version 2.0, January 2004\n',
relativePath: 'LICENSE'),
isEmpty,
);
await expectFile('test/licenses/apache_v2.txt', ['Apache-2.0']);
});
});
Expand All @@ -54,39 +56,44 @@ void main() {
group('GPL', () {
test('explicit', () async {
expect(
await detectLicenseInContent(
['GNU GENERAL PUBLIC LICENSE', 'Version 2, June 1991'].join('\n'),
relativePath: 'LICENSE'),
[]);
await detectLicenseInContent(
['GNU GENERAL PUBLIC LICENSE', 'Version 2, June 1991'].join('\n'),
relativePath: 'LICENSE'),
isEmpty,
);
expect(
await detectLicenseInContent(['GNU GPL Version 2'].join('\n'),
relativePath: 'LICENSE'),
[]);
await detectLicenseInContent(['GNU GPL Version 2'].join('\n'),
relativePath: 'LICENSE'),
isEmpty,
);
await expectFile('test/licenses/gpl_v3.txt', ['GPL-3.0']);
});
});

group('LGPL', () {
test('explicit', () async {
expect(
await detectLicenseInContent(
'\nGNU LESSER GENERAL PUBLIC LICENSE\n Version 3, 29 June 2007',
relativePath: 'LICENSE'),
[]);
await detectLicenseInContent(
'\nGNU LESSER GENERAL PUBLIC LICENSE\n Version 3, 29 June 2007',
relativePath: 'LICENSE'),
isEmpty,
);
await expectFile('test/licenses/lgpl_v3.txt', ['LGPL-3.0']);
});
});

group('MIT', () {
test('explicit', () async {
expect(
await detectLicenseInContent('\n\n The MIT license\n\n blah...',
relativePath: 'LICENSE'),
[]);
await detectLicenseInContent('\n\n The MIT license\n\n blah...',
relativePath: 'LICENSE'),
isEmpty,
);
expect(
await detectLicenseInContent('MIT license\n\n blah...',
relativePath: 'LICENSE'),
[]);
await detectLicenseInContent('MIT license\n\n blah...',
relativePath: 'LICENSE'),
isEmpty,
);

await expectFile('test/licenses/mit.txt', ['MIT']);
await expectFile('test/licenses/mit_without_mit.txt', ['MIT']);
Expand All @@ -96,28 +103,33 @@ void main() {
group('MPL', () {
test('explicit', () async {
expect(
await detectLicenseInContent(
'\n\n Mozilla Public License Version 2.0\n\n blah...',
relativePath: 'LICENSE'),
[]);
await detectLicenseInContent(
'\n\n Mozilla Public License Version 2.0\n\n blah...',
relativePath: 'LICENSE'),
isEmpty,
);
await expectFile('test/licenses/mpl_v2.txt', ['MPL-2.0']);
});
});

group('Unlicense', () {
test('explicit', () async {
expect(
await detectLicenseInContent(
'\n\n This is free and unencumbered software released into the public domain.\n',
relativePath: 'LICENSE'),
[]);
await detectLicenseInContent(
'\n\n This is free and unencumbered software released into the public domain.\n',
relativePath: 'LICENSE'),
isEmpty,
);
await expectFile('test/licenses/unlicense.txt', ['Unlicense']);
});
});

group('unknown', () {
test('empty content', () async {
expect(await detectLicenseInContent('', relativePath: 'LICENSE'), []);
expect(
await detectLicenseInContent('', relativePath: 'LICENSE'),
isEmpty,
);
});
});

Expand All @@ -133,7 +145,7 @@ void main() {
});

test('no license files', () async {
expect(await detectLicenseInDir('lib/src/'), []);
expect(await detectLicenseInDir('lib/src/'), isEmpty);
});
});
}
10 changes: 5 additions & 5 deletions test/markdown_content_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void main() {
'http://example.com/logo.png',
'gopher://example.com/logo.png',
],
'links': [],
'links': <String>[],
'isMalformedUtf8': false,
'nonAsciiRatio': 0.0,
});
Expand All @@ -52,8 +52,8 @@ void main() {
]);
final content = await scanMarkdownFileContent(file);
expect(content.toJson(), {
'images': [],
'links': [],
'images': <String>[],
'links': <String>[],
'isMalformedUtf8': true,
'nonAsciiRatio': greaterThan(0.01),
});
Expand All @@ -67,8 +67,8 @@ void main() {
]);
final content = await scanMarkdownFileContent(file);
expect(content.toJson(), {
'images': [],
'links': [],
'images': <String>[],
'links': <String>[],
'isMalformedUtf8': true,
'nonAsciiRatio': greaterThan(0.01),
});
Expand Down
18 changes: 10 additions & 8 deletions test/package_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ PackageServer? _globalPackageServer;
///
/// Calls [callback] with a [PackageServerBuilder] that's used to specify
/// which packages to serve.
Future servePackages([void Function(PackageServerBuilder?)? callback]) async {
Future<void> servePackages(
[void Function(PackageServerBuilder?)? callback]) async {
_globalPackageServer = await PackageServer.start(callback ?? (_) {});

addTearDown(() {
Expand All @@ -35,7 +36,7 @@ Future servePackages([void Function(PackageServerBuilder?)? callback]) async {
/// registered.
///
/// This will always replace a previous server.
Future serveNoPackages() => servePackages((_) {});
Future<void> serveNoPackages() => servePackages((_) {});

class PackageServer {
/// The underlying server.
Expand Down Expand Up @@ -109,7 +110,7 @@ class PackageServer {
}

/// Closes this server.
Future close() => _server.close();
Future<void> close() => _server.close();

/// The [d.DirectoryDescriptor] describing the server layout of
/// `/api/packages` on the test server.
Expand Down Expand Up @@ -166,11 +167,12 @@ class PackageServer {

/// Returns a Map in the format used by the pub.dartlang.org API to represent a
/// package version.
Map _packageVersionApiMap(String hostedUrl, _ServedPackageVersion package) {
Map<String, Object?> _packageVersionApiMap(
String hostedUrl, _ServedPackageVersion package) {
final pubspec = package.pubspec;
final name = pubspec['name'];
final version = pubspec['version'];
final map = {
final map = <String, Object?>{
'pubspec': pubspec,
'version': version,
'archive_url': '$hostedUrl/packages/$name/versions/$version.tar.gz',
Expand Down Expand Up @@ -201,12 +203,12 @@ class PackageServerBuilder {
/// If [contents] is passed, it's used as the contents of the package. By
/// default, a package just contains a dummy lib directory.
void serve(String name, String version,
{Map<String, dynamic>? deps,
Map<String, dynamic>? pubspec,
{Map<String, Object>? deps,
Map<String, Object>? pubspec,
Map<String, String>? versionData,
Iterable<d.Descriptor>? contents,
DateTime? published}) {
var pubspecFields = <String, dynamic>{
var pubspecFields = <String, Object>{
'name': name,
'version': version,
'environment': {'sdk': '>=2.12.0 <4.0.0'}
Expand Down
Loading
Loading