| 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 | 5 |
| 6 /** | 6 /** |
| 7 * Returns a matcher that matches empty strings, maps or collections. | 7 * Returns a matcher that matches empty strings, maps or collections. |
| 8 */ | 8 */ |
| 9 final Matcher isEmpty = const _Empty(); | 9 final Matcher isEmpty = const _Empty(); |
| 10 | 10 |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 | 273 |
| 274 bool matches(item) { | 274 bool matches(item) { |
| 275 if (item is Future) { | 275 if (item is Future) { |
| 276 // Queue up an asynchronous expectation that validates when the future | 276 // Queue up an asynchronous expectation that validates when the future |
| 277 // completes. | 277 // completes. |
| 278 item.onComplete(expectAsync1((future) { | 278 item.onComplete(expectAsync1((future) { |
| 279 if (future.hasValue) { | 279 if (future.hasValue) { |
| 280 expect(false, reason: | 280 expect(false, reason: |
| 281 "Expected future to fail, but succeeded with '${future.value}'."); | 281 "Expected future to fail, but succeeded with '${future.value}'."); |
| 282 } else if (_matcher != null) { | 282 } else if (_matcher != null) { |
| 283 expect(future.exception, _matcher); | 283 var reason; |
| 284 if (future.stackTrace != null) { |
| 285 var stackTrace = future.stackTrace.toString(); |
| 286 stackTrace = " ${stackTrace.replaceAll("\n", "\n ")}"; |
| 287 reason = "Actual exception trace:\n$stackTrace"; |
| 288 } |
| 289 expect(future.exception, _matcher, reason: reason); |
| 284 } | 290 } |
| 285 })); | 291 })); |
| 286 | 292 |
| 287 // It hasn't failed yet. | 293 // It hasn't failed yet. |
| 288 return true; | 294 return true; |
| 289 } | 295 } |
| 290 | 296 |
| 291 try { | 297 try { |
| 292 item(); | 298 item(); |
| 293 return false; | 299 return false; |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 final _matcher; | 587 final _matcher; |
| 582 final String _description; | 588 final String _description; |
| 583 | 589 |
| 584 const _Predicate(this._matcher, this._description); | 590 const _Predicate(this._matcher, this._description); |
| 585 | 591 |
| 586 bool matches(item) => _matcher(item); | 592 bool matches(item) => _matcher(item); |
| 587 | 593 |
| 588 Description describe(Description description) => | 594 Description describe(Description description) => |
| 589 description.add(_description); | 595 description.add(_description); |
| 590 } | 596 } |
| OLD | NEW |