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

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: 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..4809ee0944785ad26eec4dd8bd3ad2c7f32b12ff 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,24 @@ class DirectoryDescriptor extends Descriptor {
return buffer.toString();
}
}
+
+/// A class for formatting errors thrown by [DirectoryDescriptor].
+class _DirectoryValidationError {
+ final Collection<String> errors;
Bob Nystrom 2013/03/19 20:56:13 List?
nweiz 2013/03/19 21:03:33 Why? We don't rely on any List-specific methods he
+
+ static _DirectoryValidationError merge(Iterable errors) {
Bob Nystrom 2013/03/19 20:56:13 How about a comment here like: Flatten out nested
nweiz 2013/03/19 21:03:33 Done.
+ 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