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 library scheduled_future_matchers; | 5 library scheduled_future_matchers; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:stack_trace/stack_trace.dart'; | |
| 10 | |
| 9 import '../scheduled_test.dart'; | 11 import '../scheduled_test.dart'; |
| 10 | 12 |
| 11 /// Matches a [Future] that completes successfully with a value. Note that this | 13 /// Matches a [Future] that completes successfully with a value. Note that this |
| 12 /// creates an asynchronous expectation. The call to `expect()` that includes | 14 /// creates an asynchronous expectation. The call to `expect()` that includes |
| 13 /// this will return immediately and execution will continue. Later, when the | 15 /// this will return immediately and execution will continue. Later, when the |
| 14 /// future completes, the actual expectation will run. | 16 /// future completes, the actual expectation will run. |
| 15 /// | 17 /// |
| 16 /// To test that a Future completes with an exception, you can use [throws] and | 18 /// To test that a Future completes with an exception, you can use [throws] and |
| 17 /// [throwsA]. | 19 /// [throwsA]. |
| 18 /// | 20 /// |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 if (description == null) { | 55 if (description == null) { |
| 54 if (_matcher == null) { | 56 if (_matcher == null) { |
| 55 description = 'expect(..., completes)'; | 57 description = 'expect(..., completes)'; |
| 56 } else { | 58 } else { |
| 57 var matcherDescription = new StringDescription(); | 59 var matcherDescription = new StringDescription(); |
| 58 _matcher.describe(matcherDescription); | 60 _matcher.describe(matcherDescription); |
| 59 description = 'expect(..., completion($matcherDescription))'; | 61 description = 'expect(..., completion($matcherDescription))'; |
| 60 } | 62 } |
| 61 } | 63 } |
| 62 | 64 |
| 65 var outerTrace = new Trace.current(); | |
| 63 currentSchedule.wrapFuture(item.then((value) { | 66 currentSchedule.wrapFuture(item.then((value) { |
| 64 if (_matcher != null) expect(value, _matcher); | 67 if (_matcher == null) return; |
| 68 try { | |
|
Bob Nystrom
2013/04/01 17:30:49
Nit, but how about a blank line before the try?
nweiz
2013/04/01 20:46:03
Done.
| |
| 69 expect(value, _matcher); | |
| 70 } catch (e, stackTrace) { | |
| 71 throw new AsyncError(e, outerTrace); | |
| 72 } | |
| 65 }), description); | 73 }), description); |
| 66 | 74 |
| 67 return true; | 75 return true; |
| 68 } | 76 } |
| 69 | 77 |
| 70 Description describe(Description description) { | 78 Description describe(Description description) { |
| 71 if (_matcher == null) { | 79 if (_matcher == null) { |
| 72 description.add('completes successfully'); | 80 description.add('completes successfully'); |
| 73 } else { | 81 } else { |
| 74 description.add('completes to a value that ').addDescriptionOf(_matcher); | 82 description.add('completes to a value that ').addDescriptionOf(_matcher); |
| 75 } | 83 } |
| 76 return description; | 84 return description; |
| 77 } | 85 } |
| 78 } | 86 } |
| OLD | NEW |