Index: utils/tests/pub/test_pub.dart |
diff --git a/utils/tests/pub/test_pub.dart b/utils/tests/pub/test_pub.dart |
index 9fe67f0e00c7c46015046011d3081f8f37d96f8f..010a8e465ac40bac5978f4451a7912fda746a074 100644 |
--- a/utils/tests/pub/test_pub.dart |
+++ b/utils/tests/pub/test_pub.dart |
@@ -56,6 +56,11 @@ TarFileDescriptor tar(Pattern name, [List<Descriptor> contents]) => |
new TarFileDescriptor(name, contents); |
/** |
+ * Creates a new [NothingDescriptor] with [name]. |
+ */ |
+NothingDescriptor nothing(String name) => new NothingDescriptor(name); |
+ |
+/** |
* The current [HttpServer] created using [serve]. |
*/ |
var _server; |
@@ -301,11 +306,17 @@ DirectoryDescriptor gitPackageCacheDir(String name, [int modifier]) { |
* Describes the `packages/` directory containing all the given [packages], |
* which should be name/version pairs. The packages will be validated against |
* the format produced by the mock package server. |
+ * |
+ * A package with a null version should not be installed. |
*/ |
DirectoryDescriptor packagesDir(Map<String, String> packages) { |
var contents = <Descriptor>[]; |
packages.forEach((name, version) { |
- contents.add(packageDir(name, version)); |
+ if (version == null) { |
+ contents.add(nothing(name)); |
+ } else { |
+ contents.add(packageDir(name, version)); |
+ } |
}); |
return dir(packagesPath, contents); |
} |
@@ -1022,6 +1033,31 @@ class TarFileDescriptor extends Descriptor { |
} |
/** |
+ * A descriptor that validates that no file exists with the given name. |
+ */ |
+class NothingDescriptor extends Descriptor { |
+ NothingDescriptor(String name) : super(name); |
+ |
+ Future create(dir) => new Future.immediate(null); |
+ Future delete(dir) => new Future.immediate(null); |
+ |
+ Future validate(String dir) { |
+ return exists(join(dir, name)).transform((exists) { |
+ if (exists) Expect.fail('File $name in $dir should not exist.'); |
+ }); |
+ } |
+ |
+ InputStream load(List<String> path) { |
+ if (path.isEmpty()) { |
+ throw "Can't load the contents of $name: it doesn't exist."; |
+ } else { |
+ throw "Can't load ${Strings.join(path, '/')} from within $name: $name " |
+ "doesn't exist."; |
+ } |
+ } |
+} |
+ |
+/** |
* Takes a simple data structure (composed of [Map]s, [List]s, scalar objects, |
* and [Future]s) and recursively resolves all the [Future]s contained within. |
* Completes with the fully resolved structure. |