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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 /// Describes a file named `pubspec.yaml` for an application package with the | 231 /// Describes a file named `pubspec.yaml` for an application package with the |
232 /// given [dependencies]. | 232 /// given [dependencies]. |
233 Descriptor appPubspec(List dependencies) { | 233 Descriptor appPubspec(List dependencies) { |
234 return pubspec({ | 234 return pubspec({ |
235 "name": "myapp", | 235 "name": "myapp", |
236 "dependencies": _dependencyListToMap(dependencies) | 236 "dependencies": _dependencyListToMap(dependencies) |
237 }); | 237 }); |
238 } | 238 } |
239 | 239 |
240 /// Describes a file named `pubspec.yaml` for a library package with the given | 240 /// Describes a file named `pubspec.yaml` for a library package with the given |
241 /// [name], [version], and [dependencies]. | 241 /// [name], [version], and [deps]. If "sdk" is given, then it adds an SDK |
242 Descriptor libPubspec(String name, String version, [List dependencies]) => | 242 /// constraint on that version. |
243 pubspec(package(name, version, dependencies)); | 243 Descriptor libPubspec(String name, String version, {List deps, String sdk}) { |
| 244 var map = package(name, version, deps); |
| 245 |
| 246 if (sdk != null) { |
| 247 map["environment"] = { |
| 248 "sdk": sdk |
| 249 }; |
| 250 } |
| 251 |
| 252 return pubspec(map); |
| 253 } |
244 | 254 |
245 /// Describes a directory named `lib` containing a single dart file named | 255 /// Describes a directory named `lib` containing a single dart file named |
246 /// `<name>.dart` that contains a line of Dart code. | 256 /// `<name>.dart` that contains a line of Dart code. |
247 Descriptor libDir(String name, [String code]) { | 257 Descriptor libDir(String name, [String code]) { |
248 // Default to printing the name if no other code was given. | 258 // Default to printing the name if no other code was given. |
249 if (code == null) { | 259 if (code == null) { |
250 code = name; | 260 code = name; |
251 } | 261 } |
252 | 262 |
253 return dir("lib", [ | 263 return dir("lib", [ |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 bool _abortScheduled = false; | 465 bool _abortScheduled = false; |
456 | 466 |
457 /// The time (in milliseconds) to wait for the entire scheduled test to | 467 /// The time (in milliseconds) to wait for the entire scheduled test to |
458 /// complete. | 468 /// complete. |
459 final _TIMEOUT = 30000; | 469 final _TIMEOUT = 30000; |
460 | 470 |
461 /// Defines an integration test. The [body] should schedule a series of | 471 /// Defines an integration test. The [body] should schedule a series of |
462 /// operations which will be run asynchronously. | 472 /// operations which will be run asynchronously. |
463 void integration(String description, void body()) { | 473 void integration(String description, void body()) { |
464 test(description, () { | 474 test(description, () { |
| 475 // Ensure the SDK version is always available. |
| 476 dir(sdkPath, [ |
| 477 file('version', '0.1.2.3') |
| 478 ]).scheduleCreate(); |
| 479 |
465 // Schedule the test. | 480 // Schedule the test. |
466 body(); | 481 body(); |
467 | 482 |
468 // Run all of the scheduled tasks. If an error occurs, it will propagate | 483 // Run all of the scheduled tasks. If an error occurs, it will propagate |
469 // through the futures back up to here where we can hand it off to unittest. | 484 // through the futures back up to here where we can hand it off to unittest. |
470 var asyncDone = expectAsync0(() {}); | 485 var asyncDone = expectAsync0(() {}); |
471 var createdSandboxDir; | 486 var createdSandboxDir; |
472 _setUpSandbox().then((sandboxDir) { | 487 _setUpSandbox().then((sandboxDir) { |
473 createdSandboxDir = sandboxDir; | 488 createdSandboxDir = sandboxDir; |
474 return timeout(_runScheduled(sandboxDir, _scheduled), | 489 return timeout(_runScheduled(sandboxDir, _scheduled), |
(...skipping 1075 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1550 /// calling [completion] is unnecessary. | 1565 /// calling [completion] is unnecessary. |
1551 void expectLater(Future actual, matcher, {String reason, | 1566 void expectLater(Future actual, matcher, {String reason, |
1552 FailureHandler failureHandler, bool verbose: false}) { | 1567 FailureHandler failureHandler, bool verbose: false}) { |
1553 _schedule((_) { | 1568 _schedule((_) { |
1554 return actual.then((value) { | 1569 return actual.then((value) { |
1555 expect(value, matcher, reason: reason, failureHandler: failureHandler, | 1570 expect(value, matcher, reason: reason, failureHandler: failureHandler, |
1556 verbose: false); | 1571 verbose: false); |
1557 }); | 1572 }); |
1558 }); | 1573 }); |
1559 } | 1574 } |
OLD | NEW |