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 Schedule localSchedule; | |
|
nweiz
2014/04/07 18:02:21
Don't type-annotate local variables.
kevmoo
2014/04/08 01:29:33
Done.
| |
| 237 | |
| 236 Chain.capture(() { | 238 Chain.capture(() { |
| 237 _currentSchedule = new Schedule(); | 239 localSchedule = _currentSchedule = new Schedule(); |
|
nweiz
2014/04/07 18:02:21
We generally avoid multiple assignments on the sam
kevmoo
2014/04/08 01:29:33
Done.
| |
| 238 return currentSchedule.run(() { | 240 return currentSchedule.run(() { |
| 239 if (_setUpFn != null) _setUpFn(); | 241 if (_setUpFn != null) _setUpFn(); |
| 240 body(); | 242 body(); |
| 241 }).catchError((error, stackTrace) { | 243 }).catchError((error, stackTrace) { |
| 242 if (error is ScheduleError) { | 244 if (error is ScheduleError) { |
| 243 assert(error.schedule.errors.contains(error)); | 245 assert(error.schedule.errors.contains(error)); |
| 244 assert(error.schedule == currentSchedule); | 246 assert(error.schedule == currentSchedule); |
| 245 unittest.registerException(error.schedule.errorString()); | 247 unittest.registerException(error.schedule.errorString()); |
| 246 } else { | 248 } else { |
| 247 unittest.registerException(error, new Chain.forTrace(stackTrace)); | 249 unittest.registerException(error, new Chain.forTrace(stackTrace)); |
| 248 } | 250 } |
| 249 }).then(completer.complete); | 251 }).then(completer.complete); |
| 250 }, onError: (error, chain) => currentSchedule.signalError(error, chain)); | 252 }, onError: (error, chain) => localSchedule.signalError(error, chain)); |
| 251 | 253 |
| 252 return completer.future; | 254 return completer.future; |
| 253 }); | 255 }); |
| 254 } | 256 } |
| 255 | 257 |
| 256 /// Whether or not the tests currently being defined are in a group. This is | 258 /// Whether or not the tests currently being defined are in a group. This is |
| 257 /// only true when defining tests, not when executing them. | 259 /// only true when defining tests, not when executing them. |
| 258 bool _inGroup = false; | 260 bool _inGroup = false; |
| 259 | 261 |
| 260 /// Creates a new named group of tests. This has the same semantics as | 262 /// 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 | 369 /// [description] provides an optional description of the future, which is |
| 368 /// used when generating error messages. | 370 /// used when generating error messages. |
| 369 Future wrapFuture(Future future, [String description]) { | 371 Future wrapFuture(Future future, [String description]) { |
| 370 if (currentSchedule == null) { | 372 if (currentSchedule == null) { |
| 371 throw new StateError("Unexpected call to wrapFuture with no current " | 373 throw new StateError("Unexpected call to wrapFuture with no current " |
| 372 "schedule."); | 374 "schedule."); |
| 373 } | 375 } |
| 374 | 376 |
| 375 return currentSchedule.wrapFuture(future, description); | 377 return currentSchedule.wrapFuture(future, description); |
| 376 } | 378 } |
| OLD | NEW |