OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 trace_test; | |
6 | |
7 import 'package:path/path.dart' as path; | 5 import 'package:path/path.dart' as path; |
8 import 'package:stack_trace/stack_trace.dart'; | 6 import 'package:stack_trace/stack_trace.dart'; |
9 import 'package:test/test.dart'; | 7 import 'package:test/test.dart'; |
10 | 8 |
11 String getStackTraceString() { | |
12 try { | |
13 throw ''; | |
14 } catch (_, stackTrace) { | |
15 return stackTrace.toString(); | |
16 } | |
17 } | |
18 | |
19 StackTrace getStackTraceObject() { | |
20 try { | |
21 throw ''; | |
22 } catch (_, stackTrace) { | |
23 return stackTrace; | |
24 } | |
25 } | |
26 | |
27 Trace getCurrentTrace([int level]) => new Trace.current(level); | 9 Trace getCurrentTrace([int level]) => new Trace.current(level); |
28 | 10 |
29 Trace nestedGetCurrentTrace(int level) => getCurrentTrace(level); | 11 Trace nestedGetCurrentTrace(int level) => getCurrentTrace(level); |
30 | 12 |
31 void main() { | 13 void main() { |
32 // This just shouldn't crash. | 14 // This just shouldn't crash. |
33 test('a native stack trace is parseable', () => new Trace.current()); | 15 test('a native stack trace is parseable', () => new Trace.current()); |
34 | 16 |
35 group('.parse', () { | 17 group('.parse', () { |
36 test('.parse parses a VM stack trace correctly', () { | 18 test('.parse parses a VM stack trace correctly', () { |
37 var trace = new Trace.parse( | 19 var trace = new Trace.parse( |
38 '#0 Foo._bar (file:///home/nweiz/code/stuff.dart:42:21)\n' | 20 '#0 Foo._bar (file:///home/nweiz/code/stuff.dart:42:21)\n' |
39 '#1 zip.<anonymous closure>.zap (dart:async/future.dart:0:2)\n' | 21 '#1 zip.<anonymous closure>.zap (dart:async/future.dart:0:2)\n' |
40 '#2 zip.<anonymous closure>.zap (http://pub.dartlang.org/thing.' | 22 '#2 zip.<anonymous closure>.zap (http://pub.dartlang.org/thing.' |
41 'dart:1:100)'); | 23 'dart:1:100)'); |
42 | 24 |
43 expect(trace.frames[0].uri, | 25 expect(trace.frames[0].uri, |
44 equals(Uri.parse("file:///home/nweiz/code/stuff.dart"))); | 26 equals(Uri.parse("file:///home/nweiz/code/stuff.dart"))); |
45 expect(trace.frames[1].uri, equals(Uri.parse("dart:async/future.dart"))); | 27 expect(trace.frames[1].uri, equals(Uri.parse("dart:async/future.dart"))); |
46 expect(trace.frames[2].uri, | 28 expect(trace.frames[2].uri, |
47 equals(Uri.parse("http://pub.dartlang.org/thing.dart"))); | 29 equals(Uri.parse("http://pub.dartlang.org/thing.dart"))); |
48 }); | 30 }); |
49 | 31 |
50 test('parses a V8 stack trace correctly', () { | 32 test('parses a V8 stack trace correctly', () { |
51 var trace = new Trace.parse( | 33 var trace = new Trace.parse('Error\n' |
52 'Error\n' | |
53 ' at Foo._bar (http://pub.dartlang.org/stuff.js:42:21)\n' | 34 ' at Foo._bar (http://pub.dartlang.org/stuff.js:42:21)\n' |
54 ' at http://pub.dartlang.org/stuff.js:0:2\n' | 35 ' at http://pub.dartlang.org/stuff.js:0:2\n' |
55 ' at zip.<anonymous>.zap ' | 36 ' at zip.<anonymous>.zap ' |
56 '(http://pub.dartlang.org/thing.js:1:100)'); | 37 '(http://pub.dartlang.org/thing.js:1:100)'); |
57 | 38 |
58 expect(trace.frames[0].uri, | 39 expect(trace.frames[0].uri, |
59 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); | 40 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); |
60 expect(trace.frames[1].uri, | 41 expect(trace.frames[1].uri, |
61 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); | 42 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); |
62 expect(trace.frames[2].uri, | 43 expect(trace.frames[2].uri, |
63 equals(Uri.parse("http://pub.dartlang.org/thing.js"))); | 44 equals(Uri.parse("http://pub.dartlang.org/thing.js"))); |
64 | 45 |
65 trace = new Trace.parse( | 46 trace = new Trace.parse("Exception: foo\n" |
66 "Exception: foo\n" | |
67 ' at Foo._bar (http://pub.dartlang.org/stuff.js:42:21)\n' | 47 ' at Foo._bar (http://pub.dartlang.org/stuff.js:42:21)\n' |
68 ' at http://pub.dartlang.org/stuff.js:0:2\n' | 48 ' at http://pub.dartlang.org/stuff.js:0:2\n' |
69 ' at zip.<anonymous>.zap ' | 49 ' at zip.<anonymous>.zap ' |
70 '(http://pub.dartlang.org/thing.js:1:100)'); | 50 '(http://pub.dartlang.org/thing.js:1:100)'); |
71 | 51 |
72 expect(trace.frames[0].uri, | 52 expect(trace.frames[0].uri, |
73 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); | 53 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); |
74 expect(trace.frames[1].uri, | 54 expect(trace.frames[1].uri, |
75 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); | 55 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); |
76 expect(trace.frames[2].uri, | 56 expect(trace.frames[2].uri, |
77 equals(Uri.parse("http://pub.dartlang.org/thing.js"))); | 57 equals(Uri.parse("http://pub.dartlang.org/thing.js"))); |
78 | 58 |
79 trace = new Trace.parse( | 59 trace = new Trace.parse('Exception: foo\n' |
80 'Exception: foo\n' | |
81 ' bar\n' | 60 ' bar\n' |
82 ' at Foo._bar (http://pub.dartlang.org/stuff.js:42:21)\n' | 61 ' at Foo._bar (http://pub.dartlang.org/stuff.js:42:21)\n' |
83 ' at http://pub.dartlang.org/stuff.js:0:2\n' | 62 ' at http://pub.dartlang.org/stuff.js:0:2\n' |
84 ' at zip.<anonymous>.zap ' | 63 ' at zip.<anonymous>.zap ' |
85 '(http://pub.dartlang.org/thing.js:1:100)'); | 64 '(http://pub.dartlang.org/thing.js:1:100)'); |
86 | 65 |
87 expect(trace.frames[0].uri, | 66 expect(trace.frames[0].uri, |
88 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); | 67 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); |
89 expect(trace.frames[1].uri, | 68 expect(trace.frames[1].uri, |
90 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); | 69 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); |
91 expect(trace.frames[2].uri, | 70 expect(trace.frames[2].uri, |
92 equals(Uri.parse("http://pub.dartlang.org/thing.js"))); | 71 equals(Uri.parse("http://pub.dartlang.org/thing.js"))); |
| 72 |
| 73 trace = new Trace.parse('Exception: foo\n' |
| 74 ' bar\n' |
| 75 ' at Foo._bar (http://pub.dartlang.org/stuff.js:42:21)\n' |
| 76 ' at http://pub.dartlang.org/stuff.js:0:2\n' |
| 77 ' at (anonymous function).zip.zap ' |
| 78 '(http://pub.dartlang.org/thing.js:1:100)'); |
| 79 |
| 80 expect(trace.frames[0].uri, |
| 81 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); |
| 82 expect(trace.frames[1].uri, |
| 83 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); |
| 84 expect(trace.frames[1].member, equals("<fn>")); |
| 85 expect(trace.frames[2].uri, |
| 86 equals(Uri.parse("http://pub.dartlang.org/thing.js"))); |
| 87 expect(trace.frames[2].member, equals("<fn>.zip.zap")); |
93 }); | 88 }); |
94 | 89 |
95 // JavaScriptCore traces are just like V8, except that it doesn't have a | 90 // JavaScriptCore traces are just like V8, except that it doesn't have a |
96 // header and it starts with a tab rather than spaces. | 91 // header and it starts with a tab rather than spaces. |
97 test('parses a JavaScriptCore stack trace correctly', () { | 92 test('parses a JavaScriptCore stack trace correctly', () { |
98 var trace = new Trace.parse( | 93 var trace = new Trace.parse( |
99 '\tat Foo._bar (http://pub.dartlang.org/stuff.js:42:21)\n' | 94 '\tat Foo._bar (http://pub.dartlang.org/stuff.js:42:21)\n' |
100 '\tat http://pub.dartlang.org/stuff.js:0:2\n' | 95 '\tat http://pub.dartlang.org/stuff.js:0:2\n' |
101 '\tat zip.<anonymous>.zap ' | 96 '\tat zip.<anonymous>.zap ' |
102 '(http://pub.dartlang.org/thing.js:1:100)'); | 97 '(http://pub.dartlang.org/thing.js:1:100)'); |
103 | 98 |
104 expect(trace.frames[0].uri, | 99 expect(trace.frames[0].uri, |
105 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); | 100 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); |
106 expect(trace.frames[1].uri, | 101 expect(trace.frames[1].uri, |
107 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); | 102 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); |
108 expect(trace.frames[2].uri, | 103 expect(trace.frames[2].uri, |
109 equals(Uri.parse("http://pub.dartlang.org/thing.js"))); | 104 equals(Uri.parse("http://pub.dartlang.org/thing.js"))); |
110 | 105 |
111 trace = new Trace.parse( | 106 trace = new Trace.parse( |
112 '\tat Foo._bar (http://pub.dartlang.org/stuff.js:42:21)\n' | 107 '\tat Foo._bar (http://pub.dartlang.org/stuff.js:42:21)\n' |
113 '\tat \n' | 108 '\tat \n' |
114 '\tat zip.<anonymous>.zap ' | 109 '\tat zip.<anonymous>.zap ' |
115 '(http://pub.dartlang.org/thing.js:1:100)'); | 110 '(http://pub.dartlang.org/thing.js:1:100)'); |
116 | 111 |
117 expect(trace.frames[0].uri, | 112 expect(trace.frames[0].uri, |
118 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); | 113 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); |
119 expect(trace.frames[1].uri, | 114 expect(trace.frames[1].uri, |
120 equals(Uri.parse("http://pub.dartlang.org/thing.js"))); | 115 equals(Uri.parse("http://pub.dartlang.org/thing.js"))); |
121 }); | 116 }); |
122 | 117 |
123 test('parses a Firefox/Safari stack trace correctly', () { | 118 test('parses a Firefox/Safari stack trace correctly', () { |
124 var trace = new Trace.parse( | 119 var trace = |
125 'Foo._bar@http://pub.dartlang.org/stuff.js:42\n' | 120 new Trace.parse('Foo._bar@http://pub.dartlang.org/stuff.js:42\n' |
126 'zip/<@http://pub.dartlang.org/stuff.js:0\n' | 121 'zip/<@http://pub.dartlang.org/stuff.js:0\n' |
127 'zip.zap(12, "@)()/<")@http://pub.dartlang.org/thing.js:1'); | 122 'zip.zap(12, "@)()/<")@http://pub.dartlang.org/thing.js:1'); |
128 | 123 |
129 expect(trace.frames[0].uri, | 124 expect(trace.frames[0].uri, |
130 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); | 125 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); |
131 expect(trace.frames[1].uri, | 126 expect(trace.frames[1].uri, |
132 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); | 127 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); |
133 expect(trace.frames[2].uri, | 128 expect(trace.frames[2].uri, |
134 equals(Uri.parse("http://pub.dartlang.org/thing.js"))); | 129 equals(Uri.parse("http://pub.dartlang.org/thing.js"))); |
135 | 130 |
136 trace = new Trace.parse( | 131 trace = new Trace.parse('zip/<@http://pub.dartlang.org/stuff.js:0\n' |
137 'zip/<@http://pub.dartlang.org/stuff.js:0\n' | |
138 'Foo._bar@http://pub.dartlang.org/stuff.js:42\n' | 132 'Foo._bar@http://pub.dartlang.org/stuff.js:42\n' |
139 'zip.zap(12, "@)()/<")@http://pub.dartlang.org/thing.js:1'); | 133 'zip.zap(12, "@)()/<")@http://pub.dartlang.org/thing.js:1'); |
140 | 134 |
141 expect(trace.frames[0].uri, | 135 expect(trace.frames[0].uri, |
142 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); | 136 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); |
143 expect(trace.frames[1].uri, | 137 expect(trace.frames[1].uri, |
144 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); | 138 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); |
145 expect(trace.frames[2].uri, | 139 expect(trace.frames[2].uri, |
146 equals(Uri.parse("http://pub.dartlang.org/thing.js"))); | 140 equals(Uri.parse("http://pub.dartlang.org/thing.js"))); |
147 | 141 |
148 trace = new Trace.parse( | 142 trace = new Trace.parse( |
149 'zip.zap(12, "@)()/<")@http://pub.dartlang.org/thing.js:1\n' | 143 'zip.zap(12, "@)()/<")@http://pub.dartlang.org/thing.js:1\n' |
150 'zip/<@http://pub.dartlang.org/stuff.js:0\n' | 144 'zip/<@http://pub.dartlang.org/stuff.js:0\n' |
151 'Foo._bar@http://pub.dartlang.org/stuff.js:42'); | 145 'Foo._bar@http://pub.dartlang.org/stuff.js:42'); |
152 | 146 |
153 expect(trace.frames[0].uri, | 147 expect(trace.frames[0].uri, |
154 equals(Uri.parse("http://pub.dartlang.org/thing.js"))); | 148 equals(Uri.parse("http://pub.dartlang.org/thing.js"))); |
155 expect(trace.frames[1].uri, | 149 expect(trace.frames[1].uri, |
156 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); | 150 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); |
157 expect(trace.frames[2].uri, | 151 expect(trace.frames[2].uri, |
158 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); | 152 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); |
159 }); | 153 }); |
160 | 154 |
161 test('parses a Firefox/Safari stack trace containing native code correctly', | 155 test('parses a Firefox/Safari stack trace containing native code correctly', |
162 () { | 156 () { |
163 var trace = new Trace.parse( | 157 var trace = |
164 'Foo._bar@http://pub.dartlang.org/stuff.js:42\n' | 158 new Trace.parse('Foo._bar@http://pub.dartlang.org/stuff.js:42\n' |
165 'zip/<@http://pub.dartlang.org/stuff.js:0\n' | 159 'zip/<@http://pub.dartlang.org/stuff.js:0\n' |
166 'zip.zap(12, "@)()/<")@http://pub.dartlang.org/thing.js:1\n' | 160 'zip.zap(12, "@)()/<")@http://pub.dartlang.org/thing.js:1\n' |
167 '[native code]'); | 161 '[native code]'); |
168 | 162 |
169 expect(trace.frames[0].uri, | 163 expect(trace.frames[0].uri, |
170 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); | 164 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); |
171 expect(trace.frames[1].uri, | 165 expect(trace.frames[1].uri, |
172 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); | 166 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); |
173 expect(trace.frames[2].uri, | 167 expect(trace.frames[2].uri, |
174 equals(Uri.parse("http://pub.dartlang.org/thing.js"))); | 168 equals(Uri.parse("http://pub.dartlang.org/thing.js"))); |
175 expect(trace.frames.length, equals(3)); | 169 expect(trace.frames.length, equals(3)); |
176 }); | 170 }); |
177 | 171 |
178 test('parses a Firefox/Safari stack trace without a method name correctly', | 172 test('parses a Firefox/Safari stack trace without a method name correctly', |
179 () { | 173 () { |
180 var trace = new Trace.parse( | 174 var trace = new Trace.parse('http://pub.dartlang.org/stuff.js:42\n' |
181 'http://pub.dartlang.org/stuff.js:42\n' | |
182 'zip/<@http://pub.dartlang.org/stuff.js:0\n' | 175 'zip/<@http://pub.dartlang.org/stuff.js:0\n' |
183 'zip.zap(12, "@)()/<")@http://pub.dartlang.org/thing.js:1'); | 176 'zip.zap(12, "@)()/<")@http://pub.dartlang.org/thing.js:1'); |
184 | 177 |
185 expect(trace.frames[0].uri, | 178 expect(trace.frames[0].uri, |
186 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); | 179 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); |
187 expect(trace.frames[0].member, equals('<fn>')); | 180 expect(trace.frames[0].member, equals('<fn>')); |
188 expect(trace.frames[1].uri, | 181 expect(trace.frames[1].uri, |
189 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); | 182 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); |
190 expect(trace.frames[2].uri, | 183 expect(trace.frames[2].uri, |
191 equals(Uri.parse("http://pub.dartlang.org/thing.js"))); | 184 equals(Uri.parse("http://pub.dartlang.org/thing.js"))); |
192 }); | 185 }); |
193 | 186 |
194 test('parses a Firefox/Safari stack trace with an empty line correctly', | 187 test('parses a Firefox/Safari stack trace with an empty line correctly', |
195 () { | 188 () { |
196 var trace = new Trace.parse( | 189 var trace = |
197 'Foo._bar@http://pub.dartlang.org/stuff.js:42\n' | 190 new Trace.parse('Foo._bar@http://pub.dartlang.org/stuff.js:42\n' |
198 '\n' | 191 '\n' |
199 'zip/<@http://pub.dartlang.org/stuff.js:0\n' | 192 'zip/<@http://pub.dartlang.org/stuff.js:0\n' |
200 'zip.zap(12, "@)()/<")@http://pub.dartlang.org/thing.js:1'); | 193 'zip.zap(12, "@)()/<")@http://pub.dartlang.org/thing.js:1'); |
201 | 194 |
202 expect(trace.frames[0].uri, | 195 expect(trace.frames[0].uri, |
203 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); | 196 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); |
204 expect(trace.frames[1].uri, | 197 expect(trace.frames[1].uri, |
205 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); | 198 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); |
206 expect(trace.frames[2].uri, | 199 expect(trace.frames[2].uri, |
207 equals(Uri.parse("http://pub.dartlang.org/thing.js"))); | 200 equals(Uri.parse("http://pub.dartlang.org/thing.js"))); |
208 }); | 201 }); |
209 | 202 |
210 test('parses a Firefox/Safari stack trace with a column number correctly', | 203 test('parses a Firefox/Safari stack trace with a column number correctly', |
211 () { | 204 () { |
212 var trace = new Trace.parse( | 205 var trace = |
213 'Foo._bar@http://pub.dartlang.org/stuff.js:42:2\n' | 206 new Trace.parse('Foo._bar@http://pub.dartlang.org/stuff.js:42:2\n' |
214 'zip/<@http://pub.dartlang.org/stuff.js:0\n' | 207 'zip/<@http://pub.dartlang.org/stuff.js:0\n' |
215 'zip.zap(12, "@)()/<")@http://pub.dartlang.org/thing.js:1'); | 208 'zip.zap(12, "@)()/<")@http://pub.dartlang.org/thing.js:1'); |
216 | 209 |
217 expect(trace.frames[0].uri, | 210 expect(trace.frames[0].uri, |
218 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); | 211 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); |
219 expect(trace.frames[0].line, equals(42)); | 212 expect(trace.frames[0].line, equals(42)); |
220 expect(trace.frames[0].column, equals(2)); | 213 expect(trace.frames[0].column, equals(2)); |
221 expect(trace.frames[1].uri, | 214 expect(trace.frames[1].uri, |
222 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); | 215 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); |
223 expect(trace.frames[2].uri, | 216 expect(trace.frames[2].uri, |
224 equals(Uri.parse("http://pub.dartlang.org/thing.js"))); | 217 equals(Uri.parse("http://pub.dartlang.org/thing.js"))); |
225 }); | 218 }); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 }); | 273 }); |
281 | 274 |
282 test('.vmTrace returns a native-style trace', () { | 275 test('.vmTrace returns a native-style trace', () { |
283 var uri = path.toUri(path.absolute('foo')); | 276 var uri = path.toUri(path.absolute('foo')); |
284 var trace = new Trace([ | 277 var trace = new Trace([ |
285 new Frame(uri, 10, 20, 'Foo.<fn>'), | 278 new Frame(uri, 10, 20, 'Foo.<fn>'), |
286 new Frame(Uri.parse('http://dartlang.org/foo.dart'), null, null, 'bar'), | 279 new Frame(Uri.parse('http://dartlang.org/foo.dart'), null, null, 'bar'), |
287 new Frame(Uri.parse('dart:async'), 15, null, 'baz'), | 280 new Frame(Uri.parse('dart:async'), 15, null, 'baz'), |
288 ]); | 281 ]); |
289 | 282 |
290 expect(trace.vmTrace.toString(), equals( | 283 expect( |
291 '#1 Foo.<anonymous closure> ($uri:10:20)\n' | 284 trace.vmTrace.toString(), |
292 '#2 bar (http://dartlang.org/foo.dart:0:0)\n' | 285 equals('#1 Foo.<anonymous closure> ($uri:10:20)\n' |
293 '#3 baz (dart:async:15:0)\n')); | 286 '#2 bar (http://dartlang.org/foo.dart:0:0)\n' |
| 287 '#3 baz (dart:async:15:0)\n')); |
294 }); | 288 }); |
295 | 289 |
296 group("folding", () { | 290 group("folding", () { |
297 test('.terse folds core frames together bottom-up', () { | 291 group(".terse", () { |
298 var trace = new Trace.parse(''' | 292 test('folds core frames together bottom-up', () { |
| 293 var trace = new Trace.parse(''' |
299 #1 top (dart:async/future.dart:0:2) | 294 #1 top (dart:async/future.dart:0:2) |
300 #2 bottom (dart:core/uri.dart:1:100) | 295 #2 bottom (dart:core/uri.dart:1:100) |
301 #0 notCore (foo.dart:42:21) | 296 #0 notCore (foo.dart:42:21) |
302 #3 top (dart:io:5:10) | 297 #3 top (dart:io:5:10) |
303 #4 bottom (dart:async-patch/future.dart:9:11) | 298 #4 bottom (dart:async-patch/future.dart:9:11) |
304 #5 alsoNotCore (bar.dart:10:20) | 299 #5 alsoNotCore (bar.dart:10:20) |
305 '''); | 300 '''); |
306 | 301 |
307 expect(trace.terse.toString(), equals(''' | 302 expect(trace.terse.toString(), equals(''' |
308 dart:core bottom | 303 dart:core bottom |
309 foo.dart 42:21 notCore | 304 foo.dart 42:21 notCore |
310 dart:async bottom | 305 dart:async bottom |
311 bar.dart 10:20 alsoNotCore | 306 bar.dart 10:20 alsoNotCore |
312 ''')); | 307 ''')); |
313 }); | 308 }); |
314 | 309 |
315 test('.terse folds empty async frames', () { | 310 test('folds empty async frames', () { |
316 var trace = new Trace.parse(''' | 311 var trace = new Trace.parse(''' |
317 #0 top (dart:async/future.dart:0:2) | 312 #0 top (dart:async/future.dart:0:2) |
318 #1 empty.<<anonymous closure>_async_body> (bar.dart) | 313 #1 empty.<<anonymous closure>_async_body> (bar.dart) |
319 #2 bottom (dart:async-patch/future.dart:9:11) | 314 #2 bottom (dart:async-patch/future.dart:9:11) |
320 #3 notCore (foo.dart:42:21) | 315 #3 notCore (foo.dart:42:21) |
321 '''); | 316 '''); |
322 | 317 |
323 expect(trace.terse.toString(), equals(''' | 318 expect(trace.terse.toString(), equals(''' |
324 dart:async bottom | 319 dart:async bottom |
325 foo.dart 42:21 notCore | 320 foo.dart 42:21 notCore |
326 ''')); | 321 ''')); |
327 }); | 322 }); |
328 | 323 |
329 test('.terse removes the bottom-most async frame', () { | 324 test('removes the bottom-most async frame', () { |
330 var trace = new Trace.parse(''' | 325 var trace = new Trace.parse(''' |
331 #0 notCore (foo.dart:42:21) | 326 #0 notCore (foo.dart:42:21) |
332 #1 top (dart:async/future.dart:0:2) | 327 #1 top (dart:async/future.dart:0:2) |
333 #2 bottom (dart:core/uri.dart:1:100) | 328 #2 bottom (dart:core/uri.dart:1:100) |
334 #3 top (dart:io:5:10) | 329 #3 top (dart:io:5:10) |
335 #4 bottom (dart:async-patch/future.dart:9:11) | 330 #4 bottom (dart:async-patch/future.dart:9:11) |
336 '''); | 331 '''); |
337 | 332 |
338 expect(trace.terse.toString(), equals(''' | 333 expect(trace.terse.toString(), equals(''' |
339 foo.dart 42:21 notCore | 334 foo.dart 42:21 notCore |
340 ''')); | 335 ''')); |
341 }); | 336 }); |
342 | 337 |
343 test(".terse won't make a trace empty", () { | 338 test("won't make a trace empty", () { |
344 var trace = new Trace.parse(''' | 339 var trace = new Trace.parse(''' |
345 #1 top (dart:async/future.dart:0:2) | 340 #1 top (dart:async/future.dart:0:2) |
346 #2 bottom (dart:core/uri.dart:1:100) | 341 #2 bottom (dart:core/uri.dart:1:100) |
347 '''); | 342 '''); |
348 | 343 |
349 expect(trace.terse.toString(), equals(''' | 344 expect(trace.terse.toString(), equals(''' |
350 dart:core bottom | 345 dart:core bottom |
351 ''')); | 346 ''')); |
| 347 }); |
| 348 |
| 349 test("won't panic on an empty trace", () { |
| 350 expect(new Trace.parse("").terse.toString(), equals("")); |
| 351 }); |
352 }); | 352 }); |
353 | 353 |
354 test(".terse won't panic on an empty trace", () { | 354 group(".foldFrames", () { |
355 expect(new Trace.parse("").terse.toString(), equals("")); | 355 test('folds frames together bottom-up', () { |
356 }); | 356 var trace = new Trace.parse(''' |
357 | |
358 test('.foldFrames folds frames together bottom-up', () { | |
359 var trace = new Trace.parse(''' | |
360 #0 notFoo (foo.dart:42:21) | 357 #0 notFoo (foo.dart:42:21) |
361 #1 fooTop (bar.dart:0:2) | 358 #1 fooTop (bar.dart:0:2) |
362 #2 fooBottom (foo.dart:1:100) | 359 #2 fooBottom (foo.dart:1:100) |
363 #3 alsoNotFoo (bar.dart:10:20) | 360 #3 alsoNotFoo (bar.dart:10:20) |
364 #4 fooTop (dart:io/socket.dart:5:10) | 361 #4 fooTop (dart:io/socket.dart:5:10) |
365 #5 fooBottom (dart:async-patch/future.dart:9:11) | 362 #5 fooBottom (dart:async-patch/future.dart:9:11) |
366 '''); | 363 '''); |
367 | 364 |
368 var folded = trace.foldFrames((frame) => frame.member.startsWith('foo')); | 365 var folded = |
369 expect(folded.toString(), equals(''' | 366 trace.foldFrames((frame) => frame.member.startsWith('foo')); |
| 367 expect(folded.toString(), equals(''' |
370 foo.dart 42:21 notFoo | 368 foo.dart 42:21 notFoo |
371 foo.dart 1:100 fooBottom | 369 foo.dart 1:100 fooBottom |
372 bar.dart 10:20 alsoNotFoo | 370 bar.dart 10:20 alsoNotFoo |
373 dart:async-patch/future.dart 9:11 fooBottom | 371 dart:async-patch/future.dart 9:11 fooBottom |
374 ''')); | 372 ''')); |
375 }); | 373 }); |
376 | 374 |
377 test('.foldFrames with terse: true folds core frames as well', () { | 375 test('will never fold unparsed frames', () { |
378 var trace = new Trace.parse(''' | 376 var trace = new Trace.parse(r''' |
| 377 .g"cs$#:b";a#>sw{*{ul$"$xqwr`p |
| 378 %+j-?uppx<([j@#nu{{>*+$%x-={`{ |
| 379 !e($b{nj)zs?cgr%!;bmw.+$j+pfj~ |
| 380 '''); |
| 381 |
| 382 expect(trace.foldFrames((frame) => true).toString(), equals(r''' |
| 383 .g"cs$#:b";a#>sw{*{ul$"$xqwr`p |
| 384 %+j-?uppx<([j@#nu{{>*+$%x-={`{ |
| 385 !e($b{nj)zs?cgr%!;bmw.+$j+pfj~ |
| 386 ''')); |
| 387 }); |
| 388 |
| 389 group("with terse: true", () { |
| 390 test('folds core frames as well', () { |
| 391 var trace = new Trace.parse(''' |
379 #0 notFoo (foo.dart:42:21) | 392 #0 notFoo (foo.dart:42:21) |
380 #1 fooTop (bar.dart:0:2) | 393 #1 fooTop (bar.dart:0:2) |
381 #2 coreBottom (dart:async/future.dart:0:2) | 394 #2 coreBottom (dart:async/future.dart:0:2) |
382 #3 alsoNotFoo (bar.dart:10:20) | 395 #3 alsoNotFoo (bar.dart:10:20) |
383 #4 fooTop (foo.dart:9:11) | 396 #4 fooTop (foo.dart:9:11) |
384 #5 coreBottom (dart:async-patch/future.dart:9:11) | 397 #5 coreBottom (dart:async-patch/future.dart:9:11) |
385 '''); | 398 '''); |
386 | 399 |
387 var folded = trace.foldFrames((frame) => frame.member.startsWith('foo'), | 400 var folded = trace.foldFrames( |
388 terse: true); | 401 (frame) => frame.member.startsWith('foo'), |
389 expect(folded.toString(), equals(''' | 402 terse: true); |
| 403 expect(folded.toString(), equals(''' |
390 foo.dart 42:21 notFoo | 404 foo.dart 42:21 notFoo |
391 dart:async coreBottom | 405 dart:async coreBottom |
392 bar.dart 10:20 alsoNotFoo | 406 bar.dart 10:20 alsoNotFoo |
393 ''')); | 407 ''')); |
394 }); | 408 }); |
395 | 409 |
396 test('.foldFrames with terse: true shortens folded frames', () { | 410 test('shortens folded frames', () { |
397 var trace = new Trace.parse(''' | 411 var trace = new Trace.parse(''' |
398 #0 notFoo (foo.dart:42:21) | 412 #0 notFoo (foo.dart:42:21) |
399 #1 fooTop (bar.dart:0:2) | 413 #1 fooTop (bar.dart:0:2) |
400 #2 fooBottom (package:foo/bar.dart:0:2) | 414 #2 fooBottom (package:foo/bar.dart:0:2) |
401 #3 alsoNotFoo (bar.dart:10:20) | 415 #3 alsoNotFoo (bar.dart:10:20) |
402 #4 fooTop (foo.dart:9:11) | 416 #4 fooTop (foo.dart:9:11) |
403 #5 fooBottom (foo/bar.dart:9:11) | 417 #5 fooBottom (foo/bar.dart:9:11) |
| 418 #6 againNotFoo (bar.dart:20:20) |
404 '''); | 419 '''); |
405 | 420 |
406 var folded = trace.foldFrames((frame) => frame.member.startsWith('foo'), | 421 var folded = trace.foldFrames( |
407 terse: true); | 422 (frame) => frame.member.startsWith('foo'), |
408 expect(folded.toString(), equals(''' | 423 terse: true); |
| 424 expect(folded.toString(), equals(''' |
409 foo.dart 42:21 notFoo | 425 foo.dart 42:21 notFoo |
410 package:foo fooBottom | 426 package:foo fooBottom |
411 bar.dart 10:20 alsoNotFoo | 427 bar.dart 10:20 alsoNotFoo |
412 foo fooBottom | 428 foo fooBottom |
| 429 bar.dart 20:20 againNotFoo |
413 ''')); | 430 ''')); |
414 }); | 431 }); |
415 | 432 |
416 test('.foldFrames will never fold unparsed frames', () { | 433 test('removes the bottom-most folded frame', () { |
417 var trace = new Trace.parse(r''' | 434 var trace = new Trace.parse(''' |
418 .g"cs$#:b";a#>sw{*{ul$"$xqwr`p | 435 #2 fooTop (package:foo/bar.dart:0:2) |
419 %+j-?uppx<([j@#nu{{>*+$%x-={`{ | 436 #3 notFoo (bar.dart:10:20) |
420 !e($b{nj)zs?cgr%!;bmw.+$j+pfj~ | 437 #5 fooBottom (foo/bar.dart:9:11) |
421 '''); | 438 '''); |
422 | 439 |
423 expect(trace.foldFrames((frame) => true).toString(), equals(r''' | 440 var folded = trace.foldFrames( |
424 .g"cs$#:b";a#>sw{*{ul$"$xqwr`p | 441 (frame) => frame.member.startsWith('foo'), |
425 %+j-?uppx<([j@#nu{{>*+$%x-={`{ | 442 terse: true); |
426 !e($b{nj)zs?cgr%!;bmw.+$j+pfj~ | 443 expect(folded.toString(), equals(''' |
| 444 package:foo fooTop |
| 445 bar.dart 10:20 notFoo |
427 ''')); | 446 ''')); |
| 447 }); |
| 448 }); |
428 }); | 449 }); |
429 }); | 450 }); |
430 } | 451 } |
OLD | NEW |