Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Unified Diff: pkg/scheduled_test/lib/src/descriptor/directory_descriptor.dart

Issue 12440054: Properly collate multiple directory validation errors in scheduled_test. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/pkg.status ('k') | pkg/scheduled_test/test/descriptor_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/scheduled_test/lib/src/descriptor/directory_descriptor.dart
diff --git a/pkg/scheduled_test/lib/src/descriptor/directory_descriptor.dart b/pkg/scheduled_test/lib/src/descriptor/directory_descriptor.dart
index 1dbb7a4b322dfa4c6ce6487b5ea5cb4c41dea513..c8565e721d9bc7555c50226d7c0c65c67560ee92 100644
--- a/pkg/scheduled_test/lib/src/descriptor/directory_descriptor.dart
+++ b/pkg/scheduled_test/lib/src/descriptor/directory_descriptor.dart
@@ -43,8 +43,15 @@ class DirectoryDescriptor extends Descriptor {
throw "Directory not found: '$fullPath'.";
}
- return Future.wait(
- contents.map((entry) => entry.validateNow(fullPath)).toList());
+ return Future.wait(contents.map((entry) {
+ return new Future.of(() => entry.validateNow(fullPath))
+ .then((_) => null)
+ .catchError((e) => e.error);
+ })).then((results) {
+ var errors = results.where((e) => e != null);
+ if (errors.isEmpty) return;
+ throw _DirectoryValidationError.merge(errors);
+ });
}
Stream<List<int>> load(String pathToLoad) {
@@ -96,3 +103,26 @@ class DirectoryDescriptor extends Descriptor {
return buffer.toString();
}
}
+
+/// A class for formatting errors thrown by [DirectoryDescriptor].
+class _DirectoryValidationError {
+ final Collection<String> errors;
+
+ /// Flatten nested [_DirectoryValidationError]s in [errors] to create a single
+ /// list of errors.
+ static _DirectoryValidationError merge(Iterable errors) {
+ return new _DirectoryValidationError(errors.expand((error) {
+ if (error is _DirectoryValidationError) return error.errors;
+ return [error];
+ }));
+ }
+
+ _DirectoryValidationError(Iterable errors)
+ : errors = errors.map((e) => e.toString()).toList();
+
+ String toString() {
+ if (errors.length == 1) return errors.single;
+ return errors.map((e) => prefixLines(e, prefix: ' ', firstPrefix: '* '))
+ .join('\n');
+ }
+}
« no previous file with comments | « pkg/pkg.status ('k') | pkg/scheduled_test/test/descriptor_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698