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 library test.frontend.future_matchers; | 5 library test.frontend.future_matchers; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:matcher/matcher.dart' hide throws, throwsA, expect, fail; | 9 import 'package:matcher/matcher.dart' hide throws, throwsA, expect, fail; |
10 | 10 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 const _Completes(this._matcher, this._id); | 44 const _Completes(this._matcher, this._id); |
45 | 45 |
46 bool matches(item, Map matchState) { | 46 bool matches(item, Map matchState) { |
47 if (item is! Future) return false; | 47 if (item is! Future) return false; |
48 Invoker.current.addOutstandingCallback(); | 48 Invoker.current.addOutstandingCallback(); |
49 | 49 |
50 item.then((value) { | 50 item.then((value) { |
51 if (_matcher != null) expect(value, _matcher); | 51 if (_matcher != null) expect(value, _matcher); |
52 Invoker.current.removeOutstandingCallback(); | 52 Invoker.current.removeOutstandingCallback(); |
53 }, onError: (error, trace) { | 53 }, onError: (error, trace) { |
54 if (error is TestFailure) { | 54 if (error is TestFailure) throw error; |
55 Invoker.current.handleError(error, trace); | |
56 return; | |
57 } | |
58 | 55 |
59 var id = _id == '' ? '' : '${_id} '; | 56 var id = _id == '' ? '' : '${_id} '; |
60 var reason = 'Expected future ${id}to complete successfully, ' | 57 var reason = 'Expected future ${id}to complete successfully, ' |
61 'but it failed with ${error}'; | 58 'but it failed with ${error}'; |
62 if (trace != null) { | 59 if (trace != null) { |
63 var stackTrace = terseChain(trace, | 60 var stackTrace = terseChain(trace, |
64 verbose: Invoker.current.metadata.verboseTrace); | 61 verbose: Invoker.current.metadata.verboseTrace); |
65 stackTrace = ' ${stackTrace.toString().replaceAll('\n', '\n ')}'; | 62 stackTrace = ' ${stackTrace.toString().replaceAll('\n', '\n ')}'; |
66 reason = '$reason\nStack trace:\n$stackTrace'; | 63 reason = '$reason\nStack trace:\n$stackTrace'; |
67 } | 64 } |
68 fail(reason); | 65 fail(reason); |
69 }); | 66 }); |
70 | 67 |
71 return true; | 68 return true; |
72 } | 69 } |
73 | 70 |
74 Description describe(Description description) { | 71 Description describe(Description description) { |
75 if (_matcher == null) { | 72 if (_matcher == null) { |
76 description.add('completes successfully'); | 73 description.add('completes successfully'); |
77 } else { | 74 } else { |
78 description.add('completes to a value that ').addDescriptionOf(_matcher); | 75 description.add('completes to a value that ').addDescriptionOf(_matcher); |
79 } | 76 } |
80 return description; | 77 return description; |
81 } | 78 } |
82 } | 79 } |
OLD | NEW |