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

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

Issue 16097012: Make the StackTrace library better handle core library frames. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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
« no previous file with comments | « pkg/stack_trace/lib/src/trace.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'; 7 import 'dart:io';
8 8
9 import 'package:pathos/path.dart' as path; 9 import 'package:pathos/path.dart' as path;
10 import 'package:stack_trace/src/utils.dart'; 10 import 'package:stack_trace/src/utils.dart';
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 52
53 expect(parsedMember('Foo.<anonymous closure>'), equals('Foo.<fn>')); 53 expect(parsedMember('Foo.<anonymous closure>'), equals('Foo.<fn>'));
54 expect(parsedMember('<anonymous closure>.<anonymous closure>.bar'), 54 expect(parsedMember('<anonymous closure>.<anonymous closure>.bar'),
55 equals('<fn>.<fn>.bar')); 55 equals('<fn>.<fn>.bar'));
56 }); 56 });
57 57
58 test('throws a FormatException for malformed frames', () { 58 test('throws a FormatException for malformed frames', () {
59 expect(() => new Frame.parse(''), throwsFormatException); 59 expect(() => new Frame.parse(''), throwsFormatException);
60 expect(() => new Frame.parse('#1'), throwsFormatException); 60 expect(() => new Frame.parse('#1'), throwsFormatException);
61 expect(() => new Frame.parse('#1 Foo'), throwsFormatException); 61 expect(() => new Frame.parse('#1 Foo'), throwsFormatException);
62 expect(() => new Frame.parse('#1 Foo (dart:async)'), 62 expect(() => new Frame.parse('#1 Foo (dart:async/future.dart)'),
63 throwsFormatException); 63 throwsFormatException);
64 expect(() => new Frame.parse('#1 Foo (dart:async:10)'), 64 expect(() => new Frame.parse('#1 Foo (dart:async/future.dart:10)'),
65 throwsFormatException); 65 throwsFormatException);
66 expect(() => new Frame.parse('#1 (dart:async:10:15)'), 66 expect(() => new Frame.parse('#1 (dart:async/future.dart:10:15)'),
67 throwsFormatException); 67 throwsFormatException);
68 expect(() => new Frame.parse('Foo (dart:async:10:15)'), 68 expect(() => new Frame.parse('Foo (dart:async/future.dart:10:15)'),
69 throwsFormatException); 69 throwsFormatException);
70 }); 70 });
71 71
72 test('only considers dart URIs to be core', () { 72 test('only considers dart URIs to be core', () {
73 bool isCore(String library) => 73 bool isCore(String library) =>
74 new Frame.parse('#0 Foo ($library:0:0)').isCore; 74 new Frame.parse('#0 Foo ($library:0:0)').isCore;
75 75
76 expect(isCore('dart:core'), isTrue); 76 expect(isCore('dart:core'), isTrue);
77 expect(isCore('dart:async'), isTrue); 77 expect(isCore('dart:async'), isTrue);
78 expect(isCore('dart:core/uri.dart'), isTrue);
79 expect(isCore('dart:async/future.dart'), isTrue);
78 expect(isCore('bart:core'), isFalse); 80 expect(isCore('bart:core'), isFalse);
79 expect(isCore('sdart:core'), isFalse); 81 expect(isCore('sdart:core'), isFalse);
80 expect(isCore('darty:core'), isFalse); 82 expect(isCore('darty:core'), isFalse);
83 expect(isCore('bart:core/uri.dart'), isFalse);
81 }); 84 });
82 85
83 group('.caller()', () { 86 group('.caller()', () {
84 test('with no argument returns the parent frame', () { 87 test('with no argument returns the parent frame', () {
85 expect(getCaller().member, equals('main.<fn>.<fn>')); 88 expect(getCaller().member, equals('main.<fn>.<fn>'));
86 }); 89 });
87 90
88 test('at level 0 returns the current frame', () { 91 test('at level 0 returns the current frame', () {
89 expect(getCaller(0).member, equals('getCaller')); 92 expect(getCaller(0).member, equals('getCaller'));
90 }); 93 });
91 94
92 test('at level 1 returns the current frame', () { 95 test('at level 1 returns the current frame', () {
93 expect(getCaller(1).member, equals('main.<fn>.<fn>')); 96 expect(getCaller(1).member, equals('main.<fn>.<fn>'));
94 }); 97 });
95 98
96 test('at level 2 returns the grandparent frame', () { 99 test('at level 2 returns the grandparent frame', () {
97 expect(nestedGetCaller(2).member, equals('main.<fn>.<fn>')); 100 expect(nestedGetCaller(2).member, equals('main.<fn>.<fn>'));
98 }); 101 });
99 102
100 test('throws an ArgumentError for negative levels', () { 103 test('throws an ArgumentError for negative levels', () {
101 expect(() => new Frame.caller(-1), throwsArgumentError); 104 expect(() => new Frame.caller(-1), throwsArgumentError);
102 }); 105 });
103 }); 106 });
104 107
105 group('.library', () { 108 group('.library', () {
106 test('returns the URI string for non-file URIs', () { 109 test('returns the URI string for non-file URIs', () {
107 expect(new Frame.parse('#0 Foo (dart:async:0:0)').library, 110 expect(new Frame.parse('#0 Foo (dart:async/future.dart:0:0)').library,
108 equals('dart:async')); 111 equals('dart:async/future.dart'));
109 expect(new Frame.parse('#0 Foo ' 112 expect(new Frame.parse('#0 Foo '
110 '(http://dartlang.org/stuff/thing.dart:0:0)').library, 113 '(http://dartlang.org/stuff/thing.dart:0:0)').library,
111 equals('http://dartlang.org/stuff/thing.dart')); 114 equals('http://dartlang.org/stuff/thing.dart'));
112 }); 115 });
113 116
114 test('returns the relative path for file URIs', () { 117 test('returns the relative path for file URIs', () {
115 var uri = pathToFileUri(path.join('foo', 'bar.dart')); 118 var uri = pathToFileUri(path.join('foo', 'bar.dart'));
116 expect(new Frame.parse('#0 Foo ($uri:0:0)').library, 119 expect(new Frame.parse('#0 Foo ($uri:0:0)').library,
117 equals(path.join('foo', 'bar.dart'))); 120 equals(path.join('foo', 'bar.dart')));
118 }); 121 });
119 }); 122 });
120 123
121 group('.location', () { 124 group('.location', () {
122 test('returns the library and line/column numbers for non-core ' 125 test('returns the library and line/column numbers for non-core '
123 'libraries', () { 126 'libraries', () {
124 expect(new Frame.parse('#0 Foo ' 127 expect(new Frame.parse('#0 Foo '
125 '(http://dartlang.org/thing.dart:5:10)').location, 128 '(http://dartlang.org/thing.dart:5:10)').location,
126 equals('http://dartlang.org/thing.dart 5:10')); 129 equals('http://dartlang.org/thing.dart 5:10'));
127 var uri = pathToFileUri(path.join('foo', 'bar.dart')); 130 var uri = pathToFileUri(path.join('foo', 'bar.dart'));
128 expect(new Frame.parse('#0 Foo ($uri:1:2)').location, 131 expect(new Frame.parse('#0 Foo ($uri:1:2)').location,
129 equals('${path.join('foo', 'bar.dart')} 1:2')); 132 equals('${path.join('foo', 'bar.dart')} 1:2'));
130 }); 133 });
131
132 test('just returns the library for core libraries', () {
133 expect(new Frame.parse('#0 Foo (dart:core:5:10)').location,
134 equals('dart:core'));
135 expect(new Frame.parse('#0 Foo (dart:async-patch:1:2)').location,
136 equals('dart:async-patch'));
137 });
138 }); 134 });
139 135
140 group('.package', () { 136 group('.package', () {
141 test('returns null for non-package URIs', () { 137 test('returns null for non-package URIs', () {
142 expect(new Frame.parse('#0 Foo (dart:async:0:0)').package, isNull); 138 expect(new Frame.parse('#0 Foo (dart:async/future.dart:0:0)').package,
139 isNull);
143 expect(new Frame.parse('#0 Foo ' 140 expect(new Frame.parse('#0 Foo '
144 '(http://dartlang.org/stuff/thing.dart:0:0)').package, 141 '(http://dartlang.org/stuff/thing.dart:0:0)').package,
145 isNull); 142 isNull);
146 }); 143 });
147 144
148 test('returns the package name for package: URIs', () { 145 test('returns the package name for package: URIs', () {
149 expect(new Frame.parse('#0 Foo (package:foo/foo.dart:0:0)').package, 146 expect(new Frame.parse('#0 Foo (package:foo/foo.dart:0:0)').package,
150 equals('foo')); 147 equals('foo'));
151 expect(new Frame.parse('#0 Foo (package:foo/zap/bar.dart:0:0)').package, 148 expect(new Frame.parse('#0 Foo (package:foo/zap/bar.dart:0:0)').package,
152 equals('foo')); 149 equals('foo'));
153 }); 150 });
154 }); 151 });
155 152
156 group('.toString()', () { 153 group('.toString()', () {
157 test('returns the library and line/column numbers for non-core ' 154 test('returns the library and line/column numbers for non-core '
158 'libraries', () { 155 'libraries', () {
159 expect(new Frame.parse('#0 Foo (http://dartlang.org/thing.dart:5:10)') 156 expect(new Frame.parse('#0 Foo (http://dartlang.org/thing.dart:5:10)')
160 .toString(), 157 .toString(),
161 equals('http://dartlang.org/thing.dart 5:10 in Foo')); 158 equals('http://dartlang.org/thing.dart 5:10 in Foo'));
162 }); 159 });
163 160
164 test('just returns the library for core libraries', () {
165 expect(new Frame.parse('#0 Foo (dart:core:5:10)').toString(),
166 equals('dart:core in Foo'));
167 });
168
169 test('converts "<anonymous closure>" to "<fn>"', () { 161 test('converts "<anonymous closure>" to "<fn>"', () {
170 expect(new Frame.parse('#0 Foo.<anonymous closure> (dart:core:5:10)') 162 expect(new Frame.parse('#0 Foo.<anonymous closure> '
171 .toString(), 163 '(dart:core/uri.dart:5:10)').toString(),
172 equals('dart:core in Foo.<fn>')); 164 equals('dart:core/uri.dart 5:10 in Foo.<fn>'));
Bob Nystrom 2013/06/04 23:21:05 These line numbers are going to be brittle. Maybe
nweiz 2013/06/04 23:35:58 Everything is parsed from manually-entered strings
173 }); 165 });
174 }); 166 });
175 } 167 }
OLDNEW
« no previous file with comments | « pkg/stack_trace/lib/src/trace.dart ('k') | pkg/stack_trace/test/trace_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698