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

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

Issue 12321122: Add a nothing descriptor to scheduled_test. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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/scheduled_test/lib/descriptor.dart ('k') | pkg/scheduled_test/lib/src/descriptor/utils.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/nothing.dart
diff --git a/pkg/scheduled_test/lib/src/descriptor/nothing.dart b/pkg/scheduled_test/lib/src/descriptor/nothing.dart
new file mode 100644
index 0000000000000000000000000000000000000000..474c69c1e868eaf91f3af2b9a937c44f1eb6f99a
--- /dev/null
+++ b/pkg/scheduled_test/lib/src/descriptor/nothing.dart
@@ -0,0 +1,60 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library descriptor.async;
+
+import 'dart:async';
+import 'dart:io';
+
+import 'package:pathos/path.dart' as path;
+
+import '../../descriptor.dart' as descriptor;
+import '../../scheduled_test.dart';
+import '../utils.dart';
+import 'utils.dart';
+
+/// A descriptor that validates that no file exists with the given name.
+/// Creating this descriptor is a no-op and loading from it is invalid.
+class Nothing extends descriptor.Entry {
+ Nothing(Pattern name)
+ : super(name);
+
+ Future create([String parent]) => new Future.immediate(null);
+
+ Future validate([String parent]) => schedule(() {
+ if (parent == null) parent = descriptor.defaultRoot;
+ if (name is String) {
+ var fullPath = path.join(parent, name);
+ return new File(fullPath).exists().then((fileExists) {
Bob Nystrom 2013/02/25 22:59:13 Let's use the sync API here. The code is effective
+ if (!fileExists) return new Directory(fullPath).exists();
+ throw "Expected nothing to exist at '$fullPath', but found a file.";
+ }).then((dirExists) {
+ if (!dirExists) return;
+ throw "Expected nothing to exist at '$fullPath', but found a "
+ "directory.";
+ });
+ }
+
+ return new Directory(parent).list().toList().then((entries) {
+ var matchingEntries = entries
+ .map((entry) => entry is File ? entry.fullPathSync() : entry.path)
+ .where((entry) => path.basename(entry).contains(name))
+ .toList();
+ matchingEntries.sort();
+
+ if (matchingEntries.length == 0) return;
+ throw "Expected nothing to exist in '$parent' matching $nameDescription, "
+ "but found:\n"
+ "${matchingEntries.map((entry) => '* $entry').join('\n')}";
+ });
+ }, "validating $nameDescription doesn't exist");
+
+ Stream<List<int>> load(String pathToLoad) => errorStream("Nothing "
+ "descriptors don't support load().");
+
+ Stream<List<int>> read() => errorStream("Nothing descriptors don't support "
+ "read().");
+
+ String describe() => "nothing at $nameDescription";
+}
« no previous file with comments | « pkg/scheduled_test/lib/descriptor.dart ('k') | pkg/scheduled_test/lib/src/descriptor/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698