| 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 const Matcher isEmpty = const _Empty(); | 9 const Matcher isEmpty = const _Empty(); |
| 10 | 10 |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 | 273 |
| 274 const Throws([Matcher matcher]) : | 274 const Throws([Matcher matcher]) : |
| 275 this._matcher = matcher; | 275 this._matcher = matcher; |
| 276 | 276 |
| 277 bool matches(item, MatchState matchState) { | 277 bool matches(item, MatchState matchState) { |
| 278 if (item is Future) { | 278 if (item is Future) { |
| 279 // Queue up an asynchronous expectation that validates when the future | 279 // Queue up an asynchronous expectation that validates when the future |
| 280 // completes. | 280 // completes. |
| 281 item.onComplete(expectAsync1((future) { | 281 item.onComplete(expectAsync1((future) { |
| 282 if (future.hasValue) { | 282 if (future.hasValue) { |
| 283 expect(false, reason: | 283 expect(false, isTrue, |
| 284 "Expected future to fail, but succeeded with '${future.value}'."); | 284 "Expected future to fail, but succeeded with '${future.value}'."); |
| 285 } else if (_matcher != null) { | 285 } else if (_matcher != null) { |
| 286 var reason; | 286 var reason; |
| 287 if (future.stackTrace != null) { | 287 if (future.stackTrace != null) { |
| 288 var stackTrace = future.stackTrace.toString(); | 288 var stackTrace = future.stackTrace.toString(); |
| 289 stackTrace = " ${stackTrace.replaceAll("\n", "\n ")}"; | 289 stackTrace = " ${stackTrace.replaceAll("\n", "\n ")}"; |
| 290 reason = "Actual exception trace:\n$stackTrace"; | 290 reason = "Actual exception trace:\n$stackTrace"; |
| 291 } | 291 } |
| 292 expect(future.exception, _matcher, reason: reason); | 292 expect(future.exception, _matcher, reason); |
| 293 } | 293 } |
| 294 })); | 294 })); |
| 295 | 295 |
| 296 // It hasn't failed yet. | 296 // It hasn't failed yet. |
| 297 return true; | 297 return true; |
| 298 } | 298 } |
| 299 | 299 |
| 300 try { | 300 try { |
| 301 item(); | 301 item(); |
| 302 return false; | 302 return false; |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 final _matcher; | 618 final _matcher; |
| 619 final String _description; | 619 final String _description; |
| 620 | 620 |
| 621 const _Predicate(this._matcher, this._description); | 621 const _Predicate(this._matcher, this._description); |
| 622 | 622 |
| 623 bool matches(item, MatchState matchState) => _matcher(item); | 623 bool matches(item, MatchState matchState) => _matcher(item); |
| 624 | 624 |
| 625 Description describe(Description description) => | 625 Description describe(Description description) => |
| 626 description.add(_description); | 626 description.add(_description); |
| 627 } | 627 } |
| OLD | NEW |