| 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 '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 17 matching lines...) Expand all Loading... |
| 28 } | 28 } |
| 29 | 29 |
| 30 Trace getCurrentTrace([int level]) => new Trace.current(level); | 30 Trace getCurrentTrace([int level]) => new Trace.current(level); |
| 31 | 31 |
| 32 Trace nestedGetCurrentTrace(int level) => getCurrentTrace(level); | 32 Trace nestedGetCurrentTrace(int level) => getCurrentTrace(level); |
| 33 | 33 |
| 34 void main() { | 34 void main() { |
| 35 test('parses a stack trace correctly', () { | 35 test('parses a stack trace correctly', () { |
| 36 var trace = new Trace.parse(''' | 36 var trace = new Trace.parse(''' |
| 37 #0 Foo._bar (file:///home/nweiz/code/stuff.dart:42:21) | 37 #0 Foo._bar (file:///home/nweiz/code/stuff.dart:42:21) |
| 38 #1 zip.<anonymous closure>.zap (dart:async:0:2) | 38 #1 zip.<anonymous closure>.zap (dart:async/future.dart:0:2) |
| 39 #2 zip.<anonymous closure>.zap (http://pub.dartlang.org/thing.dart:1:100) | 39 #2 zip.<anonymous closure>.zap (http://pub.dartlang.org/thing.dart:1:100) |
| 40 '''); | 40 '''); |
| 41 | 41 |
| 42 expect(trace.frames[0].uri, | 42 expect(trace.frames[0].uri, |
| 43 equals(Uri.parse("file:///home/nweiz/code/stuff.dart"))); | 43 equals(Uri.parse("file:///home/nweiz/code/stuff.dart"))); |
| 44 expect(trace.frames[1].uri, equals(Uri.parse("dart:async"))); | 44 expect(trace.frames[1].uri, equals(Uri.parse("dart:async/future.dart"))); |
| 45 expect(trace.frames[2].uri, | 45 expect(trace.frames[2].uri, |
| 46 equals(Uri.parse("http://pub.dartlang.org/thing.dart"))); | 46 equals(Uri.parse("http://pub.dartlang.org/thing.dart"))); |
| 47 }); | 47 }); |
| 48 | 48 |
| 49 test('parses a real stack trace correctly', () { | 49 test('parses a real stack trace correctly', () { |
| 50 var trace = new Trace.parse(getStackTraceString()); | 50 var trace = new Trace.parse(getStackTraceString()); |
| 51 // TODO(nweiz): use URL-style paths when such a thing exists. | 51 // TODO(nweiz): use URL-style paths when such a thing exists. |
| 52 var builder = new path.Builder(style: path.Style.posix); | 52 var builder = new path.Builder(style: path.Style.posix); |
| 53 expect(builder.basename(trace.frames.first.uri.path), | 53 expect(builder.basename(trace.frames.first.uri.path), |
| 54 equals('trace_test.dart')); | 54 equals('trace_test.dart')); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 | 87 |
| 88 test('throws an ArgumentError for negative levels', () { | 88 test('throws an ArgumentError for negative levels', () { |
| 89 expect(() => new Trace.current(-1), throwsArgumentError); | 89 expect(() => new Trace.current(-1), throwsArgumentError); |
| 90 }); | 90 }); |
| 91 }); | 91 }); |
| 92 | 92 |
| 93 test('.toString() nicely formats the stack trace', () { | 93 test('.toString() nicely formats the stack trace', () { |
| 94 var uri = pathToFileUri(path.join('foo', 'bar.dart')); | 94 var uri = pathToFileUri(path.join('foo', 'bar.dart')); |
| 95 var trace = new Trace.parse(''' | 95 var trace = new Trace.parse(''' |
| 96 #0 Foo._bar ($uri:42:21) | 96 #0 Foo._bar ($uri:42:21) |
| 97 #1 zip.<anonymous closure>.zap (dart:async:0:2) | 97 #1 zip.<anonymous closure>.zap (dart:async/future.dart:0:2) |
| 98 #2 zip.<anonymous closure>.zap (http://pub.dartlang.org/thing.dart:1:100) | 98 #2 zip.<anonymous closure>.zap (http://pub.dartlang.org/thing.dart:1:100) |
| 99 '''); | 99 '''); |
| 100 | 100 |
| 101 expect(trace.toString(), equals(''' | 101 expect(trace.toString(), equals(''' |
| 102 ${path.join('foo', 'bar.dart')} 42:21 Foo._bar | 102 ${path.join('foo', 'bar.dart')} 42:21 Foo._bar |
| 103 dart:async zip.<fn>.zap | 103 dart:async/future.dart 0:2 zip.<fn>.zap |
| 104 http://pub.dartlang.org/thing.dart 1:100 zip.<fn>.zap | 104 http://pub.dartlang.org/thing.dart 1:100 zip.<fn>.zap |
| 105 ''')); | 105 ''')); |
| 106 }); | 106 }); |
| 107 | 107 |
| 108 test('.stackTrace forwards to .toString()', () { | 108 test('.stackTrace forwards to .toString()', () { |
| 109 var trace = new Trace.current(); | 109 var trace = new Trace.current(); |
| 110 expect(trace.stackTrace, equals(trace.toString())); | 110 expect(trace.stackTrace, equals(trace.toString())); |
| 111 }); | 111 }); |
| 112 | 112 |
| 113 test('.fullStackTrace forwards to .toString()', () { | 113 test('.fullStackTrace forwards to .toString()', () { |
| 114 var trace = new Trace.current(); | 114 var trace = new Trace.current(); |
| 115 expect(trace.fullStackTrace, equals(trace.toString())); | 115 expect(trace.fullStackTrace, equals(trace.toString())); |
| 116 }); | 116 }); |
| 117 | 117 |
| 118 test('.terse folds core frames together bottom-up', () { | 118 test('.terse folds core frames together bottom-up', () { |
| 119 var trace = new Trace.parse(''' | 119 var trace = new Trace.parse(''' |
| 120 #0 notCore (foo.dart:42:21) | 120 #0 notCore (foo.dart:42:21) |
| 121 #1 top (dart:async:0:2) | 121 #1 top (dart:async/future.dart:0:2) |
| 122 #2 bottom (dart:core:1:100) | 122 #2 bottom (dart:core/uri.dart:1:100) |
| 123 #3 alsoNotCore (bar.dart:10:20) | 123 #3 alsoNotCore (bar.dart:10:20) |
| 124 #4 top (dart:io:5:10) | 124 #4 top (dart:io:5:10) |
| 125 #5 bottom (dart:async-patch:9:11) | 125 #5 bottom (dart:async-patch/future.dart:9:11) |
| 126 '''); | 126 '''); |
| 127 | 127 |
| 128 expect(trace.terse.toString(), equals(''' | 128 expect(trace.terse.toString(), equals(''' |
| 129 foo.dart 42:21 notCore | 129 foo.dart 42:21 notCore |
| 130 dart:core bottom | 130 dart:core bottom |
| 131 bar.dart 10:20 alsoNotCore | 131 bar.dart 10:20 alsoNotCore |
| 132 dart:async bottom | 132 dart:async bottom |
| 133 ''')); | 133 ''')); |
| 134 }); | 134 }); |
| 135 | 135 |
| 136 test('.foldFrames folds frames together bottom-up', () { | 136 test('.foldFrames folds frames together bottom-up', () { |
| 137 var trace = new Trace.parse(''' | 137 var trace = new Trace.parse(''' |
| 138 #0 notFoo (foo.dart:42:21) | 138 #0 notFoo (foo.dart:42:21) |
| 139 #1 fooTop (bar.dart:0:2) | 139 #1 fooTop (bar.dart:0:2) |
| 140 #2 fooBottom (foo.dart:1:100) | 140 #2 fooBottom (foo.dart:1:100) |
| 141 #3 alsoNotFoo (bar.dart:10:20) | 141 #3 alsoNotFoo (bar.dart:10:20) |
| 142 #4 fooTop (dart:io:5:10) | 142 #4 fooTop (dart:io/socket.dart:5:10) |
| 143 #5 fooBottom (dart:async-patch:9:11) | 143 #5 fooBottom (dart:async-patch/future.dart:9:11) |
| 144 '''); | 144 '''); |
| 145 | 145 |
| 146 var folded = trace.foldFrames((frame) => frame.member.startsWith('foo')); | 146 var folded = trace.foldFrames((frame) => frame.member.startsWith('foo')); |
| 147 expect(folded.toString(), equals(''' | 147 expect(folded.toString(), equals(''' |
| 148 foo.dart 42:21 notFoo | 148 foo.dart 42:21 notFoo |
| 149 foo.dart 1:100 fooBottom | 149 foo.dart 1:100 fooBottom |
| 150 bar.dart 10:20 alsoNotFoo | 150 bar.dart 10:20 alsoNotFoo |
| 151 dart:async-patch fooBottom | 151 dart:async-patch/future.dart 9:11 fooBottom |
| 152 ''')); | 152 ''')); |
| 153 }); | 153 }); |
| 154 } | 154 } |
| OLD | NEW |