| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 | 77 |
| 78 future.then((error) { | 78 future.then((error) { |
| 79 // Null means there were no errors. | 79 // Null means there were no errors. |
| 80 if (error != null) Expect.fail(error); | 80 if (error != null) Expect.fail(error); |
| 81 | 81 |
| 82 deleteSandboxIfCreated(); | 82 deleteSandboxIfCreated(); |
| 83 }); | 83 }); |
| 84 | 84 |
| 85 future.handleException((error) { | 85 future.handleException((error) { |
| 86 deleteSandboxIfCreated(); | 86 deleteSandboxIfCreated(); |
| 87 return false; |
| 87 }); | 88 }); |
| 88 }); | 89 }); |
| 89 } | 90 } |
| 90 | 91 |
| 91 Future<Directory> _setUpSandbox() { | 92 Future<Directory> _setUpSandbox() { |
| 92 return createTempDir('pub-test-sandbox-'); | 93 return createTempDir('pub-test-sandbox-'); |
| 93 } | 94 } |
| 94 | 95 |
| 95 Future _setUpCache(Directory sandboxDir, List<Descriptor> cache) { | 96 Future _setUpCache(Directory sandboxDir, List<Descriptor> cache) { |
| 96 // No cache. | 97 // No cache. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 109 Future<ProcessResult> _runPub(List<String> pubArgs, String workingDir) { | 110 Future<ProcessResult> _runPub(List<String> pubArgs, String workingDir) { |
| 110 // Find a dart executable we can use to run pub. Uses the one that the | 111 // Find a dart executable we can use to run pub. Uses the one that the |
| 111 // test infrastructure uses. | 112 // test infrastructure uses. |
| 112 final scriptDir = new File(new Options().script).directorySync().path; | 113 final scriptDir = new File(new Options().script).directorySync().path; |
| 113 final platform = Platform.operatingSystem(); | 114 final platform = Platform.operatingSystem(); |
| 114 final dartBin = join(scriptDir, '../../../tools/testing/bin/$platform/dart'); | 115 final dartBin = join(scriptDir, '../../../tools/testing/bin/$platform/dart'); |
| 115 | 116 |
| 116 // Find the main pub entrypoint. | 117 // Find the main pub entrypoint. |
| 117 final pubPath = fs.joinPaths(scriptDir, '../../pub/pub.dart'); | 118 final pubPath = fs.joinPaths(scriptDir, '../../pub/pub.dart'); |
| 118 | 119 |
| 119 final args = [pubPath]; | 120 final args = ['--enable-type-checks', '--enable-asserts', pubPath]; |
| 120 args.addAll(pubArgs); | 121 args.addAll(pubArgs); |
| 121 | 122 |
| 122 return runProcess(dartBin, args, workingDir); | 123 return runProcess(dartBin, args, workingDir); |
| 123 } | 124 } |
| 124 | 125 |
| 125 /** | 126 /** |
| 126 * Validates the contents of the "packages" directory inside [appDir] against | 127 * Validates the contents of the "packages" directory inside [appDir] against |
| 127 * [expectedPackageDir]. | 128 * [expectedPackageDir]. |
| 128 */ | 129 */ |
| 129 Future<String> _validateExpectedPackages(Directory appDir, | 130 Future<String> _validateExpectedPackages(Directory appDir, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 * The short name of this file or directory. | 189 * The short name of this file or directory. |
| 189 */ | 190 */ |
| 190 final String name; | 191 final String name; |
| 191 | 192 |
| 192 Descriptor(this.name); | 193 Descriptor(this.name); |
| 193 | 194 |
| 194 /** | 195 /** |
| 195 * Creates the file or directory within [dir]. Returns a [Future] that is | 196 * Creates the file or directory within [dir]. Returns a [Future] that is |
| 196 * completed after the creation is done. | 197 * completed after the creation is done. |
| 197 */ | 198 */ |
| 198 abstract Future create(String dir); | 199 abstract Future create(dir); |
| 199 | 200 |
| 200 /** | 201 /** |
| 201 * Validates that this descriptor correctly matches the corresponding file | 202 * Validates that this descriptor correctly matches the corresponding file |
| 202 * system entry within [dir]. Returns a [Future] that completes to `null` if | 203 * system entry within [dir]. Returns a [Future] that completes to `null` if |
| 203 * the entry is valid, or a message describing the error if it failed. | 204 * the entry is valid, or a message describing the error if it failed. |
| 204 */ | 205 */ |
| 205 abstract Future<String> validate(String dir); | 206 abstract Future<String> validate(String dir); |
| 206 } | 207 } |
| 207 | 208 |
| 208 /** | 209 /** |
| 209 * Describes a file. These are used both for setting up an expected directory | 210 * Describes a file. These are used both for setting up an expected directory |
| 210 * tree before running a test, and for validating that the file system matches | 211 * tree before running a test, and for validating that the file system matches |
| 211 * some expectations after running it. | 212 * some expectations after running it. |
| 212 */ | 213 */ |
| 213 class FileDescriptor extends Descriptor { | 214 class FileDescriptor extends Descriptor { |
| 214 /** | 215 /** |
| 215 * The text contents of the file. | 216 * The text contents of the file. |
| 216 */ | 217 */ |
| 217 final String contents; | 218 final String contents; |
| 218 | 219 |
| 219 FileDescriptor(String name, this.contents) : super(name); | 220 FileDescriptor(String name, this.contents) : super(name); |
| 220 | 221 |
| 221 /** | 222 /** |
| 222 * Creates the file within [dir]. Returns a [Future] that is completed after | 223 * Creates the file within [dir]. Returns a [Future] that is completed after |
| 223 * the creation is done. | 224 * the creation is done. |
| 224 */ | 225 */ |
| 225 Future<File> create(String dir) { | 226 Future<File> create(dir) { |
| 226 return writeTextFile(join(dir, name), contents); | 227 return writeTextFile(join(dir, name), contents); |
| 227 } | 228 } |
| 228 | 229 |
| 229 /** | 230 /** |
| 230 * Validates that this file correctly matches the actual file at [path]. | 231 * Validates that this file correctly matches the actual file at [path]. |
| 231 */ | 232 */ |
| 232 Future<String> validate(String path) { | 233 Future<String> validate(String path) { |
| 233 path = join(path, name); | 234 path = join(path, name); |
| 234 return fileExists(path).chain((exists) { | 235 return fileExists(path).chain((exists) { |
| 235 if (!exists) { | 236 if (!exists) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 256 * The files and directories contained in this directory. | 257 * The files and directories contained in this directory. |
| 257 */ | 258 */ |
| 258 final List<Descriptor> contents; | 259 final List<Descriptor> contents; |
| 259 | 260 |
| 260 DirectoryDescriptor(String name, this.contents) : super(name); | 261 DirectoryDescriptor(String name, this.contents) : super(name); |
| 261 | 262 |
| 262 /** | 263 /** |
| 263 * Creates the file within [dir]. Returns a [Future] that is completed after | 264 * Creates the file within [dir]. Returns a [Future] that is completed after |
| 264 * the creation is done. | 265 * the creation is done. |
| 265 */ | 266 */ |
| 266 Future<Directory> create(String parentDir) { | 267 Future<Directory> create(parentDir) { |
| 267 final completer = new Completer<Directory>(); | 268 final completer = new Completer<Directory>(); |
| 268 | 269 |
| 269 // Create the directory. | 270 // Create the directory. |
| 270 createDir(join(parentDir, name)).then((dir) { | 271 createDir(join(parentDir, name)).then((dir) { |
| 271 if (contents == null) { | 272 if (contents == null) { |
| 272 completer.complete(dir); | 273 completer.complete(dir); |
| 273 } else { | 274 } else { |
| 274 // Recursively create all of its children. | 275 // Recursively create all of its children. |
| 275 final childFutures = contents.map((child) => child.create(dir.path)); | 276 final childFutures = contents.map((child) => child.create(dir)); |
| 276 Futures.wait(childFutures).then((_) { | 277 Futures.wait(childFutures).then((_) { |
| 277 // Only complete once all of the children have been created too. | 278 // Only complete once all of the children have been created too. |
| 278 completer.complete(dir); | 279 completer.complete(dir); |
| 279 }); | 280 }); |
| 280 } | 281 } |
| 281 }); | 282 }); |
| 282 | 283 |
| 283 return completer.future; | 284 return completer.future; |
| 284 } | 285 } |
| 285 | 286 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 298 return Futures.wait(entryFutures).transform((entries) { | 299 return Futures.wait(entryFutures).transform((entries) { |
| 299 for (final entry in entries) { | 300 for (final entry in entries) { |
| 300 if (entry != null) return entry; | 301 if (entry != null) return entry; |
| 301 } | 302 } |
| 302 | 303 |
| 303 // If we got here, all of the sub-entries were valid. | 304 // If we got here, all of the sub-entries were valid. |
| 304 return null; | 305 return null; |
| 305 }); | 306 }); |
| 306 } | 307 } |
| 307 } | 308 } |
| OLD | NEW |