| 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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 void _test(String description, 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 // Capture this in a local variable in case we capture an out-of-band error |
| 249 // after the schedule completes. |
| 250 var errorHandler; |
| 251 |
| 248 Chain.capture(() { | 252 Chain.capture(() { |
| 249 _currentSchedule = new Schedule(); | 253 _currentSchedule = new Schedule(); |
| 254 errorHandler = _currentSchedule.signalError; |
| 250 return currentSchedule.run(() { | 255 return currentSchedule.run(() { |
| 251 if (_setUpFn != null) maybeWrapFuture(_setUpFn(), "set up"); | 256 if (_setUpFn != null) maybeWrapFuture(_setUpFn(), "set up"); |
| 252 maybeWrapFuture(body(), "test body"); | 257 maybeWrapFuture(body(), "test body"); |
| 253 }).catchError((error, stackTrace) { | 258 }).catchError((error, stackTrace) { |
| 254 if (error is ScheduleError) { | 259 if (error is ScheduleError) { |
| 255 assert(error.schedule.errors.contains(error)); | 260 assert(error.schedule.errors.contains(error)); |
| 256 assert(error.schedule == currentSchedule); | 261 assert(error.schedule == currentSchedule); |
| 257 unittest.registerException(error.schedule.errorString()); | 262 unittest.registerException(error.schedule.errorString()); |
| 258 } else { | 263 } else { |
| 259 unittest.registerException(error, new Chain.forTrace(stackTrace)); | 264 unittest.registerException(error, new Chain.forTrace(stackTrace)); |
| 260 } | 265 } |
| 261 }).then(completer.complete); | 266 }).then(completer.complete); |
| 262 }, onError: (error, chain) => currentSchedule.signalError(error, chain)); | 267 }, onError: (error, stackTrace) => errorHandler(error, stackTrace)); |
| 263 | 268 |
| 264 return completer.future; | 269 return completer.future; |
| 265 }); | 270 }); |
| 266 } | 271 } |
| 267 | 272 |
| 268 /// Whether or not the tests currently being defined are in a group. This is | 273 /// Whether or not the tests currently being defined are in a group. This is |
| 269 /// only true when defining tests, not when executing them. | 274 /// only true when defining tests, not when executing them. |
| 270 bool _inGroup = false; | 275 bool _inGroup = false; |
| 271 | 276 |
| 272 /// Creates a new named group of tests. This has the same semantics as | 277 /// Creates a new named group of tests. This has the same semantics as |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 /// [description] provides an optional description of the future, which is | 384 /// [description] provides an optional description of the future, which is |
| 380 /// used when generating error messages. | 385 /// used when generating error messages. |
| 381 Future wrapFuture(Future future, [String description]) { | 386 Future wrapFuture(Future future, [String description]) { |
| 382 if (currentSchedule == null) { | 387 if (currentSchedule == null) { |
| 383 throw new StateError("Unexpected call to wrapFuture with no current " | 388 throw new StateError("Unexpected call to wrapFuture with no current " |
| 384 "schedule."); | 389 "schedule."); |
| 385 } | 390 } |
| 386 | 391 |
| 387 return currentSchedule.wrapFuture(future, description); | 392 return currentSchedule.wrapFuture(future, description); |
| 388 } | 393 } |
| OLD | NEW |