| 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 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 */ | 221 */ |
| 222 Descriptor pubspec(Map contents) { | 222 Descriptor pubspec(Map contents) { |
| 223 return async(_awaitObject(contents).transform((resolvedContents) => | 223 return async(_awaitObject(contents).transform((resolvedContents) => |
| 224 file("pubspec.yaml", yaml(resolvedContents)))); | 224 file("pubspec.yaml", yaml(resolvedContents)))); |
| 225 } | 225 } |
| 226 | 226 |
| 227 /** | 227 /** |
| 228 * Describes a file named `pubspec.yaml` for an application package with the | 228 * Describes a file named `pubspec.yaml` for an application package with the |
| 229 * given [dependencies]. | 229 * given [dependencies]. |
| 230 */ | 230 */ |
| 231 Descriptor appPubspec(List dependencies) => | 231 Descriptor appPubspec(List dependencies) { |
| 232 pubspec({"dependencies": _dependencyListToMap(dependencies)}); | 232 return pubspec({ |
| 233 "name": "myapp", |
| 234 "dependencies": _dependencyListToMap(dependencies) |
| 235 }); |
| 236 } |
| 233 | 237 |
| 234 /** | 238 /** |
| 235 * Describes a file named `pubspec.yaml` for a library package with the given | 239 * Describes a file named `pubspec.yaml` for a library package with the given |
| 236 * [name], [version], and [dependencies]. | 240 * [name], [version], and [dependencies]. |
| 237 */ | 241 */ |
| 238 Descriptor libPubspec(String name, String version, [List dependencies]) => | 242 Descriptor libPubspec(String name, String version, [List dependencies]) => |
| 239 pubspec(package(name, version, dependencies)); | 243 pubspec(package(name, version, dependencies)); |
| 240 | 244 |
| 241 /** | 245 /** |
| 242 * Describes a map representing a library package with the given [name], | 246 * Describes a map representing a library package with the given [name], |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 | 436 |
| 433 final future = _setUpSandbox().chain((sandboxDir) { | 437 final future = _setUpSandbox().chain((sandboxDir) { |
| 434 createdSandboxDir = sandboxDir; | 438 createdSandboxDir = sandboxDir; |
| 435 return _runScheduled(sandboxDir, _scheduled); | 439 return _runScheduled(sandboxDir, _scheduled); |
| 436 }); | 440 }); |
| 437 | 441 |
| 438 future.handleException((error) { | 442 future.handleException((error) { |
| 439 // If an error occurs during testing, delete the sandbox, throw the error so | 443 // If an error occurs during testing, delete the sandbox, throw the error so |
| 440 // that the test framework sees it, then finally call asyncDone so that the | 444 // that the test framework sees it, then finally call asyncDone so that the |
| 441 // test framework knows we're done doing asynchronous stuff. | 445 // test framework knows we're done doing asynchronous stuff. |
| 442 cleanup().then((_) { | 446 cleanup().then((_) => registerException(error, future.stackTrace)); |
| 443 registerException(error, future.stackTrace); | |
| 444 asyncDone(); | |
| 445 }); | |
| 446 return true; | 447 return true; |
| 447 }); | 448 }); |
| 448 | 449 |
| 449 future.chain((_) => cleanup()).then((_) => asyncDone()); | 450 future.chain((_) => cleanup()).then((_) { |
| 451 asyncDone(); |
| 452 }); |
| 450 } | 453 } |
| 451 | 454 |
| 452 /** | 455 /** |
| 453 * Schedules a call to the Pub command-line utility. Runs Pub with [args] and | 456 * Schedules a call to the Pub command-line utility. Runs Pub with [args] and |
| 454 * validates that its results match [output], [error], and [exitCode]. | 457 * validates that its results match [output], [error], and [exitCode]. |
| 455 */ | 458 */ |
| 456 void schedulePub([List<String> args, Pattern output, Pattern error, | 459 void schedulePub([List<String> args, Pattern output, Pattern error, |
| 457 int exitCode = 0]) { | 460 int exitCode = 0]) { |
| 458 _schedule((sandboxDir) { | 461 _schedule((sandboxDir) { |
| 459 String pathInSandbox(path) => join(getFullPath(sandboxDir), path); | 462 String pathInSandbox(path) => join(getFullPath(sandboxDir), path); |
| (...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1052 } | 1055 } |
| 1053 | 1056 |
| 1054 /** | 1057 /** |
| 1055 * Schedules a callback to be called after Pub is run with [runPub], even if it | 1058 * Schedules a callback to be called after Pub is run with [runPub], even if it |
| 1056 * fails. | 1059 * fails. |
| 1057 */ | 1060 */ |
| 1058 void _scheduleCleanup(_ScheduledEvent event) { | 1061 void _scheduleCleanup(_ScheduledEvent event) { |
| 1059 if (_scheduledCleanup == null) _scheduledCleanup = []; | 1062 if (_scheduledCleanup == null) _scheduledCleanup = []; |
| 1060 _scheduledCleanup.add(event); | 1063 _scheduledCleanup.add(event); |
| 1061 } | 1064 } |
| OLD | NEW |