| 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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 _ensureInitialized(); | 231 _ensureInitialized(); |
| 232 _ensureSetUpForTopLevel(); | 232 _ensureSetUpForTopLevel(); |
| 233 testFn(description, () { | 233 testFn(description, () { |
| 234 var completer = new Completer(); | 234 var completer = new Completer(); |
| 235 | 235 |
| 236 Chain.capture(() { | 236 Chain.capture(() { |
| 237 _currentSchedule = new Schedule(); | 237 _currentSchedule = new Schedule(); |
| 238 return currentSchedule.run(() { | 238 return currentSchedule.run(() { |
| 239 if (_setUpFn != null) _setUpFn(); | 239 if (_setUpFn != null) _setUpFn(); |
| 240 body(); | 240 body(); |
| 241 }).catchError((error, stackTrace) { |
| 242 if (error is ScheduleError) { |
| 243 assert(error.schedule.errors.contains(error)); |
| 244 assert(error.schedule == currentSchedule); |
| 245 unittest.registerException(error.schedule.errorString()); |
| 246 } else { |
| 247 unittest.registerException(error, new Chain.forTrace(stackTrace)); |
| 248 } |
| 241 }).then(completer.complete); | 249 }).then(completer.complete); |
| 242 }, onError: (e, chain) { | 250 }, onError: (error, chain) => currentSchedule.signalError(error, chain)); |
| 243 if (e is ScheduleError) { | |
| 244 assert(e.schedule.errors.contains(e)); | |
| 245 assert(e.schedule == currentSchedule); | |
| 246 unittest.registerException(e.schedule.errorString()); | |
| 247 } else { | |
| 248 unittest.registerException(e, chain); | |
| 249 } | |
| 250 completer.complete(); | |
| 251 }); | |
| 252 | 251 |
| 253 return completer.future; | 252 return completer.future; |
| 254 }); | 253 }); |
| 255 } | 254 } |
| 256 | 255 |
| 257 /// Whether or not the tests currently being defined are in a group. This is | 256 /// Whether or not the tests currently being defined are in a group. This is |
| 258 /// only true when defining tests, not when executing them. | 257 /// only true when defining tests, not when executing them. |
| 259 bool _inGroup = false; | 258 bool _inGroup = false; |
| 260 | 259 |
| 261 /// Creates a new named group of tests. This has the same semantics as | 260 /// Creates a new named group of tests. This has the same semantics as |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 /// [description] provides an optional description of the future, which is | 369 /// [description] provides an optional description of the future, which is |
| 371 /// used when generating error messages. | 370 /// used when generating error messages. |
| 372 Future wrapFuture(Future future, [String description]) { | 371 Future wrapFuture(Future future, [String description]) { |
| 373 if (currentSchedule == null) { | 372 if (currentSchedule == null) { |
| 374 throw new StateError("Unexpected call to wrapFuture with no current " | 373 throw new StateError("Unexpected call to wrapFuture with no current " |
| 375 "schedule."); | 374 "schedule."); |
| 376 } | 375 } |
| 377 | 376 |
| 378 return currentSchedule.wrapFuture(future, description); | 377 return currentSchedule.wrapFuture(future, description); |
| 379 } | 378 } |
| OLD | NEW |