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'; | |
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 getStackTraceString() { | 13 String getStackTraceString() { |
15 try { | 14 try { |
16 throw ''; | 15 throw ''; |
17 } catch (_, stackTrace) { | 16 } catch (_, stackTrace) { |
18 return stackTrace.toString(); | 17 return stackTrace.toString(); |
19 } | 18 } |
20 } | 19 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 var trace = nestedGetCurrentTrace(2); | 83 var trace = nestedGetCurrentTrace(2); |
85 expect(trace.frames.first.member, equals('main.<fn>.<fn>')); | 84 expect(trace.frames.first.member, equals('main.<fn>.<fn>')); |
86 }); | 85 }); |
87 | 86 |
88 test('throws an ArgumentError for negative levels', () { | 87 test('throws an ArgumentError for negative levels', () { |
89 expect(() => new Trace.current(-1), throwsArgumentError); | 88 expect(() => new Trace.current(-1), throwsArgumentError); |
90 }); | 89 }); |
91 }); | 90 }); |
92 | 91 |
93 test('.toString() nicely formats the stack trace', () { | 92 test('.toString() nicely formats the stack trace', () { |
94 var uri = pathToFileUri(path.join('foo', 'bar.dart')); | 93 var uri = path.toUri(path.join('foo', 'bar.dart')); |
95 var trace = new Trace.parse(''' | 94 var trace = new Trace.parse(''' |
96 #0 Foo._bar ($uri:42:21) | 95 #0 Foo._bar ($uri:42:21) |
97 #1 zip.<anonymous closure>.zap (dart:async/future.dart:0:2) | 96 #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) | 97 #2 zip.<anonymous closure>.zap (http://pub.dartlang.org/thing.dart:1:100) |
99 '''); | 98 '''); |
100 | 99 |
101 expect(trace.toString(), equals(''' | 100 expect(trace.toString(), equals(''' |
102 ${path.join('foo', 'bar.dart')} 42:21 Foo._bar | 101 ${path.join('foo', 'bar.dart')} 42:21 Foo._bar |
103 dart:async/future.dart 0:2 zip.<fn>.zap | 102 dart:async/future.dart 0:2 zip.<fn>.zap |
104 http://pub.dartlang.org/thing.dart 1:100 zip.<fn>.zap | 103 http://pub.dartlang.org/thing.dart 1:100 zip.<fn>.zap |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 | 144 |
146 var folded = trace.foldFrames((frame) => frame.member.startsWith('foo')); | 145 var folded = trace.foldFrames((frame) => frame.member.startsWith('foo')); |
147 expect(folded.toString(), equals(''' | 146 expect(folded.toString(), equals(''' |
148 foo.dart 42:21 notFoo | 147 foo.dart 42:21 notFoo |
149 foo.dart 1:100 fooBottom | 148 foo.dart 1:100 fooBottom |
150 bar.dart 10:20 alsoNotFoo | 149 bar.dart 10:20 alsoNotFoo |
151 dart:async-patch/future.dart 9:11 fooBottom | 150 dart:async-patch/future.dart 9:11 fooBottom |
152 ''')); | 151 ''')); |
153 }); | 152 }); |
154 } | 153 } |
OLD | NEW |