| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 test.frontend.throws_matcher; | 5 library test.frontend.throws_matcher; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:matcher/matcher.dart' hide fail, expect; | 9 import 'package:matcher/matcher.dart' hide fail, expect; |
| 10 | 10 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 Invoker.current.addOutstandingCallback(); | 53 Invoker.current.addOutstandingCallback(); |
| 54 // Queue up an asynchronous expectation that validates when the future | 54 // Queue up an asynchronous expectation that validates when the future |
| 55 // completes. | 55 // completes. |
| 56 item.then((value) { | 56 item.then((value) { |
| 57 fail("Expected future to fail, but succeeded with '$value'."); | 57 fail("Expected future to fail, but succeeded with '$value'."); |
| 58 }, onError: (error, trace) { | 58 }, onError: (error, trace) { |
| 59 if (_matcher == null) return; | 59 if (_matcher == null) return; |
| 60 | 60 |
| 61 var reason; | 61 var reason; |
| 62 if (trace != null) { | 62 if (trace != null) { |
| 63 var stackTrace = terseChain(trace).toString(); | 63 var stackTrace = terseChain(trace, |
| 64 stackTrace = " ${stackTrace.replaceAll("\n", "\n ")}"; | 64 verbose: Invoker.current.metadata.verboseTrace); |
| 65 stackTrace = " ${stackTrace.toString().replaceAll("\n", "\n ")}"; |
| 65 reason = "Actual exception trace:\n$stackTrace"; | 66 reason = "Actual exception trace:\n$stackTrace"; |
| 66 } | 67 } |
| 67 | 68 |
| 68 // Re-run [expect] to get the proper formatting. | 69 // Re-run [expect] to get the proper formatting. |
| 69 expect(() => throw error, this, reason: reason); | 70 expect(() => throw error, this, reason: reason); |
| 70 }).then((_) => Invoker.current.removeOutstandingCallback()); | 71 }).then((_) => Invoker.current.removeOutstandingCallback()); |
| 71 // It hasn't failed yet. | 72 // It hasn't failed yet. |
| 72 return true; | 73 return true; |
| 73 } | 74 } |
| 74 | 75 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 103 mismatchDescription | 104 mismatchDescription |
| 104 .add('threw ') | 105 .add('threw ') |
| 105 .addDescriptionOf(matchState['exception']); | 106 .addDescriptionOf(matchState['exception']); |
| 106 if (verbose) { | 107 if (verbose) { |
| 107 mismatchDescription.add(' at ').add(matchState['stack'].toString()); | 108 mismatchDescription.add(' at ').add(matchState['stack'].toString()); |
| 108 } | 109 } |
| 109 return mismatchDescription; | 110 return mismatchDescription; |
| 110 } | 111 } |
| 111 } | 112 } |
| 112 } | 113 } |
| OLD | NEW |