Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
## 1.2.1-dev
## 2.0.0-nullsafety

* Update minimum Dart SDK to `2.7.0`.
* Migrate to null safety.
* Fix outdated URLs in `README.md`.
* BREAKING: Removed archive support.

## 1.2.0

Expand Down
186 changes: 0 additions & 186 deletions lib/src/archive_descriptor.dart

This file was deleted.

4 changes: 2 additions & 2 deletions lib/src/descriptor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ abstract class Descriptor {

/// Creates this entry within the [parent] directory, which defaults to
/// [sandbox].
Future create([String parent]);
Future<void> create([String? parent]);

/// Validates that the physical file system under [parent] (which defaults to
/// [sandbox]) contains an entry that matches this descriptor.
Future validate([String parent]);
Future<void> validate([String? parent]);

/// Returns a human-friendly tree-style description of this descriptor.
String describe();
Expand Down
8 changes: 4 additions & 4 deletions lib/src/directory_descriptor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,18 @@ class DirectoryDescriptor extends Descriptor {
}
// Ignore broken symlinks.
return null;
}).where((path) => path != null));
}).whereType<Descriptor>());
}

@override
Future create([String parent]) async {
Future<void> create([String? parent]) async {
var fullPath = p.join(parent ?? sandbox, name);
await Directory(fullPath).create(recursive: true);
await Future.wait(contents.map((entry) => entry.create(fullPath)));
}

@override
Future validate([String parent]) async {
Future<void> validate([String? parent]) async {
var fullPath = p.join(parent ?? sandbox, name);
if (!(await Directory(fullPath).exists())) {
fail('Directory not found: "${prettyPath(fullPath)}".');
Expand All @@ -80,7 +80,7 @@ class DirectoryDescriptor extends Descriptor {
/// The [parents] parameter should only be passed by subclasses of
/// [DirectoryDescriptor] that are recursively calling [load]. It's the
/// URL-format path of the directories that have been loaded so far.
Stream<List<int>> load(url, [String parents]) {
Stream<List<int>> load(url, [String? parents]) {
String path;
if (url is String) {
path = url;
Expand Down
12 changes: 6 additions & 6 deletions lib/src/file_descriptor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ abstract class FileDescriptor extends Descriptor {
FileDescriptor.protected(String name) : super(name);

@override
Future create([String parent]) async {
Future<void> create([String? parent]) async {
// Create the stream before we call [File.openWrite] because it may fail
// fast (e.g. if this is a matcher file).
var file = File(p.join(parent ?? sandbox, name)).openWrite();
Expand All @@ -72,7 +72,7 @@ abstract class FileDescriptor extends Descriptor {
}

@override
Future validate([String parent]) async {
Future<void> validate([String? parent]) async {
var fullPath = p.join(parent ?? sandbox, name);
var pretty = prettyPath(fullPath);
if (!(await File(fullPath).exists())) {
Expand All @@ -87,7 +87,7 @@ abstract class FileDescriptor extends Descriptor {
///
/// The [prettyPath] is a human-friendly representation of the path to the
/// descriptor.
Future _validate(String prettyPath, List<int> binaryContents);
FutureOr<void> /*!*/ _validate(String prettyPath, List<int> binaryContents);

/// Reads and decodes the contents of this descriptor as a UTF-8 string.
///
Expand All @@ -113,7 +113,7 @@ class _BinaryFileDescriptor extends FileDescriptor {
Stream<List<int>> readAsBytes() => Stream.fromIterable([_contents]);

@override
Future _validate(String prettPath, List<int> actualContents) async {
Future<void> _validate(String prettPath, List<int> actualContents) async {
if (const IterableEquality().equals(_contents, actualContents)) return null;
// TODO(nweiz): show a hex dump here if the data is small enough.
fail('File "$prettPath" didn\'t contain the expected binary data.');
Expand All @@ -134,7 +134,7 @@ class _StringFileDescriptor extends FileDescriptor {
Stream.fromIterable([utf8.encode(_contents)]);

@override
Future _validate(String prettyPath, List<int> actualContents) {
void _validate(String prettyPath, List<int> actualContents) {
var actualContentsText = utf8.decode(actualContents);
if (_contents == actualContentsText) return null;
fail(_textMismatchMessage(prettyPath, _contents, actualContentsText));
Expand Down Expand Up @@ -194,7 +194,7 @@ class _MatcherFileDescriptor extends FileDescriptor {
throw UnsupportedError("Matcher files can't be created or read.");

@override
Future _validate(String prettyPath, List<int> actualContents) async {
Future<void> _validate(String prettyPath, List<int> actualContents) async {
try {
expect(
_isBinary ? actualContents : utf8.decode(actualContents), _matcher);
Expand Down
4 changes: 2 additions & 2 deletions lib/src/nothing_descriptor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ class NothingDescriptor extends Descriptor {
NothingDescriptor(String name) : super(name);

@override
Future create([String parent]) async {}
Future<void> create([String? parent]) async {}

@override
Future validate([String parent]) async {
Future<void> validate([String? parent]) async {
var fullPath = p.join(parent ?? sandbox, name);
var pretty = prettyPath(fullPath);
if (File(fullPath).existsSync()) {
Expand Down
35 changes: 19 additions & 16 deletions lib/src/pattern_descriptor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class PatternDescriptor extends Descriptor {
/// in the constructor and validates the result. If exactly one succeeds,
/// `this` is considered valid.
@override
Future validate([String parent]) async {
Future<void> validate([String? parent]) async {
var inSandbox = parent == null;
parent ??= sandbox;
var matchingEntries = await Directory(parent)
Expand All @@ -57,27 +57,30 @@ class PatternDescriptor extends Descriptor {
fail('No entries found in $location matching $_patternDescription.');
}

var results = await Future.wait(matchingEntries.map((entry) {
var basename = p.basename(entry);
return runZonedGuarded(() {
return Result.capture(Future.sync(() async {
await _fn(basename).validate(parent);
return basename;
}));
}, (_, __) {
// Validate may produce multiple errors, but we ignore all but the first
// to avoid cluttering the user with many different errors from many
// different un-matched entries.
});
}).toList());
var results = await Future.wait(matchingEntries
.map((entry) {
var basename = p.basename(entry);
return runZonedGuarded(() {
return Result.capture(Future.sync(() async {
await _fn(basename).validate(parent);
return basename;
}));
}, (_, __) {
// Validate may produce multiple errors, but we ignore all but the first
// to avoid cluttering the user with many different errors from many
// different un-matched entries.
});
})
.whereType<Future<Result<String>>>()
.toList());

var successes = results.where((result) => result.isValue).toList();
if (successes.isEmpty) {
await waitAndReportErrors(results.map((result) => result.asFuture));
} else if (successes.length > 1) {
fail('Multiple valid entries found in $location matching '
'$_patternDescription:\n'
'${bullet(successes.map((result) => result.asValue.value))}');
'${bullet(successes.map((result) => result.asValue!.value))}');
}
}

Expand All @@ -96,7 +99,7 @@ class PatternDescriptor extends Descriptor {
}

@override
Future create([String parent]) {
Future<void> create([String? parent]) {
throw UnsupportedError("Pattern descriptors don't support create().");
}
}
Loading