| 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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 /// The user-provided setUp function. This is set for each test during | 215 /// The user-provided setUp function. This is set for each test during |
| 216 /// `unittest.setUp`. | 216 /// `unittest.setUp`. |
| 217 Function _setUpFn; | 217 Function _setUpFn; |
| 218 | 218 |
| 219 /// Creates a new test case with the given description and body. | 219 /// Creates a new test case with the given description and body. |
| 220 /// | 220 /// |
| 221 /// This has the same semantics as [unittest.test]. | 221 /// This has the same semantics as [unittest.test]. |
| 222 /// | 222 /// |
| 223 /// If [body] returns a [Future], that future will automatically be wrapped with | 223 /// If [body] returns a [Future], that future will automatically be wrapped with |
| 224 /// [wrapFuture]. | 224 /// [wrapFuture]. |
| 225 void test(String description, Future body()) => | 225 void test(String description, body()) => |
| 226 _test(description, body, unittest.test); | 226 _test(description, body, unittest.test); |
| 227 | 227 |
| 228 /// Creates a new test case with the given description and body that will be the | 228 /// Creates a new test case with the given description and body that will be the |
| 229 /// only test run in this file. | 229 /// only test run in this file. |
| 230 /// | 230 /// |
| 231 /// This has the same semantics as [unittest.solo_test]. | 231 /// This has the same semantics as [unittest.solo_test]. |
| 232 /// | 232 /// |
| 233 /// If [body] returns a [Future], that future will automatically be wrapped with | 233 /// If [body] returns a [Future], that future will automatically be wrapped with |
| 234 /// [wrapFuture]. | 234 /// [wrapFuture]. |
| 235 void solo_test(String description, Future body()) => | 235 void solo_test(String description, body()) => |
| 236 _test(description, body, unittest.solo_test); | 236 _test(description, body, unittest.solo_test); |
| 237 | 237 |
| 238 void _test(String description, Future body(), Function testFn) { | 238 void _test(String description, body(), Function testFn) { |
| 239 maybeWrapFuture(future, description) { | 239 maybeWrapFuture(future, description) { |
| 240 if (future != null) wrapFuture(future, description); | 240 if (future != null) wrapFuture(future, description); |
| 241 } | 241 } |
| 242 | 242 |
| 243 unittest.ensureInitialized(); | 243 unittest.ensureInitialized(); |
| 244 _ensureSetUpForTopLevel(); | 244 _ensureSetUpForTopLevel(); |
| 245 testFn(description, () { | 245 testFn(description, () { |
| 246 var completer = new Completer(); | 246 var completer = new Completer(); |
| 247 | 247 |
| 248 Chain.capture(() { | 248 Chain.capture(() { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 currentSchedule.tasks.schedule(fn, description); | 302 currentSchedule.tasks.schedule(fn, description); |
| 303 | 303 |
| 304 /// Register a [setUp] function for a test [group]. This has the same semantics | 304 /// Register a [setUp] function for a test [group]. This has the same semantics |
| 305 /// as [unittest.setUp]. Tasks may be scheduled using [schedule] within | 305 /// as [unittest.setUp]. Tasks may be scheduled using [schedule] within |
| 306 /// [setUpFn], and [currentSchedule] may be accessed as well. | 306 /// [setUpFn], and [currentSchedule] may be accessed as well. |
| 307 /// | 307 /// |
| 308 /// Note that there is no associated [tearDown] function. Instead, tasks should | 308 /// Note that there is no associated [tearDown] function. Instead, tasks should |
| 309 /// be scheduled for [currentSchedule.onComplete] or | 309 /// be scheduled for [currentSchedule.onComplete] or |
| 310 /// [currentSchedule.onException]. These tasks will be run after each test's | 310 /// [currentSchedule.onException]. These tasks will be run after each test's |
| 311 /// schedule is completed. | 311 /// schedule is completed. |
| 312 void setUp(void setUpFn()) { | 312 void setUp(setUpFn()) { |
| 313 _setUpScheduledTest(setUpFn); | 313 _setUpScheduledTest(setUpFn); |
| 314 } | 314 } |
| 315 | 315 |
| 316 /// Whether [unittest.setUp] has been called in the top level scope. | 316 /// Whether [unittest.setUp] has been called in the top level scope. |
| 317 bool _setUpForTopLevel = false; | 317 bool _setUpForTopLevel = false; |
| 318 | 318 |
| 319 /// If we're in the top-level scope (that is, not in any [group]s) and | 319 /// If we're in the top-level scope (that is, not in any [group]s) and |
| 320 /// [unittest.setUp] hasn't been called yet, call it. | 320 /// [unittest.setUp] hasn't been called yet, call it. |
| 321 void _ensureSetUpForTopLevel() { | 321 void _ensureSetUpForTopLevel() { |
| 322 if (_inGroup || _setUpForTopLevel) return; | 322 if (_inGroup || _setUpForTopLevel) return; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 /// [description] provides an optional description of the future, which is | 379 /// [description] provides an optional description of the future, which is |
| 380 /// used when generating error messages. | 380 /// used when generating error messages. |
| 381 Future wrapFuture(Future future, [String description]) { | 381 Future wrapFuture(Future future, [String description]) { |
| 382 if (currentSchedule == null) { | 382 if (currentSchedule == null) { |
| 383 throw new StateError("Unexpected call to wrapFuture with no current " | 383 throw new StateError("Unexpected call to wrapFuture with no current " |
| 384 "schedule."); | 384 "schedule."); |
| 385 } | 385 } |
| 386 | 386 |
| 387 return currentSchedule.wrapFuture(future, description); | 387 return currentSchedule.wrapFuture(future, description); |
| 388 } | 388 } |
| OLD | NEW |