Chromium Code Reviews| 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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 /// [unittest.solo_test]. | 226 /// [unittest.solo_test]. |
| 227 void solo_test(String description, void body()) => | 227 void solo_test(String description, void body()) => |
| 228 _test(description, body, unittest.solo_test); | 228 _test(description, body, unittest.solo_test); |
| 229 | 229 |
| 230 void _test(String description, void body(), Function testFn) { | 230 void _test(String description, void body(), Function testFn) { |
| 231 unittest.ensureInitialized(); | 231 unittest.ensureInitialized(); |
| 232 _ensureSetUpForTopLevel(); | 232 _ensureSetUpForTopLevel(); |
| 233 testFn(description, () { | 233 testFn(description, () { |
| 234 var completer = new Completer(); | 234 var completer = new Completer(); |
| 235 | 235 |
| 236 var errorHandler; | |
|
nweiz
2014/04/08 19:27:36
Add a comment: "Capture this in a local variable i
kevmoo
2014/04/08 20:17:51
Done.
| |
| 237 | |
| 236 Chain.capture(() { | 238 Chain.capture(() { |
| 237 _currentSchedule = new Schedule(); | 239 _currentSchedule = new Schedule(); |
| 240 errorHandler = _currentSchedule.signalError; | |
| 238 return currentSchedule.run(() { | 241 return currentSchedule.run(() { |
| 239 if (_setUpFn != null) _setUpFn(); | 242 if (_setUpFn != null) _setUpFn(); |
| 240 body(); | 243 body(); |
| 241 }).catchError((error, stackTrace) { | 244 }).catchError((error, stackTrace) { |
| 242 if (error is ScheduleError) { | 245 if (error is ScheduleError) { |
| 243 assert(error.schedule.errors.contains(error)); | 246 assert(error.schedule.errors.contains(error)); |
| 244 assert(error.schedule == currentSchedule); | 247 assert(error.schedule == currentSchedule); |
| 245 unittest.registerException(error.schedule.errorString()); | 248 unittest.registerException(error.schedule.errorString()); |
| 246 } else { | 249 } else { |
| 247 unittest.registerException(error, new Chain.forTrace(stackTrace)); | 250 unittest.registerException(error, new Chain.forTrace(stackTrace)); |
| 248 } | 251 } |
| 249 }).then(completer.complete); | 252 }).then(completer.complete); |
| 250 }, onError: (error, chain) => currentSchedule.signalError(error, chain)); | 253 }, onError: errorHandler); |
|
nweiz
2014/04/09 01:20:41
I figured out the issue: this is being passed in w
| |
| 251 | 254 |
| 252 return completer.future; | 255 return completer.future; |
| 253 }); | 256 }); |
| 254 } | 257 } |
| 255 | 258 |
| 256 /// Whether or not the tests currently being defined are in a group. This is | 259 /// Whether or not the tests currently being defined are in a group. This is |
| 257 /// only true when defining tests, not when executing them. | 260 /// only true when defining tests, not when executing them. |
| 258 bool _inGroup = false; | 261 bool _inGroup = false; |
| 259 | 262 |
| 260 /// Creates a new named group of tests. This has the same semantics as | 263 /// 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... | |
| 367 /// [description] provides an optional description of the future, which is | 370 /// [description] provides an optional description of the future, which is |
| 368 /// used when generating error messages. | 371 /// used when generating error messages. |
| 369 Future wrapFuture(Future future, [String description]) { | 372 Future wrapFuture(Future future, [String description]) { |
| 370 if (currentSchedule == null) { | 373 if (currentSchedule == null) { |
| 371 throw new StateError("Unexpected call to wrapFuture with no current " | 374 throw new StateError("Unexpected call to wrapFuture with no current " |
| 372 "schedule."); | 375 "schedule."); |
| 373 } | 376 } |
| 374 | 377 |
| 375 return currentSchedule.wrapFuture(future, description); | 378 return currentSchedule.wrapFuture(future, description); |
| 376 } | 379 } |
| OLD | NEW |