| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 part of matcher; | 5 part of matcher; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Matches a [Future] that completes successfully with a value. Note that this | 8 * Matches a [Future] that completes successfully with a value. Note that this |
| 9 * creates an asynchronous expectation. The call to `expect()` that includes | 9 * creates an asynchronous expectation. The call to `expect()` that includes |
| 10 * this will return immediately and execution will continue. Later, when the | 10 * this will return immediately and execution will continue. Later, when the |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 final String _id; | 35 final String _id; |
| 36 | 36 |
| 37 const _Completes(this._matcher, this._id); | 37 const _Completes(this._matcher, this._id); |
| 38 | 38 |
| 39 bool matches(item, MatchState matchState) { | 39 bool matches(item, MatchState matchState) { |
| 40 if (item is! Future) return false; | 40 if (item is! Future) return false; |
| 41 var done = wrapAsync((fn) => fn(), _id); | 41 var done = wrapAsync((fn) => fn(), _id); |
| 42 | 42 |
| 43 item.then((value) { | 43 item.then((value) { |
| 44 done(() { if (_matcher != null) expect(value, _matcher); }); | 44 done(() { if (_matcher != null) expect(value, _matcher); }); |
| 45 }, onError: (e) { | 45 }, onError: (error) { |
| 46 var id = _id == '' ? '' : '${_id} '; | 46 var id = _id == '' ? '' : '${_id} '; |
| 47 var reason = 'Expected future ${id}to complete successfully, ' | 47 var reason = 'Expected future ${id}to complete successfully, ' |
| 48 'but it failed with ${e.error}'; | 48 'but it failed with ${error}'; |
| 49 if (e.stackTrace != null) { | 49 var trace = getAttachedStackTrace(error); |
| 50 var stackTrace = e.stackTrace.toString(); | 50 if (trace != null) { |
| 51 var stackTrace = trace.toString(); |
| 51 stackTrace = ' ${stackTrace.replaceAll('\n', '\n ')}'; | 52 stackTrace = ' ${stackTrace.replaceAll('\n', '\n ')}'; |
| 52 reason = '$reason\nStack trace:\n$stackTrace'; | 53 reason = '$reason\nStack trace:\n$stackTrace'; |
| 53 } | 54 } |
| 54 done(() => fail(reason)); | 55 done(() => fail(reason)); |
| 55 }); | 56 }); |
| 56 | 57 |
| 57 return true; | 58 return true; |
| 58 } | 59 } |
| 59 | 60 |
| 60 Description describe(Description description) { | 61 Description describe(Description description) { |
| 61 if (_matcher == null) { | 62 if (_matcher == null) { |
| 62 description.add('completes successfully'); | 63 description.add('completes successfully'); |
| 63 } else { | 64 } else { |
| 64 description.add('completes to a value that ').addDescriptionOf(_matcher); | 65 description.add('completes to a value that ').addDescriptionOf(_matcher); |
| 65 } | 66 } |
| 66 return description; | 67 return description; |
| 67 } | 68 } |
| 68 } | 69 } |
| OLD | NEW |