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 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'; | |
11 import 'package:stack_trace/stack_trace.dart'; | 10 import 'package:stack_trace/stack_trace.dart'; |
12 import 'package:unittest/unittest.dart'; | 11 import 'package:unittest/unittest.dart'; |
13 | 12 |
14 String getStackFrame() { | 13 String getStackFrame() { |
15 try { | 14 try { |
16 throw ''; | 15 throw ''; |
17 } catch (_, stackTrace) { | 16 } catch (_, stackTrace) { |
18 return stackTrace.toString().split("\n").first; | 17 return stackTrace.toString().split("\n").first; |
19 } | 18 } |
20 } | 19 } |
(...skipping 13 matching lines...) Expand all Loading... |
34 expect(frame.line, equals(42)); | 33 expect(frame.line, equals(42)); |
35 expect(frame.column, equals(21)); | 34 expect(frame.column, equals(21)); |
36 expect(frame.member, equals('Foo._bar')); | 35 expect(frame.member, equals('Foo._bar')); |
37 }); | 36 }); |
38 | 37 |
39 test('parses a real stack frame correctly', () { | 38 test('parses a real stack frame correctly', () { |
40 var frame = new Frame.parse(getStackFrame()); | 39 var frame = new Frame.parse(getStackFrame()); |
41 // TODO(nweiz): use URL-style paths when such a thing exists. | 40 // TODO(nweiz): use URL-style paths when such a thing exists. |
42 var builder = new path.Builder(style: path.Style.posix); | 41 var builder = new path.Builder(style: path.Style.posix); |
43 expect(builder.basename(frame.uri.path), equals('frame_test.dart')); | 42 expect(builder.basename(frame.uri.path), equals('frame_test.dart')); |
44 expect(frame.line, equals(16)); | 43 expect(frame.line, equals(15)); |
45 expect(frame.column, equals(5)); | 44 expect(frame.column, equals(5)); |
46 expect(frame.member, equals('getStackFrame')); | 45 expect(frame.member, equals('getStackFrame')); |
47 }); | 46 }); |
48 | 47 |
49 test('converts "<anonymous closure>" to "<fn>"', () { | 48 test('converts "<anonymous closure>" to "<fn>"', () { |
50 String parsedMember(String member) => | 49 String parsedMember(String member) => |
51 new Frame.parse('#0 $member (foo:0:0)').member; | 50 new Frame.parse('#0 $member (foo:0:0)').member; |
52 | 51 |
53 expect(parsedMember('Foo.<anonymous closure>'), equals('Foo.<fn>')); | 52 expect(parsedMember('Foo.<anonymous closure>'), equals('Foo.<fn>')); |
54 expect(parsedMember('<anonymous closure>.<anonymous closure>.bar'), | 53 expect(parsedMember('<anonymous closure>.<anonymous closure>.bar'), |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 group('.library', () { | 107 group('.library', () { |
109 test('returns the URI string for non-file URIs', () { | 108 test('returns the URI string for non-file URIs', () { |
110 expect(new Frame.parse('#0 Foo (dart:async/future.dart:0:0)').library, | 109 expect(new Frame.parse('#0 Foo (dart:async/future.dart:0:0)').library, |
111 equals('dart:async/future.dart')); | 110 equals('dart:async/future.dart')); |
112 expect(new Frame.parse('#0 Foo ' | 111 expect(new Frame.parse('#0 Foo ' |
113 '(http://dartlang.org/stuff/thing.dart:0:0)').library, | 112 '(http://dartlang.org/stuff/thing.dart:0:0)').library, |
114 equals('http://dartlang.org/stuff/thing.dart')); | 113 equals('http://dartlang.org/stuff/thing.dart')); |
115 }); | 114 }); |
116 | 115 |
117 test('returns the relative path for file URIs', () { | 116 test('returns the relative path for file URIs', () { |
118 var uri = pathToFileUri(path.join('foo', 'bar.dart')); | 117 var uri = path.toUri(path.join('foo', 'bar.dart')); |
119 expect(new Frame.parse('#0 Foo ($uri:0:0)').library, | 118 expect(new Frame.parse('#0 Foo ($uri:0:0)').library, |
120 equals(path.join('foo', 'bar.dart'))); | 119 equals(path.join('foo', 'bar.dart'))); |
121 }); | 120 }); |
122 }); | 121 }); |
123 | 122 |
124 group('.location', () { | 123 group('.location', () { |
125 test('returns the library and line/column numbers for non-core ' | 124 test('returns the library and line/column numbers for non-core ' |
126 'libraries', () { | 125 'libraries', () { |
127 expect(new Frame.parse('#0 Foo ' | 126 expect(new Frame.parse('#0 Foo ' |
128 '(http://dartlang.org/thing.dart:5:10)').location, | 127 '(http://dartlang.org/thing.dart:5:10)').location, |
129 equals('http://dartlang.org/thing.dart 5:10')); | 128 equals('http://dartlang.org/thing.dart 5:10')); |
130 var uri = pathToFileUri(path.join('foo', 'bar.dart')); | 129 var uri = path.toUri(path.join('foo', 'bar.dart')); |
131 expect(new Frame.parse('#0 Foo ($uri:1:2)').location, | 130 expect(new Frame.parse('#0 Foo ($uri:1:2)').location, |
132 equals('${path.join('foo', 'bar.dart')} 1:2')); | 131 equals('${path.join('foo', 'bar.dart')} 1:2')); |
133 }); | 132 }); |
134 }); | 133 }); |
135 | 134 |
136 group('.package', () { | 135 group('.package', () { |
137 test('returns null for non-package URIs', () { | 136 test('returns null for non-package URIs', () { |
138 expect(new Frame.parse('#0 Foo (dart:async/future.dart:0:0)').package, | 137 expect(new Frame.parse('#0 Foo (dart:async/future.dart:0:0)').package, |
139 isNull); | 138 isNull); |
140 expect(new Frame.parse('#0 Foo ' | 139 expect(new Frame.parse('#0 Foo ' |
(...skipping 17 matching lines...) Expand all Loading... |
158 equals('http://dartlang.org/thing.dart 5:10 in Foo')); | 157 equals('http://dartlang.org/thing.dart 5:10 in Foo')); |
159 }); | 158 }); |
160 | 159 |
161 test('converts "<anonymous closure>" to "<fn>"', () { | 160 test('converts "<anonymous closure>" to "<fn>"', () { |
162 expect(new Frame.parse('#0 Foo.<anonymous closure> ' | 161 expect(new Frame.parse('#0 Foo.<anonymous closure> ' |
163 '(dart:core/uri.dart:5:10)').toString(), | 162 '(dart:core/uri.dart:5:10)').toString(), |
164 equals('dart:core/uri.dart 5:10 in Foo.<fn>')); | 163 equals('dart:core/uri.dart 5:10 in Foo.<fn>')); |
165 }); | 164 }); |
166 }); | 165 }); |
167 } | 166 } |
OLD | NEW |