| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // TODO(nweiz): Add support for calling [schedule] while the schedule is already | 5 // TODO(nweiz): Add support for calling [schedule] while the schedule is already |
| 6 // running. | 6 // running. |
| 7 // TODO(nweiz): Port the non-Pub-specific scheduled test libraries from Pub. | 7 // TODO(nweiz): Port the non-Pub-specific scheduled test libraries from Pub. |
| 8 /// A package for writing readable tests of asynchronous behavior. | 8 /// A package for writing readable tests of asynchronous behavior. |
| 9 /// | 9 /// |
| 10 /// ## Installing ## | 10 /// ## Installing ## |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 /// | 42 /// |
| 43 /// schedule(() { | 43 /// schedule(() { |
| 44 /// return new File("output.txt").readAsString().then((contents) { | 44 /// return new File("output.txt").readAsString().then((contents) { |
| 45 /// // The normal unittest matchers can still be used. | 45 /// // The normal unittest matchers can still be used. |
| 46 /// expect(contents, equals("contents")); | 46 /// expect(contents, equals("contents")); |
| 47 /// }); | 47 /// }); |
| 48 /// }); | 48 /// }); |
| 49 /// }); | 49 /// }); |
| 50 /// } | 50 /// } |
| 51 /// | 51 /// |
| 52 /// ## Setting Up and Tearing Down | 52 /// ## Setting up and tearing down |
| 53 /// | 53 /// |
| 54 /// The `scheduled_test` package defines its own [setUp] method that works just | 54 /// The `scheduled_test` package defines its own [setUp] method that works just |
| 55 /// like the one in `unittest`. Tasks can be scheduled in [setUp]; they'll be | 55 /// like the one in `unittest`. Tasks can be scheduled in [setUp]; they'll be |
| 56 /// run before the tasks scheduled by tests in that group. [currentSchedule] is | 56 /// run before the tasks scheduled by tests in that group. [currentSchedule] is |
| 57 /// also set in the [setUp] callback. | 57 /// also set in the [setUp] callback. |
| 58 /// | 58 /// |
| 59 /// This package doesn't have an explicit `tearDown` method. Instead, the | 59 /// This package doesn't have an explicit `tearDown` method. Instead, the |
| 60 /// [currentSchedule.onComplete] and [currentSchedule.onException] task queues | 60 /// [currentSchedule.onComplete] and [currentSchedule.onException] task queues |
| 61 /// can have tasks scheduled during [setUp]. For example: | 61 /// can have tasks scheduled during [setUp]. For example: |
| 62 /// | 62 /// |
| 63 /// import 'package:scheduled_test/scheduled_test.dart'; | 63 /// import 'package:scheduled_test/scheduled_test.dart'; |
| 64 /// | 64 /// |
| 65 /// void main() { | 65 /// void main() { |
| 66 /// var tempDir; | 66 /// var tempDir; |
| 67 /// setUp(() { | 67 /// setUp(() { |
| 68 /// schedule(() { | 68 /// schedule(() { |
| 69 /// return createTempDir().then((dir) { | 69 /// return createTempDir().then((dir) { |
| 70 /// tempDir = dir; | 70 /// tempDir = dir; |
| 71 /// }); | 71 /// }); |
| 72 /// }); | 72 /// }); |
| 73 /// | 73 /// |
| 74 /// currentSchedule.onComplete.schedule(() => deleteDir(tempDir)); | 74 /// currentSchedule.onComplete.schedule(() => deleteDir(tempDir)); |
| 75 /// }); | 75 /// }); |
| 76 /// | 76 /// |
| 77 /// // ... | 77 /// // ... |
| 78 /// } | 78 /// } |
| 79 /// | 79 /// |
| 80 /// ## Passing Values Between Tasks | 80 /// ## Passing values between tasks |
| 81 /// | 81 /// |
| 82 /// It's often useful to use values computed in one task in other tasks that are | 82 /// It's often useful to use values computed in one task in other tasks that are |
| 83 /// scheduled afterwards. There are two ways to do this. The most | 83 /// scheduled afterwards. There are two ways to do this. The most |
| 84 /// straightforward is just to define a local variable and assign to it. For | 84 /// straightforward is just to define a local variable and assign to it. For |
| 85 /// example: | 85 /// example: |
| 86 /// | 86 /// |
| 87 /// import 'package:scheduled_test/scheduled_test.dart'; | 87 /// import 'package:scheduled_test/scheduled_test.dart'; |
| 88 /// | 88 /// |
| 89 /// void main() { | 89 /// void main() { |
| 90 /// test('computeValue returns 12', () { | 90 /// test('computeValue returns 12', () { |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 /// [description] provides an optional description of the future, which is | 368 /// [description] provides an optional description of the future, which is |
| 369 /// used when generating error messages. | 369 /// used when generating error messages. |
| 370 Future wrapFuture(Future future, [String description]) { | 370 Future wrapFuture(Future future, [String description]) { |
| 371 if (currentSchedule == null) { | 371 if (currentSchedule == null) { |
| 372 throw new StateError("Unexpected call to wrapFuture with no current " | 372 throw new StateError("Unexpected call to wrapFuture with no current " |
| 373 "schedule."); | 373 "schedule."); |
| 374 } | 374 } |
| 375 | 375 |
| 376 return currentSchedule.wrapFuture(future, description); | 376 return currentSchedule.wrapFuture(future, description); |
| 377 } | 377 } |
| OLD | NEW |