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