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

Side by Side Diff: tests/compiler/dart2js_extra/async_stacktrace_test.dart

Issue 945783002: Dart2js async-await. Propagate stacktraces from futures. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
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.
4
5 import "dart:async";
6
7 import "package:expect/expect.dart";
8 import "package:async_helper/async_helper.dart";
9
10 class Tracer {
11 final String expected;
12 final String name;
13 String _trace = "";
14
15 Tracer(this.expected, [this.name]);
16
17 void trace(msg) {
18 if (name != null) {
19 print("Tracing $name: $msg");
20 }
21 _trace += msg;
22 }
23
24 void done() {
25 Expect.equals(expected, _trace);
26 }
27 }
28
29 test1(Tracer tracer) {
30 foo() async
31 * /// asyncStar: ok
32 {
33 var savedStackTrace;
34 try {
35 try {
36 tracer.trace("a");
37 throw "Error";
38 } catch (e, st) {
39 tracer.trace("b");
40 savedStackTrace = st;
41 }
42 tracer.trace("c");
43 await new Future.error("Error 2", savedStackTrace);
44 tracer.trace("d");
45 } catch (e, st) {
46 tracer.trace("e");
47 Expect.equals(savedStackTrace.toString(), st.toString());
48 }
49 tracer.trace("f");
50 }
51 return foo()
52 .toList() /// asyncStar: continued
53 ;
54 }
55
56 test2(Tracer tracer) {
57 var savedStackTrace;
58 foo() async
59 * /// asyncStar: continued
60 {
61 try {
62 tracer.trace("a");
63 throw "Error";
64 } catch (e, st) {
65 tracer.trace("b");
66 savedStackTrace = st;
67 }
68 tracer.trace("c");
69 await new Future.error("Error 2", savedStackTrace);
70 tracer.trace("d");
71 }
72 return foo()
73 .toList() /// asyncStar: continued
74 .catchError((e, st) {
75 tracer.trace("e");
76 Expect.equals(savedStackTrace.toString(), st.toString());
77 });
78 }
79
80 test3(Tracer tracer) {
81 var savedStackTrace;
82 foo() async
83 * /// asyncStar: continued
84 {
85 try {
86 tracer.trace("a");
87 throw "Error";
88 } catch (e, st) {
89 tracer.trace("b");
90 savedStackTrace = st;
91 rethrow;
92 }
93 }
94 return foo()
95 .toList() /// asyncStar: continued
96 .catchError((e, st) {
97 tracer.trace("c");
98 Expect.equals(savedStackTrace.toString(), st.toString());
99 });
100 }
101
102 runTest(String expectedTrace, Future test(Tracer tracer)) async {
103 Tracer tracer = new Tracer(expectedTrace);
104 await test(tracer);
105 tracer.done();
106 }
107
108 runTests() async {
109 await runTest("abcef", test1);
110 await runTest("abce", test2);
111 await runTest("abc", test3);
112 }
113
114 main() {
115 asyncTest(runTests);
116 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/js_lib/js_helper.dart ('k') | tests/language/language_dart2js.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698