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 /// Test infrastructure for testing pub. Unlike typical unit tests, most pub | 5 /// Test infrastructure for testing pub. Unlike typical unit tests, most pub |
6 /// tests are integration tests that stage some stuff on the file system, run | 6 /// tests are integration tests that stage some stuff on the file system, run |
7 /// pub, and then validate the results. This library provides an API to build | 7 /// pub, and then validate the results. This library provides an API to build |
8 /// tests like that. | 8 /// tests like that. |
9 library test_pub; | 9 library test_pub; |
10 | 10 |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 /// Describes a file named `pubspec.yaml` for an application package with the | 236 /// Describes a file named `pubspec.yaml` for an application package with the |
237 /// given [dependencies]. | 237 /// given [dependencies]. |
238 Descriptor appPubspec(List dependencies) { | 238 Descriptor appPubspec(List dependencies) { |
239 return pubspec({ | 239 return pubspec({ |
240 "name": "myapp", | 240 "name": "myapp", |
241 "dependencies": _dependencyListToMap(dependencies) | 241 "dependencies": _dependencyListToMap(dependencies) |
242 }); | 242 }); |
243 } | 243 } |
244 | 244 |
245 /// Describes a file named `pubspec.yaml` for a library package with the given | 245 /// Describes a file named `pubspec.yaml` for a library package with the given |
246 /// [name], [version], and [dependencies]. | 246 /// [name], [version], and [deps]. If "sdk" is given, then it adds an SDK |
247 Descriptor libPubspec(String name, String version, [List dependencies]) => | 247 /// constraint on that version. |
248 pubspec(package(name, version, dependencies)); | 248 Descriptor libPubspec(String name, String version, {List deps, String sdk}) { |
| 249 var map = package(name, version, deps); |
| 250 |
| 251 if (sdk != null) { |
| 252 map["environment"] = { |
| 253 "sdk": sdk |
| 254 }; |
| 255 } |
| 256 |
| 257 return pubspec(map); |
| 258 } |
249 | 259 |
250 /// Describes a directory named `lib` containing a single dart file named | 260 /// Describes a directory named `lib` containing a single dart file named |
251 /// `<name>.dart` that contains a line of Dart code. | 261 /// `<name>.dart` that contains a line of Dart code. |
252 Descriptor libDir(String name, [String code]) { | 262 Descriptor libDir(String name, [String code]) { |
253 // Default to printing the name if no other code was given. | 263 // Default to printing the name if no other code was given. |
254 if (code == null) { | 264 if (code == null) { |
255 code = name; | 265 code = name; |
256 } | 266 } |
257 | 267 |
258 return dir("lib", [ | 268 return dir("lib", [ |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 bool _abortScheduled = false; | 470 bool _abortScheduled = false; |
461 | 471 |
462 /// The time (in milliseconds) to wait for the entire scheduled test to | 472 /// The time (in milliseconds) to wait for the entire scheduled test to |
463 /// complete. | 473 /// complete. |
464 final _TIMEOUT = 30000; | 474 final _TIMEOUT = 30000; |
465 | 475 |
466 /// Defines an integration test. The [body] should schedule a series of | 476 /// Defines an integration test. The [body] should schedule a series of |
467 /// operations which will be run asynchronously. | 477 /// operations which will be run asynchronously. |
468 void integration(String description, void body()) { | 478 void integration(String description, void body()) { |
469 test(description, () { | 479 test(description, () { |
| 480 // Ensure the SDK version is always available. |
| 481 dir(sdkPath, [ |
| 482 file('version', '0.1.2.3') |
| 483 ]).scheduleCreate(); |
| 484 |
470 // Schedule the test. | 485 // Schedule the test. |
471 body(); | 486 body(); |
472 | 487 |
473 // Run all of the scheduled tasks. If an error occurs, it will propagate | 488 // Run all of the scheduled tasks. If an error occurs, it will propagate |
474 // through the futures back up to here where we can hand it off to unittest. | 489 // through the futures back up to here where we can hand it off to unittest. |
475 var asyncDone = expectAsync0(() {}); | 490 var asyncDone = expectAsync0(() {}); |
476 var createdSandboxDir; | 491 var createdSandboxDir; |
477 _setUpSandbox().then((sandboxDir) { | 492 _setUpSandbox().then((sandboxDir) { |
478 createdSandboxDir = sandboxDir; | 493 createdSandboxDir = sandboxDir; |
479 return timeout(_runScheduled(sandboxDir, _scheduled), | 494 return timeout(_runScheduled(sandboxDir, _scheduled), |
(...skipping 1079 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1559 /// calling [completion] is unnecessary. | 1574 /// calling [completion] is unnecessary. |
1560 void expectLater(Future actual, matcher, {String reason, | 1575 void expectLater(Future actual, matcher, {String reason, |
1561 FailureHandler failureHandler, bool verbose: false}) { | 1576 FailureHandler failureHandler, bool verbose: false}) { |
1562 _schedule((_) { | 1577 _schedule((_) { |
1563 return actual.then((value) { | 1578 return actual.then((value) { |
1564 expect(value, matcher, reason: reason, failureHandler: failureHandler, | 1579 expect(value, matcher, reason: reason, failureHandler: failureHandler, |
1565 verbose: false); | 1580 verbose: false); |
1566 }); | 1581 }); |
1567 }); | 1582 }); |
1568 } | 1583 } |
OLD | NEW |