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