| 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 892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 903 /** | 903 /** |
| 904 * Creates the file within [dir]. Returns a [Future] that is completed after | 904 * Creates the file within [dir]. Returns a [Future] that is completed after |
| 905 * the creation is done. | 905 * the creation is done. |
| 906 */ | 906 */ |
| 907 Future<Directory> create(parentDir) { | 907 Future<Directory> create(parentDir) { |
| 908 // Create the directory. | 908 // Create the directory. |
| 909 return ensureDir(join(parentDir, _stringName)).chain((dir) { | 909 return ensureDir(join(parentDir, _stringName)).chain((dir) { |
| 910 if (contents == null) return new Future<Directory>.immediate(dir); | 910 if (contents == null) return new Future<Directory>.immediate(dir); |
| 911 | 911 |
| 912 // Recursively create all of its children. | 912 // Recursively create all of its children. |
| 913 final childFutures = contents.mappedBy((child) => child.create(dir)); | 913 final childFutures = |
| 914 contents.mappedBy((child) => child.create(dir)).toList(); |
| 914 // Only complete once all of the children have been created too. | 915 // Only complete once all of the children have been created too. |
| 915 return Futures.wait(childFutures).transform((_) => dir); | 916 return Futures.wait(childFutures).transform((_) => dir); |
| 916 }); | 917 }); |
| 917 } | 918 } |
| 918 | 919 |
| 919 /** | 920 /** |
| 920 * Deletes the directory within [dir]. Returns a [Future] that is completed | 921 * Deletes the directory within [dir]. Returns a [Future] that is completed |
| 921 * after the deletion is done. | 922 * after the deletion is done. |
| 922 */ | 923 */ |
| 923 Future delete(dir) { | 924 Future delete(dir) { |
| 924 return deleteDir(join(dir, _stringName)); | 925 return deleteDir(join(dir, _stringName)); |
| 925 } | 926 } |
| 926 | 927 |
| 927 /** | 928 /** |
| 928 * Validates that the directory at [path] contains all of the expected | 929 * Validates that the directory at [path] contains all of the expected |
| 929 * contents in this descriptor. Note that this does *not* check that the | 930 * contents in this descriptor. Note that this does *not* check that the |
| 930 * directory doesn't contain other unexpected stuff, just that it *does* | 931 * directory doesn't contain other unexpected stuff, just that it *does* |
| 931 * contain the stuff we do expect. | 932 * contain the stuff we do expect. |
| 932 */ | 933 */ |
| 933 Future validate(String path) { | 934 Future validate(String path) { |
| 934 return _validateOneMatch(path, (dir) { | 935 return _validateOneMatch(path, (dir) { |
| 935 // Validate each of the items in this directory. | 936 // Validate each of the items in this directory. |
| 936 final entryFutures = contents.mappedBy((entry) => entry.validate(dir)); | 937 final entryFutures = |
| 938 contents.mappedBy((entry) => entry.validate(dir)).toList(); |
| 937 | 939 |
| 938 // If they are all valid, the directory is valid. | 940 // If they are all valid, the directory is valid. |
| 939 return Futures.wait(entryFutures).transform((entries) => null); | 941 return Futures.wait(entryFutures).transform((entries) => null); |
| 940 }); | 942 }); |
| 941 } | 943 } |
| 942 | 944 |
| 943 /** | 945 /** |
| 944 * Loads [path] from within this directory. | 946 * Loads [path] from within this directory. |
| 945 */ | 947 */ |
| 946 InputStream load(List<String> path) { | 948 InputStream load(List<String> path) { |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1191 } | 1193 } |
| 1192 | 1194 |
| 1193 /** | 1195 /** |
| 1194 * Takes a simple data structure (composed of [Map]s, [List]s, scalar objects, | 1196 * Takes a simple data structure (composed of [Map]s, [List]s, scalar objects, |
| 1195 * and [Future]s) and recursively resolves all the [Future]s contained within. | 1197 * and [Future]s) and recursively resolves all the [Future]s contained within. |
| 1196 * Completes with the fully resolved structure. | 1198 * Completes with the fully resolved structure. |
| 1197 */ | 1199 */ |
| 1198 Future _awaitObject(object) { | 1200 Future _awaitObject(object) { |
| 1199 // Unroll nested futures. | 1201 // Unroll nested futures. |
| 1200 if (object is Future) return object.chain(_awaitObject); | 1202 if (object is Future) return object.chain(_awaitObject); |
| 1201 if (object is Collection) return Futures.wait(object.mappedBy(_awaitObject)); | 1203 if (object is Collection) { |
| 1204 return Futures.wait(object.mappedBy(_awaitObject).toList()); |
| 1205 } |
| 1202 if (object is! Map) return new Future.immediate(object); | 1206 if (object is! Map) return new Future.immediate(object); |
| 1203 | 1207 |
| 1204 var pairs = <Future<Pair>>[]; | 1208 var pairs = <Future<Pair>>[]; |
| 1205 object.forEach((key, value) { | 1209 object.forEach((key, value) { |
| 1206 pairs.add(_awaitObject(value) | 1210 pairs.add(_awaitObject(value) |
| 1207 .transform((resolved) => new Pair(key, resolved))); | 1211 .transform((resolved) => new Pair(key, resolved))); |
| 1208 }); | 1212 }); |
| 1209 return Futures.wait(pairs).transform((resolvedPairs) { | 1213 return Futures.wait(pairs).transform((resolvedPairs) { |
| 1210 var map = {}; | 1214 var map = {}; |
| 1211 for (var pair in resolvedPairs) { | 1215 for (var pair in resolvedPairs) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1224 } | 1228 } |
| 1225 | 1229 |
| 1226 /** | 1230 /** |
| 1227 * Schedules a callback to be called after Pub is run with [runPub], even if it | 1231 * Schedules a callback to be called after Pub is run with [runPub], even if it |
| 1228 * fails. | 1232 * fails. |
| 1229 */ | 1233 */ |
| 1230 void _scheduleCleanup(_ScheduledEvent event) { | 1234 void _scheduleCleanup(_ScheduledEvent event) { |
| 1231 if (_scheduledCleanup == null) _scheduledCleanup = []; | 1235 if (_scheduledCleanup == null) _scheduledCleanup = []; |
| 1232 _scheduledCleanup.add(event); | 1236 _scheduledCleanup.add(event); |
| 1233 } | 1237 } |
| OLD | NEW |