Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Unified Diff: lib/src/throws_matcher.dart

Issue 934413002: Replace the existing unittest APIs with the new runner infrastructure. (Closed) Base URL: git@github.com:dart-lang/unittest@master
Patch Set: Code review changes Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/test_environment.dart ('k') | lib/src/utils.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/throws_matcher.dart
diff --git a/lib/src/throws_matcher.dart b/lib/src/throws_matcher.dart
index 9790d22a0f760371ef0412103d9718a002f7d730..6807e6d248379ded62e7c6cc6fbef9a04db93ad2 100644
--- a/lib/src/throws_matcher.dart
+++ b/lib/src/throws_matcher.dart
@@ -8,7 +8,9 @@ import 'dart:async';
import 'package:matcher/matcher.dart' hide fail, expect;
-import '../unittest.dart';
+import 'expect.dart';
+import 'invoker.dart';
+import 'utils.dart';
/// This can be used to match two kinds of objects:
///
@@ -48,26 +50,24 @@ class Throws extends Matcher {
bool matches(item, Map matchState) {
if (item is! Function && item is! Future) return false;
if (item is Future) {
- var done = expectAsync((fn) => fn());
-
+ Invoker.current.addOutstandingCallback();
// Queue up an asynchronous expectation that validates when the future
// completes.
item.then((value) {
- done(() {
- fail("Expected future to fail, but succeeded with '$value'.");
- });
+ fail("Expected future to fail, but succeeded with '$value'.");
}, onError: (error, trace) {
- done(() {
- if (_matcher == null) return;
- var reason;
- if (trace != null) {
- var stackTrace = trace.toString();
- stackTrace = " ${stackTrace.replaceAll("\n", "\n ")}";
- reason = "Actual exception trace:\n$stackTrace";
- }
- expect(error, _matcher, reason: reason);
- });
- });
+ if (_matcher == null) return;
+
+ var reason;
+ if (trace != null) {
+ var stackTrace = terseChain(trace).toString();
+ stackTrace = " ${stackTrace.replaceAll("\n", "\n ")}";
+ reason = "Actual exception trace:\n$stackTrace";
+ }
+
+ // Re-run [expect] to get the proper formatting.
+ expect(() => throw error, this, reason: reason);
+ }).then((_) => Invoker.current.removeOutstandingCallback());
// It hasn't failed yet.
return true;
}
« no previous file with comments | « lib/src/test_environment.dart ('k') | lib/src/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698