| 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 trace_test; | 5 library trace_test; |
| 6 | 6 |
| 7 import 'package:pathos/path.dart' as path; | 7 import 'package:pathos/path.dart' as path; |
| 8 import 'package:stack_trace/stack_trace.dart'; | 8 import 'package:stack_trace/stack_trace.dart'; |
| 9 import 'package:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
| 10 | 10 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 'Foo._bar@http://pub.dartlang.org/stuff.js:42'); | 94 'Foo._bar@http://pub.dartlang.org/stuff.js:42'); |
| 95 | 95 |
| 96 expect(trace.frames[0].uri, | 96 expect(trace.frames[0].uri, |
| 97 equals(Uri.parse("http://pub.dartlang.org/thing.js"))); | 97 equals(Uri.parse("http://pub.dartlang.org/thing.js"))); |
| 98 expect(trace.frames[1].uri, | 98 expect(trace.frames[1].uri, |
| 99 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); | 99 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); |
| 100 expect(trace.frames[2].uri, | 100 expect(trace.frames[2].uri, |
| 101 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); | 101 equals(Uri.parse("http://pub.dartlang.org/stuff.js"))); |
| 102 }); | 102 }); |
| 103 | 103 |
| 104 test('parses a package:stack_trace stack trace correctly', () { |
| 105 var trace = new Trace.parse( |
| 106 'http://dartlang.org/foo/bar.dart 10:11 Foo.<fn>.bar\n' |
| 107 'http://dartlang.org/foo/baz.dart Foo.<fn>.bar'); |
| 108 |
| 109 expect(trace.frames[0].uri, |
| 110 equals(Uri.parse("http://dartlang.org/foo/bar.dart"))); |
| 111 expect(trace.frames[1].uri, |
| 112 equals(Uri.parse("http://dartlang.org/foo/baz.dart"))); |
| 113 }); |
| 114 |
| 115 test('parses a real package:stack_trace stack trace correctly', () { |
| 116 var traceString = new Trace.current().toString(); |
| 117 expect(new Trace.parse(traceString).toString(), equals(traceString)); |
| 118 }); |
| 119 |
| 104 test('parses an empty string correctly', () { | 120 test('parses an empty string correctly', () { |
| 105 var trace = new Trace.parse(''); | 121 var trace = new Trace.parse(''); |
| 106 expect(trace.frames, isEmpty); | 122 expect(trace.frames, isEmpty); |
| 107 expect(trace.toString(), equals('')); | 123 expect(trace.toString(), equals('')); |
| 108 }); | 124 }); |
| 109 }); | 125 }); |
| 110 | 126 |
| 111 test('.toString() nicely formats the stack trace', () { | 127 test('.toString() nicely formats the stack trace', () { |
| 112 var trace = new Trace.parse(''' | 128 var trace = new Trace.parse(''' |
| 113 #0 Foo._bar (foo/bar.dart:42:21) | 129 #0 Foo._bar (foo/bar.dart:42:21) |
| 114 #1 zip.<anonymous closure>.zap (dart:async/future.dart:0:2) | 130 #1 zip.<anonymous closure>.zap (dart:async/future.dart:0:2) |
| 115 #2 zip.<anonymous closure>.zap (http://pub.dartlang.org/thing.dart:1:100) | 131 #2 zip.<anonymous closure>.zap (http://pub.dartlang.org/thing.dart:1:100) |
| 116 '''); | 132 '''); |
| 117 | 133 |
| 118 expect(trace.toString(), equals(''' | 134 expect(trace.toString(), equals(''' |
| 119 foo/bar.dart 42:21 Foo._bar | 135 foo/bar.dart 42:21 Foo._bar |
| 120 dart:async/future.dart 0:2 zip.<fn>.zap | 136 dart:async/future.dart 0:2 zip.<fn>.zap |
| 121 http://pub.dartlang.org/thing.dart 1:100 zip.<fn>.zap | 137 http://pub.dartlang.org/thing.dart 1:100 zip.<fn>.zap |
| 122 ''')); | 138 ''')); |
| 123 }); | 139 }); |
| 124 | 140 |
| 125 test('.stackTrace forwards to .toString()', () { | 141 test('.vmTrace returns a native-style trace', () { |
| 126 var trace = new Trace.current(); | 142 var uri = path.toUri(path.absolute('foo')); |
| 127 expect(trace.stackTrace, equals(trace.toString())); | 143 var trace = new Trace([ |
| 128 }); | 144 new Frame(uri, 10, 20, 'Foo.<fn>'), |
| 145 new Frame(Uri.parse('http://dartlang.org/foo.dart'), null, null, 'bar'), |
| 146 new Frame(Uri.parse('dart:async'), 15, null, 'baz'), |
| 147 ]); |
| 129 | 148 |
| 130 test('.fullStackTrace forwards to .toString()', () { | 149 expect(trace.vmTrace.toString(), equals( |
| 131 var trace = new Trace.current(); | 150 '#1 Foo.<anonymous closure> ($uri:10:20)\n' |
| 132 expect(trace.fullStackTrace, equals(trace.toString())); | 151 '#2 bar (http://dartlang.org/foo.dart:0:0)\n' |
| 152 '#3 baz (dart:async:15:0)\n')); |
| 133 }); | 153 }); |
| 134 | 154 |
| 135 test('.terse folds core frames together bottom-up', () { | 155 test('.terse folds core frames together bottom-up', () { |
| 136 var trace = new Trace.parse(''' | 156 var trace = new Trace.parse(''' |
| 137 #0 notCore (foo.dart:42:21) | 157 #0 notCore (foo.dart:42:21) |
| 138 #1 top (dart:async/future.dart:0:2) | 158 #1 top (dart:async/future.dart:0:2) |
| 139 #2 bottom (dart:core/uri.dart:1:100) | 159 #2 bottom (dart:core/uri.dart:1:100) |
| 140 #3 alsoNotCore (bar.dart:10:20) | 160 #3 alsoNotCore (bar.dart:10:20) |
| 141 #4 top (dart:io:5:10) | 161 #4 top (dart:io:5:10) |
| 142 #5 bottom (dart:async-patch/future.dart:9:11) | 162 #5 bottom (dart:async-patch/future.dart:9:11) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 162 | 182 |
| 163 var folded = trace.foldFrames((frame) => frame.member.startsWith('foo')); | 183 var folded = trace.foldFrames((frame) => frame.member.startsWith('foo')); |
| 164 expect(folded.toString(), equals(''' | 184 expect(folded.toString(), equals(''' |
| 165 foo.dart 42:21 notFoo | 185 foo.dart 42:21 notFoo |
| 166 foo.dart 1:100 fooBottom | 186 foo.dart 1:100 fooBottom |
| 167 bar.dart 10:20 alsoNotFoo | 187 bar.dart 10:20 alsoNotFoo |
| 168 dart:async-patch/future.dart 9:11 fooBottom | 188 dart:async-patch/future.dart 9:11 fooBottom |
| 169 ''')); | 189 ''')); |
| 170 }); | 190 }); |
| 171 } | 191 } |
| OLD | NEW |