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

Side by Side Diff: pkg/stack_trace/test/frame_test.dart

Issue 17998002: Revert "Add support for V8 and Firefox stack traces in pkg/stack_trace." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 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
« no previous file with comments | « pkg/stack_trace/test/dartium_test.dart ('k') | pkg/stack_trace/test/trace_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 frame_test; 5 library frame_test;
6 6
7 import 'dart:io';
8
7 import 'package:pathos/path.dart' as path; 9 import 'package:pathos/path.dart' as path;
8 import 'package:stack_trace/stack_trace.dart'; 10 import 'package:stack_trace/stack_trace.dart';
9 import 'package:unittest/unittest.dart'; 11 import 'package:unittest/unittest.dart';
10 12
13 String getStackFrame() {
14 try {
15 throw '';
16 } catch (_, stackTrace) {
17 return stackTrace.toString().split("\n").first;
18 }
19 }
20
21 Frame getCaller([int level]) {
22 if (level == null) return new Frame.caller();
23 return new Frame.caller(level);
24 }
25
26 Frame nestedGetCaller(int level) => getCaller(level);
27
11 void main() { 28 void main() {
12 group('.parseVM', () { 29 test('parses a stack frame correctly', () {
13 test('parses a stack frame correctly', () { 30 var frame = new Frame.parse("#1 Foo._bar "
14 var frame = new Frame.parseVM("#1 Foo._bar " 31 "(file:///home/nweiz/code/stuff.dart:42:21)");
15 "(file:///home/nweiz/code/stuff.dart:42:21)"); 32 expect(frame.uri, equals(Uri.parse("file:///home/nweiz/code/stuff.dart")));
16 expect(frame.uri, 33 expect(frame.line, equals(42));
17 equals(Uri.parse("file:///home/nweiz/code/stuff.dart"))); 34 expect(frame.column, equals(21));
18 expect(frame.line, equals(42)); 35 expect(frame.member, equals('Foo._bar'));
19 expect(frame.column, equals(21));
20 expect(frame.member, equals('Foo._bar'));
21 });
22
23 test('converts "<anonymous closure>" to "<fn>"', () {
24 String parsedMember(String member) =>
25 new Frame.parseVM('#0 $member (foo:0:0)').member;
26
27 expect(parsedMember('Foo.<anonymous closure>'), equals('Foo.<fn>'));
28 expect(parsedMember('<anonymous closure>.<anonymous closure>.bar'),
29 equals('<fn>.<fn>.bar'));
30 });
31
32 test('throws a FormatException for malformed frames', () {
33 expect(() => new Frame.parseVM(''), throwsFormatException);
34 expect(() => new Frame.parseVM('#1'), throwsFormatException);
35 expect(() => new Frame.parseVM('#1 Foo'), throwsFormatException);
36 expect(() => new Frame.parseVM('#1 Foo (dart:async/future.dart)'),
37 throwsFormatException);
38 expect(() => new Frame.parseVM('#1 Foo (dart:async/future.dart:10)'),
39 throwsFormatException);
40 expect(() => new Frame.parseVM('#1 (dart:async/future.dart:10:15)'),
41 throwsFormatException);
42 expect(() => new Frame.parseVM('Foo (dart:async/future.dart:10:15)'),
43 throwsFormatException);
44 });
45 }); 36 });
46 37
47 group('.parseV8', () { 38 test('parses a real stack frame correctly', () {
48 test('parses a stack frame correctly', () { 39 var frame = new Frame.parse(getStackFrame());
49 var frame = new Frame.parseV8(" at VW.call\$0 " 40 // TODO(nweiz): use URL-style paths when such a thing exists.
50 "(http://pub.dartlang.org/stuff.dart.js:560:28)"); 41 var builder = new path.Builder(style: path.Style.posix);
51 expect(frame.uri, 42 expect(builder.basename(frame.uri.path), equals('frame_test.dart'));
52 equals(Uri.parse("http://pub.dartlang.org/stuff.dart.js"))); 43 expect(frame.line, equals(15));
53 expect(frame.line, equals(560)); 44 expect(frame.column, equals(5));
54 expect(frame.column, equals(28)); 45 expect(frame.member, equals('getStackFrame'));
55 expect(frame.member, equals('VW.call\$0'));
56 });
57
58 test('parses an anonymous stack frame correctly', () {
59 var frame = new Frame.parseV8(
60 " at http://pub.dartlang.org/stuff.dart.js:560:28");
61 expect(frame.uri,
62 equals(Uri.parse("http://pub.dartlang.org/stuff.dart.js")));
63 expect(frame.line, equals(560));
64 expect(frame.column, equals(28));
65 expect(frame.member, equals('<fn>'));
66 });
67
68 test('converts "<anonymous>" to "<fn>"', () {
69 String parsedMember(String member) =>
70 new Frame.parseV8(' at $member (foo:0:0)').member;
71
72 expect(parsedMember('Foo.<anonymous>'), equals('Foo.<fn>'));
73 expect(parsedMember('<anonymous>.<anonymous>.bar'),
74 equals('<fn>.<fn>.bar'));
75 });
76
77 test('throws a FormatException for malformed frames', () {
78 expect(() => new Frame.parseV8(''), throwsFormatException);
79 expect(() => new Frame.parseV8(' at'), throwsFormatException);
80 expect(() => new Frame.parseV8(' at Foo'), throwsFormatException);
81 expect(() => new Frame.parseV8(' at Foo (dart:async/future.dart)'),
82 throwsFormatException);
83 expect(() => new Frame.parseV8(' at Foo (dart:async/future.dart:10)'),
84 throwsFormatException);
85 expect(() => new Frame.parseV8(' at (dart:async/future.dart:10:15)'),
86 throwsFormatException);
87 expect(() => new Frame.parseV8('Foo (dart:async/future.dart:10:15)'),
88 throwsFormatException);
89 expect(() => new Frame.parseV8(' at dart:async/future.dart'),
90 throwsFormatException);
91 expect(() => new Frame.parseV8(' at dart:async/future.dart:10'),
92 throwsFormatException);
93 expect(() => new Frame.parseV8('dart:async/future.dart:10:15'),
94 throwsFormatException);
95 });
96 }); 46 });
97 47
98 group('.parseFirefox', () { 48 test('converts "<anonymous closure>" to "<fn>"', () {
99 test('parses a simple stack frame correctly', () { 49 String parsedMember(String member) =>
100 var frame = new Frame.parseFirefox( 50 new Frame.parse('#0 $member (foo:0:0)').member;
101 ".VW.call\$0@http://pub.dartlang.org/stuff.dart.js:560");
102 expect(frame.uri,
103 equals(Uri.parse("http://pub.dartlang.org/stuff.dart.js")));
104 expect(frame.line, equals(560));
105 expect(frame.column, isNull);
106 expect(frame.member, equals('VW.call\$0'));
107 });
108 51
109 test('parses a simple anonymous stack frame correctly', () { 52 expect(parsedMember('Foo.<anonymous closure>'), equals('Foo.<fn>'));
110 var frame = new Frame.parseFirefox( 53 expect(parsedMember('<anonymous closure>.<anonymous closure>.bar'),
111 "@http://pub.dartlang.org/stuff.dart.js:560"); 54 equals('<fn>.<fn>.bar'));
112 expect(frame.uri, 55 });
113 equals(Uri.parse("http://pub.dartlang.org/stuff.dart.js")));
114 expect(frame.line, equals(560));
115 expect(frame.column, isNull);
116 expect(frame.member, equals("<fn>"));
117 });
118 56
119 test('parses a nested anonymous stack frame correctly', () { 57 test('throws a FormatException for malformed frames', () {
120 var frame = new Frame.parseFirefox( 58 expect(() => new Frame.parse(''), throwsFormatException);
121 ".foo/<@http://pub.dartlang.org/stuff.dart.js:560"); 59 expect(() => new Frame.parse('#1'), throwsFormatException);
122 expect(frame.uri, 60 expect(() => new Frame.parse('#1 Foo'), throwsFormatException);
123 equals(Uri.parse("http://pub.dartlang.org/stuff.dart.js"))); 61 expect(() => new Frame.parse('#1 Foo (dart:async/future.dart)'),
124 expect(frame.line, equals(560)); 62 throwsFormatException);
125 expect(frame.column, isNull); 63 expect(() => new Frame.parse('#1 Foo (dart:async/future.dart:10)'),
126 expect(frame.member, equals("foo.<fn>")); 64 throwsFormatException);
127 }); 65 expect(() => new Frame.parse('#1 (dart:async/future.dart:10:15)'),
128 66 throwsFormatException);
129 test('parses a named nested anonymous stack frame correctly', () { 67 expect(() => new Frame.parse('Foo (dart:async/future.dart:10:15)'),
130 var frame = new Frame.parseFirefox( 68 throwsFormatException);
131 ".foo/.name<@http://pub.dartlang.org/stuff.dart.js:560");
132 expect(frame.uri,
133 equals(Uri.parse("http://pub.dartlang.org/stuff.dart.js")));
134 expect(frame.line, equals(560));
135 expect(frame.column, isNull);
136 expect(frame.member, equals("foo.<fn>"));
137 });
138
139 test('parses a stack frame with parameters correctly', () {
140 var frame = new Frame.parseFirefox(
141 '.foo(12, "@)()/<")@http://pub.dartlang.org/stuff.dart.js:560');
142 expect(frame.uri,
143 equals(Uri.parse("http://pub.dartlang.org/stuff.dart.js")));
144 expect(frame.line, equals(560));
145 expect(frame.column, isNull);
146 expect(frame.member, equals("foo"));
147 });
148
149 test('parses a nested anonymous stack frame with parameters correctly', () {
150 var frame = new Frame.parseFirefox(
151 '.foo(12, "@)()/<")/.fn<@'
152 'http://pub.dartlang.org/stuff.dart.js:560');
153 expect(frame.uri,
154 equals(Uri.parse("http://pub.dartlang.org/stuff.dart.js")));
155 expect(frame.line, equals(560));
156 expect(frame.column, isNull);
157 expect(frame.member, equals("foo.<fn>"));
158 });
159
160 test('throws a FormatException for malformed frames', () {
161 expect(() => new Frame.parseFirefox(''), throwsFormatException);
162 expect(() => new Frame.parseFirefox('.foo'), throwsFormatException);
163 expect(() => new Frame.parseFirefox('.foo@dart:async/future.dart'),
164 throwsFormatException);
165 expect(() => new Frame.parseFirefox('.foo/@dart:async/future.dart:10'),
166 throwsFormatException);
167 expect(() => new Frame.parseFirefox('.foo(@dart:async/future.dart:10'),
168 throwsFormatException);
169 expect(() => new Frame.parseFirefox('@dart:async/future.dart'),
170 throwsFormatException);
171 });
172 }); 69 });
173 70
174 test('only considers dart URIs to be core', () { 71 test('only considers dart URIs to be core', () {
175 bool isCore(String library) => 72 bool isCore(String library) =>
176 new Frame.parseVM('#0 Foo ($library:0:0)').isCore; 73 new Frame.parse('#0 Foo ($library:0:0)').isCore;
177 74
178 expect(isCore('dart:core'), isTrue); 75 expect(isCore('dart:core'), isTrue);
179 expect(isCore('dart:async'), isTrue); 76 expect(isCore('dart:async'), isTrue);
180 expect(isCore('dart:core/uri.dart'), isTrue); 77 expect(isCore('dart:core/uri.dart'), isTrue);
181 expect(isCore('dart:async/future.dart'), isTrue); 78 expect(isCore('dart:async/future.dart'), isTrue);
182 expect(isCore('bart:core'), isFalse); 79 expect(isCore('bart:core'), isFalse);
183 expect(isCore('sdart:core'), isFalse); 80 expect(isCore('sdart:core'), isFalse);
184 expect(isCore('darty:core'), isFalse); 81 expect(isCore('darty:core'), isFalse);
185 expect(isCore('bart:core/uri.dart'), isFalse); 82 expect(isCore('bart:core/uri.dart'), isFalse);
186 }); 83 });
187 84
85 group('.caller()', () {
86 test('with no argument returns the parent frame', () {
87 expect(getCaller().member, equals('main.<fn>.<fn>'));
88 });
89
90 test('at level 0 returns the current frame', () {
91 expect(getCaller(0).member, equals('getCaller'));
92 });
93
94 test('at level 1 returns the current frame', () {
95 expect(getCaller(1).member, equals('main.<fn>.<fn>'));
96 });
97
98 test('at level 2 returns the grandparent frame', () {
99 expect(nestedGetCaller(2).member, equals('main.<fn>.<fn>'));
100 });
101
102 test('throws an ArgumentError for negative levels', () {
103 expect(() => new Frame.caller(-1), throwsArgumentError);
104 });
105 });
106
188 group('.library', () { 107 group('.library', () {
189 test('returns the URI string for non-file URIs', () { 108 test('returns the URI string for non-file URIs', () {
190 expect(new Frame.parseVM('#0 Foo (dart:async/future.dart:0:0)').library, 109 expect(new Frame.parse('#0 Foo (dart:async/future.dart:0:0)').library,
191 equals('dart:async/future.dart')); 110 equals('dart:async/future.dart'));
192 expect(new Frame.parseVM('#0 Foo ' 111 expect(new Frame.parse('#0 Foo '
193 '(http://dartlang.org/stuff/thing.dart:0:0)').library, 112 '(http://dartlang.org/stuff/thing.dart:0:0)').library,
194 equals('http://dartlang.org/stuff/thing.dart')); 113 equals('http://dartlang.org/stuff/thing.dart'));
195 }); 114 });
196 115
197 test('returns the relative path for file URIs', () { 116 test('returns the relative path for file URIs', () {
198 expect(new Frame.parseVM('#0 Foo (foo/bar.dart:0:0)').library, 117 expect(new Frame.parse('#0 Foo (foo/bar.dart:0:0)').library,
199 equals('foo/bar.dart')); 118 equals('foo/bar.dart'));
200 }); 119 });
201 }); 120 });
202 121
203 group('.location', () { 122 group('.location', () {
204 test('returns the library and line/column numbers for non-core ' 123 test('returns the library and line/column numbers for non-core '
205 'libraries', () { 124 'libraries', () {
206 expect(new Frame.parseVM('#0 Foo ' 125 expect(new Frame.parse('#0 Foo '
207 '(http://dartlang.org/thing.dart:5:10)').location, 126 '(http://dartlang.org/thing.dart:5:10)').location,
208 equals('http://dartlang.org/thing.dart 5:10')); 127 equals('http://dartlang.org/thing.dart 5:10'));
209 expect(new Frame.parseVM('#0 Foo (foo/bar.dart:1:2)').location, 128 expect(new Frame.parse('#0 Foo (foo/bar.dart:1:2)').location,
210 equals('foo/bar.dart 1:2')); 129 equals('foo/bar.dart 1:2'));
211 }); 130 });
212 }); 131 });
213 132
214 group('.package', () { 133 group('.package', () {
215 test('returns null for non-package URIs', () { 134 test('returns null for non-package URIs', () {
216 expect(new Frame.parseVM('#0 Foo (dart:async/future.dart:0:0)').package, 135 expect(new Frame.parse('#0 Foo (dart:async/future.dart:0:0)').package,
217 isNull); 136 isNull);
218 expect(new Frame.parseVM('#0 Foo ' 137 expect(new Frame.parse('#0 Foo '
219 '(http://dartlang.org/stuff/thing.dart:0:0)').package, 138 '(http://dartlang.org/stuff/thing.dart:0:0)').package,
220 isNull); 139 isNull);
221 }); 140 });
222 141
223 test('returns the package name for package: URIs', () { 142 test('returns the package name for package: URIs', () {
224 expect(new Frame.parseVM('#0 Foo (package:foo/foo.dart:0:0)').package, 143 expect(new Frame.parse('#0 Foo (package:foo/foo.dart:0:0)').package,
225 equals('foo')); 144 equals('foo'));
226 expect(new Frame.parseVM('#0 Foo (package:foo/zap/bar.dart:0:0)').package, 145 expect(new Frame.parse('#0 Foo (package:foo/zap/bar.dart:0:0)').package,
227 equals('foo')); 146 equals('foo'));
228 }); 147 });
229 }); 148 });
230 149
231 group('.toString()', () { 150 group('.toString()', () {
232 test('returns the library and line/column numbers for non-core ' 151 test('returns the library and line/column numbers for non-core '
233 'libraries', () { 152 'libraries', () {
234 expect(new Frame.parseVM('#0 Foo (http://dartlang.org/thing.dart:5:10)') 153 expect(new Frame.parse('#0 Foo (http://dartlang.org/thing.dart:5:10)')
235 .toString(), 154 .toString(),
236 equals('http://dartlang.org/thing.dart 5:10 in Foo')); 155 equals('http://dartlang.org/thing.dart 5:10 in Foo'));
237 }); 156 });
238 157
239 test('converts "<anonymous closure>" to "<fn>"', () { 158 test('converts "<anonymous closure>" to "<fn>"', () {
240 expect(new Frame.parseVM('#0 Foo.<anonymous closure> ' 159 expect(new Frame.parse('#0 Foo.<anonymous closure> '
241 '(dart:core/uri.dart:5:10)').toString(), 160 '(dart:core/uri.dart:5:10)').toString(),
242 equals('dart:core/uri.dart 5:10 in Foo.<fn>')); 161 equals('dart:core/uri.dart 5:10 in Foo.<fn>'));
243 }); 162 });
244 }); 163 });
245 } 164 }
OLDNEW
« no previous file with comments | « pkg/stack_trace/test/dartium_test.dart ('k') | pkg/stack_trace/test/trace_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698