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

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

Issue 15682008: Allow DirectoryDescriptor.load to load a file next to a directory. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes. Created 7 years, 6 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
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 97f8c92341c5f78a573887bccc5c911d625692b3..5d7b28af15dda5bbe83d09d8290c436d0b3f38a6 100644
--- a/pkg/scheduled_test/lib/src/descriptor/directory_descriptor.dart
+++ b/pkg/scheduled_test/lib/src/descriptor/directory_descriptor.dart
@@ -17,7 +17,7 @@ import '../utils.dart';
final path.Builder _path = new path.Builder(style: path.Style.posix);
/// A descriptor describing a directory containing multiple files.
-class DirectoryDescriptor extends Descriptor {
+class DirectoryDescriptor extends Descriptor implements LoadableDescriptor {
/// The entries contained within this directory. This is intentionally
/// mutable.
final List<Descriptor> contents;
@@ -59,21 +59,29 @@ class DirectoryDescriptor extends Descriptor {
Stream<List<int>> load(String pathToLoad) {
return futureStream(new Future.value().then((_) {
if (_path.isAbsolute(pathToLoad)) {
- throw "Can't load absolute path '$pathToLoad'.";
+ throw new ArgumentError("Can't load absolute path '$pathToLoad'.");
}
var split = _path.split(_path.normalize(pathToLoad));
if (split.isEmpty || split.first == '.' || split.first == '..') {
- throw "Can't load '$pathToLoad' from within '$name'.";
+ throw new ArgumentError("Can't load '$pathToLoad' from within "
+ "'$name'.");
}
- var matchingEntries = contents.where((entry) =>
- entry.name == split.first).toList();
+ var requiresReadable = split.length == 1;
+ var matchingEntries = contents.where((entry) {
+ return entry.name == split.first && (requiresReadable ?
+ entry is ReadableDescriptor :
+ entry is LoadableDescriptor);
+ }).toList();
+ var adjective = requiresReadable ? 'readable' : 'loadable';
if (matchingEntries.length == 0) {
- throw "Couldn't find an entry named '${split.first}' within '$name'.";
+ throw "Couldn't find a $adjective entry named '${split.first}' within "
+ "'$name'.";
} else if (matchingEntries.length > 1) {
- throw "Found multiple entries named '${split.first}' within '$name'.";
+ throw "Found multiple $adjective entries named '${split.first}' within "
+ "'$name'.";
} else {
var remainingPath = split.sublist(1);
if (remainingPath.isEmpty) {
@@ -85,9 +93,6 @@ class DirectoryDescriptor extends Descriptor {
}));
}
- Stream<List<int>> read() => errorStream("Can't read the contents of '$name': "
- "is a directory.");
-
String describe() {
if (contents.isEmpty) return name;
« no previous file with comments | « pkg/scheduled_test/lib/src/descriptor/descriptor.dart ('k') | pkg/scheduled_test/lib/src/descriptor/file_descriptor.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698