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

Unified Diff: tests/corelib/future_test.dart

Issue 10542117: Allow optional callStack argument to Future.completeException(). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 6 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
Index: tests/corelib/future_test.dart
diff --git a/tests/corelib/future_test.dart b/tests/corelib/future_test.dart
index c96b2c60538bde9cdf273faef5e21dc7a45c546d..96f5aa66cf58b9246d665a588be7bd8ea6e7aee1 100644
--- a/tests/corelib/future_test.dart
+++ b/tests/corelib/future_test.dart
@@ -206,7 +206,7 @@ testException() {
final ex = new Exception();
future.then((_) {}); // exception is thrown if we plan to use the value
Expect.throws(
- () { completer.completeException(ex); },
+ () { completer.completeException(ex); },
check: (e) => e == ex);
}
@@ -262,7 +262,7 @@ testExceptionHandlerReturnsFalse() {
future.handleException((e) { return false; });
future.handleException((e) { reached = true; return false; }); // overshadowed
Expect.throws(
- () { completer.completeException(ex); },
+ () { completer.completeException(ex); },
check: (e) => e == ex);
Expect.isTrue(reached);
}
@@ -303,6 +303,54 @@ testExceptionHandlerAfterCompleteReturnsFalseThenThrows() {
Expect.equals(ex, ex2);
}
+// Tests for accessing the exception call stack.
+
+testCallStackThrowsIfNotComplete() {
+ var exception;
+ try {
+ new Completer().future.callStack;
+ } catch (var ex) {
+ exception = ex;
+ }
+
+ Expect.isTrue(exception is FutureNotCompleteException);
+}
+
+testCallStackIsNullIfCompletedSuccessfully() {
+ Expect.isNull(new Future.immediate('blah').callStack);
+}
+
+testCallStackReturnsCallstackPassedToCompleteException() {
+ final completer = new Completer();
+ final future = completer.future;
+
+ final callstack = 'fake call stack';
+ completer.completeException(new Exception(), callstack);
+ Expect.equals(callstack, future.callStack);
+}
+
+testCallStackIsCapturedIfTransformCallbackThrows() {
+ final completer = new Completer();
+ final transformed = completer.future.transform((_) {
+ throw 'whoops!';
+ });
+
+ final callstack = 'fake call stack';
+ completer.complete('blah');
+ Expect.isNotNull(transformed.callStack);
+}
+
+testCallStackIsCapturedIfChainCallbackThrows() {
+ final completer = new Completer();
+ final chained = completer.future.chain((_) {
+ throw 'whoops!';
+ });
+
+ final callstack = 'fake call stack';
+ completer.complete('blah');
+ Expect.isNotNull(chained.callStack);
+}
+
// Tests for mixed usage of [onComplete], [then], and [handleException]
testCompleteWithCompletionAndSuccessHandlers() {
@@ -470,6 +518,11 @@ main() {
testExceptionHandlerReturnsFalse2();
testExceptionHandlerAfterCompleteThenNotCalled();
testExceptionHandlerAfterCompleteReturnsFalseThenThrows();
+ testCallStackThrowsIfNotComplete();
+ testCallStackIsNullIfCompletedSuccessfully();
+ testCallStackReturnsCallstackPassedToCompleteException();
+ testCallStackIsCapturedIfTransformCallbackThrows();
+ testCallStackIsCapturedIfChainCallbackThrows();
testCompleteWithCompletionAndSuccessHandlers();
testExceptionWithCompletionAndSuccessHandlers();
testExceptionWithCompletionAndSuccessAndExceptionHandlers();
« corelib/src/future.dart ('K') | « corelib/src/implementation/future_implementation.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698