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

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

Issue 2345083003: dart2js: run dartfmt on tests (Closed)
Patch Set: Created 4 years, 3 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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 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 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 import "dart:async"; 5 import "dart:async";
6 6
7 import "package:expect/expect.dart"; 7 import "package:expect/expect.dart";
8 import "package:async_helper/async_helper.dart"; 8 import "package:async_helper/async_helper.dart";
9 9
10 class Tracer { 10 class Tracer {
11 final String expected; 11 final String expected;
12 final String name; 12 final String name;
13 String _trace = ""; 13 String _trace = "";
14 14
15 Tracer(this.expected, [this.name]); 15 Tracer(this.expected, [this.name]);
16 16
17 void trace(msg) { 17 void trace(msg) {
18 if (name != null) { 18 if (name != null) {
19 print("Tracing $name: $msg"); 19 print("Tracing $name: $msg");
20 } 20 }
21 _trace += msg; 21 _trace += msg;
22 } 22 }
23 23
24 void done() { 24 void done() {
25 Expect.equals(expected, _trace); 25 Expect.equals(expected, _trace);
26 } 26 }
27 } 27 }
28 28
29 test1(Tracer tracer) { 29 test1(Tracer tracer) {
30 foo() async 30 foo() async*
31 * /// asyncStar: ok 31
32 { 32 /// asyncStar: ok
33 {
33 var savedStackTrace; 34 var savedStackTrace;
34 try { 35 try {
35 try { 36 try {
36 tracer.trace("a"); 37 tracer.trace("a");
37 throw "Error"; 38 throw "Error";
38 } catch (e, st) { 39 } catch (e, st) {
39 tracer.trace("b"); 40 tracer.trace("b");
40 savedStackTrace = st; 41 savedStackTrace = st;
41 } 42 }
42 tracer.trace("c"); 43 tracer.trace("c");
43 await new Future.error("Error 2", savedStackTrace); 44 await new Future.error("Error 2", savedStackTrace);
44 tracer.trace("d"); 45 tracer.trace("d");
45 } catch (e, st) { 46 } catch (e, st) {
46 tracer.trace("e"); 47 tracer.trace("e");
47 Expect.equals(savedStackTrace.toString(), st.toString()); 48 Expect.equals(savedStackTrace.toString(), st.toString());
48 } 49 }
49 tracer.trace("f"); 50 tracer.trace("f");
50 } 51 }
51 return foo() 52 return foo().toList()
52 .toList() /// asyncStar: continued 53
53 ; 54 /// asyncStar: continued
55 ;
54 } 56 }
55 57
56 test2(Tracer tracer) { 58 test2(Tracer tracer) {
57 var savedStackTrace; 59 var savedStackTrace;
58 foo() async 60 foo() async*
59 * /// asyncStar: continued 61
60 { 62 /// asyncStar: continued
63 {
61 try { 64 try {
62 tracer.trace("a"); 65 tracer.trace("a");
63 throw "Error"; 66 throw "Error";
64 } catch (e, st) { 67 } catch (e, st) {
65 tracer.trace("b"); 68 tracer.trace("b");
66 savedStackTrace = st; 69 savedStackTrace = st;
67 } 70 }
68 tracer.trace("c"); 71 tracer.trace("c");
69 await new Future.error("Error 2", savedStackTrace); 72 await new Future.error("Error 2", savedStackTrace);
70 tracer.trace("d"); 73 tracer.trace("d");
71 } 74 }
72 return foo() 75 return foo().toList()
73 .toList() /// asyncStar: continued 76
77 /// asyncStar: continued
74 .catchError((e, st) { 78 .catchError((e, st) {
75 tracer.trace("e"); 79 tracer.trace("e");
76 Expect.equals(savedStackTrace.toString(), st.toString()); 80 Expect.equals(savedStackTrace.toString(), st.toString());
77 }); 81 });
78 } 82 }
79 83
80 test3(Tracer tracer) { 84 test3(Tracer tracer) {
81 var savedStackTrace; 85 var savedStackTrace;
82 foo() async 86 foo() async*
83 * /// asyncStar: continued 87
84 { 88 /// asyncStar: continued
89 {
85 try { 90 try {
86 tracer.trace("a"); 91 tracer.trace("a");
87 throw "Error"; 92 throw "Error";
88 } catch (e, st) { 93 } catch (e, st) {
89 tracer.trace("b"); 94 tracer.trace("b");
90 savedStackTrace = st; 95 savedStackTrace = st;
91 rethrow; 96 rethrow;
92 } 97 }
93 } 98 }
94 return foo() 99 return foo().toList()
95 .toList() /// asyncStar: continued 100
101 /// asyncStar: continued
96 .catchError((e, st) { 102 .catchError((e, st) {
97 tracer.trace("c"); 103 tracer.trace("c");
98 Expect.equals(savedStackTrace.toString(), st.toString()); 104 Expect.equals(savedStackTrace.toString(), st.toString());
99 }); 105 });
100 } 106 }
101 107
102 runTest(String expectedTrace, Future test(Tracer tracer)) async { 108 runTest(String expectedTrace, Future test(Tracer tracer)) async {
103 Tracer tracer = new Tracer(expectedTrace); 109 Tracer tracer = new Tracer(expectedTrace);
104 await test(tracer); 110 await test(tracer);
105 tracer.done(); 111 tracer.done();
106 } 112 }
107 113
108 runTests() async { 114 runTests() async {
109 await runTest("abcef", test1); 115 await runTest("abcef", test1);
110 await runTest("abce", test2); 116 await runTest("abce", test2);
111 await runTest("abc", test3); 117 await runTest("abc", test3);
112 } 118 }
113 119
114 main() { 120 main() {
115 asyncTest(runTests); 121 asyncTest(runTests);
116 } 122 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698