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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/pkg.status ('k') | pkg/scheduled_test/test/descriptor_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library descriptor.file; 5 library descriptor.file;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import '../../../../../pkg/pathos/lib/path.dart' as path; 10 import '../../../../../pkg/pathos/lib/path.dart' as path;
(...skipping 25 matching lines...) Expand all
36 Future validate([String parent]) => schedule(() => validateNow(parent), 36 Future validate([String parent]) => schedule(() => validateNow(parent),
37 'validating directory:\n${describe()}'); 37 'validating directory:\n${describe()}');
38 38
39 Future validateNow([String parent]) { 39 Future validateNow([String parent]) {
40 if (parent == null) parent = defaultRoot; 40 if (parent == null) parent = defaultRoot;
41 var fullPath = path.join(parent, name); 41 var fullPath = path.join(parent, name);
42 if (!new Directory(fullPath).existsSync()) { 42 if (!new Directory(fullPath).existsSync()) {
43 throw "Directory not found: '$fullPath'."; 43 throw "Directory not found: '$fullPath'.";
44 } 44 }
45 45
46 return Future.wait( 46 return Future.wait(contents.map((entry) {
47 contents.map((entry) => entry.validateNow(fullPath)).toList()); 47 return new Future.of(() => entry.validateNow(fullPath))
48 .then((_) => null)
49 .catchError((e) => e.error);
50 })).then((results) {
51 var errors = results.where((e) => e != null);
52 if (errors.isEmpty) return;
53 throw _DirectoryValidationError.merge(errors);
54 });
48 } 55 }
49 56
50 Stream<List<int>> load(String pathToLoad) { 57 Stream<List<int>> load(String pathToLoad) {
51 return futureStream(new Future.immediate(null).then((_) { 58 return futureStream(new Future.immediate(null).then((_) {
52 if (_path.isAbsolute(pathToLoad)) { 59 if (_path.isAbsolute(pathToLoad)) {
53 throw "Can't load absolute path '$pathToLoad'."; 60 throw "Can't load absolute path '$pathToLoad'.";
54 } 61 }
55 62
56 var split = _path.split(_path.normalize(pathToLoad)); 63 var split = _path.split(_path.normalize(pathToLoad));
57 if (split.isEmpty || split.first == '.' || split.first == '..') { 64 if (split.isEmpty || split.first == '.' || split.first == '..') {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 .replaceFirst('| ', '|-- '); 96 .replaceFirst('| ', '|-- ');
90 buffer.writeln(entryString); 97 buffer.writeln(entryString);
91 } 98 }
92 99
93 var lastEntryString = prefixLines(contents.last.describe(), prefix: ' ') 100 var lastEntryString = prefixLines(contents.last.describe(), prefix: ' ')
94 .replaceFirst(' ', "'-- "); 101 .replaceFirst(' ', "'-- ");
95 buffer.write(lastEntryString); 102 buffer.write(lastEntryString);
96 return buffer.toString(); 103 return buffer.toString();
97 } 104 }
98 } 105 }
106
107 /// A class for formatting errors thrown by [DirectoryDescriptor].
108 class _DirectoryValidationError {
109 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
110
111 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.
112 return new _DirectoryValidationError(errors.expand((error) {
113 if (error is _DirectoryValidationError) return error.errors;
114 return [error];
115 }));
116 }
117
118 _DirectoryValidationError(Iterable errors)
119 : errors = errors.map((e) => e.toString()).toList();
120
121 String toString() {
122 if (errors.length == 1) return errors.single;
123 return errors.map((e) => prefixLines(e, prefix: ' ', firstPrefix: '* '))
124 .join('\n');
125 }
126 }
OLDNEW
« 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