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

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

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

Powered by Google App Engine
This is Rietveld 408576698