| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 deleteSandboxIfCreated(); | 80 deleteSandboxIfCreated(); |
| 81 }); | 81 }); |
| 82 | 82 |
| 83 future.handleException((error) { | 83 future.handleException((error) { |
| 84 deleteSandboxIfCreated(); | 84 deleteSandboxIfCreated(); |
| 85 }); | 85 }); |
| 86 }); | 86 }); |
| 87 } | 87 } |
| 88 | 88 |
| 89 Future<Directory> _setUpSandbox() { | 89 Future<Directory> _setUpSandbox() { |
| 90 return createTempDir('pub-test-sandbox-'); | 90 return cleanDir('pub-test-sandbox'); |
| 91 } | 91 } |
| 92 | 92 |
| 93 Future _setUpCache(Directory sandboxDir, List<Descriptor> cache) { | 93 Future _setUpCache(Directory sandboxDir, List<Descriptor> cache) { |
| 94 // No cache. | 94 // No cache. |
| 95 if (cache == null) return new Future.immediate(null); | 95 if (cache == null) return new Future.immediate(null); |
| 96 | 96 |
| 97 return dir('pub-cache', cache).create(sandboxDir); | 97 return dir('pub-cache', cache).create(sandboxDir); |
| 98 } | 98 } |
| 99 | 99 |
| 100 Future _setUpApp(Directory sandboxDir, Descriptor app) { | 100 Future _setUpApp(Directory sandboxDir, Descriptor app) { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 | 185 |
| 186 Descriptor(this.name); | 186 Descriptor(this.name); |
| 187 | 187 |
| 188 /** | 188 /** |
| 189 * Creates the file or directory within [dir]. Returns a [Future] that is | 189 * Creates the file or directory within [dir]. Returns a [Future] that is |
| 190 * completed after the creation is done. | 190 * completed after the creation is done. |
| 191 */ | 191 */ |
| 192 abstract Future create(String dir); | 192 abstract Future create(String dir); |
| 193 | 193 |
| 194 /** | 194 /** |
| 195 * Validates that this descriptor correctly matches the actual file system | 195 * Validates that this descriptor correctly matches the corresponding file |
| 196 * entry at [path]. Returns a [Future] that completes when the validation is | 196 * system entry within [dir]. Returns a [Future] that completes when the |
| 197 * done. | 197 * validation is done. |
| 198 */ | 198 */ |
| 199 abstract Future<bool> validate(String path); | 199 abstract Future<bool> validate(String dir); |
| 200 } | 200 } |
| 201 | 201 |
| 202 /** | 202 /** |
| 203 * Describes a file. These are used both for setting up an expected directory | 203 * Describes a file. These are used both for setting up an expected directory |
| 204 * tree before running a test, and for validating that the file system matches | 204 * tree before running a test, and for validating that the file system matches |
| 205 * some expectations after running it. | 205 * some expectations after running it. |
| 206 */ | 206 */ |
| 207 class FileDescriptor extends Descriptor { | 207 class FileDescriptor extends Descriptor { |
| 208 /** | 208 /** |
| 209 * The text contents of the file. | 209 * The text contents of the file. |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 // Validate each of the items in this directory. | 280 // Validate each of the items in this directory. |
| 281 final entryFutures = contents.map( | 281 final entryFutures = contents.map( |
| 282 (entry) => entry.validate(join(path, name))); | 282 (entry) => entry.validate(join(path, name))); |
| 283 | 283 |
| 284 // If they are all valid, the directory is valid. | 284 // If they are all valid, the directory is valid. |
| 285 return Futures.wait(entryFutures).transform((entries) { | 285 return Futures.wait(entryFutures).transform((entries) { |
| 286 return !entries.some((valid) => !valid); | 286 return !entries.some((valid) => !valid); |
| 287 }); | 287 }); |
| 288 } | 288 } |
| 289 } | 289 } |
| OLD | NEW |