| 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): Keep track of and display multiple errors so there's more |
| 6 // visibility into cascading errors. |
| 5 // TODO(nweiz): Add timeouts to scheduled tests. | 7 // TODO(nweiz): Add timeouts to scheduled tests. |
| 6 // TODO(nweiz): Add support for calling [schedule] while the schedule is already | 8 // TODO(nweiz): Add support for calling [schedule] while the schedule is already |
| 7 // running. | 9 // running. |
| 8 // TODO(nweiz): Port the non-Pub-specific scheduled test libraries from Pub. | 10 // TODO(nweiz): Port the non-Pub-specific scheduled test libraries from Pub. |
| 9 /// A package for writing readable tests of asynchronous behavior. | 11 /// A package for writing readable tests of asynchronous behavior. |
| 10 /// | 12 /// |
| 11 /// This package works by building up a queue of asynchronous tasks called a | 13 /// This package works by building up a queue of asynchronous tasks called a |
| 12 /// "schedule", then executing those tasks in order. This allows the tests to | 14 /// "schedule", then executing those tasks in order. This allows the tests to |
| 13 /// read like synchronous, linear code, despite executing asynchronously. | 15 /// read like synchronous, linear code, despite executing asynchronously. |
| 14 /// | 16 /// |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 testFn(description, () { | 187 testFn(description, () { |
| 186 var asyncDone = unittest.expectAsync0(() {}); | 188 var asyncDone = unittest.expectAsync0(() {}); |
| 187 return currentSchedule.run(() { | 189 return currentSchedule.run(() { |
| 188 if (_setUpFn != null) _setUpFn(); | 190 if (_setUpFn != null) _setUpFn(); |
| 189 body(); | 191 body(); |
| 190 }).then((_) { | 192 }).then((_) { |
| 191 // If we got here, the test completed successfully so tell unittest so. | 193 // If we got here, the test completed successfully so tell unittest so. |
| 192 asyncDone(); | 194 asyncDone(); |
| 193 }).catchError((e) { | 195 }).catchError((e) { |
| 194 if (e is ScheduleError) { | 196 if (e is ScheduleError) { |
| 195 assert(e.schedule.errors.contains(e)); | 197 unittest.registerException(new ExpectException(e.toString())); |
| 196 assert(e.schedule == currentSchedule); | |
| 197 unittest.registerException(e.schedule.errorString()); | |
| 198 } else if (e is AsyncError) { | 198 } else if (e is AsyncError) { |
| 199 unittest.registerException(e.error, e.stackTrace); | 199 unittest.registerException(e.error, e.stackTrace); |
| 200 } else { | 200 } else { |
| 201 unittest.registerException(e); | 201 unittest.registerException(e); |
| 202 } | 202 } |
| 203 }); | 203 }); |
| 204 }); | 204 }); |
| 205 } | 205 } |
| 206 | 206 |
| 207 /// Whether or not the tests currently being defined are in a group. This is | 207 /// Whether or not the tests currently being defined are in a group. This is |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 unittest.ensureInitialized(); | 283 unittest.ensureInitialized(); |
| 284 unittest.wrapAsync = (f) { | 284 unittest.wrapAsync = (f) { |
| 285 if (currentSchedule == null) { | 285 if (currentSchedule == null) { |
| 286 throw new StateError("Unexpected call to wrapAsync with no current " | 286 throw new StateError("Unexpected call to wrapAsync with no current " |
| 287 "schedule."); | 287 "schedule."); |
| 288 } | 288 } |
| 289 | 289 |
| 290 return currentSchedule.wrapAsync(f); | 290 return currentSchedule.wrapAsync(f); |
| 291 }; | 291 }; |
| 292 } | 292 } |
| OLD | NEW |