OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /** | 5 /** |
6 * Test infrastructure for testing pub. Unlike typical unit tests, most pub | 6 * Test infrastructure for testing pub. Unlike typical unit tests, most pub |
7 * tests are integration tests that stage some stuff on the file system, run | 7 * tests are integration tests that stage some stuff on the file system, run |
8 * pub, and then validate the results. This library provides an API to build | 8 * pub, and then validate the results. This library provides an API to build |
9 * tests like that. | 9 * tests like that. |
10 */ | 10 */ |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 GitRepoDescriptor git(Pattern name, [List<Descriptor> contents]) => | 49 GitRepoDescriptor git(Pattern name, [List<Descriptor> contents]) => |
50 new GitRepoDescriptor(name, contents); | 50 new GitRepoDescriptor(name, contents); |
51 | 51 |
52 /** | 52 /** |
53 * Creates a new [TarFileDescriptor] with [name] and [contents]. | 53 * Creates a new [TarFileDescriptor] with [name] and [contents]. |
54 */ | 54 */ |
55 TarFileDescriptor tar(Pattern name, [List<Descriptor> contents]) => | 55 TarFileDescriptor tar(Pattern name, [List<Descriptor> contents]) => |
56 new TarFileDescriptor(name, contents); | 56 new TarFileDescriptor(name, contents); |
57 | 57 |
58 /** | 58 /** |
| 59 * Creates a new [NothingDescriptor] with [name]. |
| 60 */ |
| 61 NothingDescriptor nothing(String name) => new NothingDescriptor(name); |
| 62 |
| 63 /** |
59 * The current [HttpServer] created using [serve]. | 64 * The current [HttpServer] created using [serve]. |
60 */ | 65 */ |
61 var _server; | 66 var _server; |
62 | 67 |
63 /** The cached value for [_portCompleter]. */ | 68 /** The cached value for [_portCompleter]. */ |
64 Completer<int> _portCompleterCache; | 69 Completer<int> _portCompleterCache; |
65 | 70 |
66 /** The completer for [port]. */ | 71 /** The completer for [port]. */ |
67 Completer<int> get _portCompleter { | 72 Completer<int> get _portCompleter { |
68 if (_portCompleterCache != null) return _portCompleterCache; | 73 if (_portCompleterCache != null) return _portCompleterCache; |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 if (modifier != null) value = "$name $modifier"; | 299 if (modifier != null) value = "$name $modifier"; |
295 return dir(new RegExp("$name${@'-[a-f0-9]+'}"), [ | 300 return dir(new RegExp("$name${@'-[a-f0-9]+'}"), [ |
296 file('$name.dart', 'main() => "$value";') | 301 file('$name.dart', 'main() => "$value";') |
297 ]); | 302 ]); |
298 } | 303 } |
299 | 304 |
300 /** | 305 /** |
301 * Describes the `packages/` directory containing all the given [packages], | 306 * Describes the `packages/` directory containing all the given [packages], |
302 * which should be name/version pairs. The packages will be validated against | 307 * which should be name/version pairs. The packages will be validated against |
303 * the format produced by the mock package server. | 308 * the format produced by the mock package server. |
| 309 * |
| 310 * A package with a null version should not be installed. |
304 */ | 311 */ |
305 DirectoryDescriptor packagesDir(Map<String, String> packages) { | 312 DirectoryDescriptor packagesDir(Map<String, String> packages) { |
306 var contents = <Descriptor>[]; | 313 var contents = <Descriptor>[]; |
307 packages.forEach((name, version) { | 314 packages.forEach((name, version) { |
308 contents.add(packageDir(name, version)); | 315 if (version == null) { |
| 316 contents.add(nothing(name)); |
| 317 } else { |
| 318 contents.add(packageDir(name, version)); |
| 319 } |
309 }); | 320 }); |
310 return dir(packagesPath, contents); | 321 return dir(packagesPath, contents); |
311 } | 322 } |
312 | 323 |
313 /** | 324 /** |
314 * Describes the global package cache directory containing all the given | 325 * Describes the global package cache directory containing all the given |
315 * [packages], which should be name/version pairs. The packages will be | 326 * [packages], which should be name/version pairs. The packages will be |
316 * validated against the format produced by the mock package server. | 327 * validated against the format produced by the mock package server. |
317 * | 328 * |
318 * A package's value may also be a list of versions, in which case all versions | 329 * A package's value may also be a list of versions, in which case all versions |
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1015 }).then((tar) { | 1026 }).then((tar) { |
1016 var sourceStream = tar.openInputStream(); | 1027 var sourceStream = tar.openInputStream(); |
1017 pipeInputToInput( | 1028 pipeInputToInput( |
1018 sourceStream, sinkStream, onClosed: tempDir.deleteRecursively); | 1029 sourceStream, sinkStream, onClosed: tempDir.deleteRecursively); |
1019 }); | 1030 }); |
1020 return sinkStream; | 1031 return sinkStream; |
1021 } | 1032 } |
1022 } | 1033 } |
1023 | 1034 |
1024 /** | 1035 /** |
| 1036 * A descriptor that validates that no file exists with the given name. |
| 1037 */ |
| 1038 class NothingDescriptor extends Descriptor { |
| 1039 NothingDescriptor(String name) : super(name); |
| 1040 |
| 1041 Future create(dir) => new Future.immediate(null); |
| 1042 Future delete(dir) => new Future.immediate(null); |
| 1043 |
| 1044 Future validate(String dir) { |
| 1045 return exists(join(dir, name)).transform((exists) { |
| 1046 if (exists) Expect.fail('File $name in $dir should not exist.'); |
| 1047 }); |
| 1048 } |
| 1049 |
| 1050 InputStream load(List<String> path) { |
| 1051 if (path.isEmpty()) { |
| 1052 throw "Can't load the contents of $name: it doesn't exist."; |
| 1053 } else { |
| 1054 throw "Can't load ${Strings.join(path, '/')} from within $name: $name " |
| 1055 "doesn't exist."; |
| 1056 } |
| 1057 } |
| 1058 } |
| 1059 |
| 1060 /** |
1025 * Takes a simple data structure (composed of [Map]s, [List]s, scalar objects, | 1061 * Takes a simple data structure (composed of [Map]s, [List]s, scalar objects, |
1026 * and [Future]s) and recursively resolves all the [Future]s contained within. | 1062 * and [Future]s) and recursively resolves all the [Future]s contained within. |
1027 * Completes with the fully resolved structure. | 1063 * Completes with the fully resolved structure. |
1028 */ | 1064 */ |
1029 Future _awaitObject(object) { | 1065 Future _awaitObject(object) { |
1030 // Unroll nested futures. | 1066 // Unroll nested futures. |
1031 if (object is Future) return object.chain(_awaitObject); | 1067 if (object is Future) return object.chain(_awaitObject); |
1032 if (object is Collection) return Futures.wait(object.map(_awaitObject)); | 1068 if (object is Collection) return Futures.wait(object.map(_awaitObject)); |
1033 if (object is! Map) return new Future.immediate(object); | 1069 if (object is! Map) return new Future.immediate(object); |
1034 | 1070 |
(...skipping 20 matching lines...) Expand all Loading... |
1055 } | 1091 } |
1056 | 1092 |
1057 /** | 1093 /** |
1058 * Schedules a callback to be called after Pub is run with [runPub], even if it | 1094 * Schedules a callback to be called after Pub is run with [runPub], even if it |
1059 * fails. | 1095 * fails. |
1060 */ | 1096 */ |
1061 void _scheduleCleanup(_ScheduledEvent event) { | 1097 void _scheduleCleanup(_ScheduledEvent event) { |
1062 if (_scheduledCleanup == null) _scheduledCleanup = []; | 1098 if (_scheduledCleanup == null) _scheduledCleanup = []; |
1063 _scheduledCleanup.add(event); | 1099 _scheduledCleanup.add(event); |
1064 } | 1100 } |
OLD | NEW |