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 /// This file tests stack_trace's ability to parse live stack traces. It's a | 5 /// This file tests stack_trace's ability to parse live stack traces. It's a |
6 /// dual of dartium_test.dart, since method names can differ somewhat from | 6 /// dual of dartium_test.dart, since method names can differ somewhat from |
7 /// platform to platform. No similar file exists for dart2js since the specific | 7 /// platform to platform. No similar file exists for dart2js since the specific |
8 /// method names there are implementation details. | 8 /// method names there are implementation details. |
9 @TestOn('vm') | 9 @TestOn('vm') |
10 | 10 |
11 import 'package:path/path.dart' as path; | 11 import 'package:path/path.dart' as path; |
12 import 'package:stack_trace/stack_trace.dart'; | 12 import 'package:stack_trace/stack_trace.dart'; |
13 import 'package:test/test.dart'; | 13 import 'package:test/test.dart'; |
14 | 14 |
15 String getStackTraceString() { | 15 // The name of this (trivial) function is verified as part of the test |
16 try { | 16 String getStackTraceString() => StackTrace.current.toString(); |
17 throw ''; | |
18 } catch (_, stackTrace) { | |
19 return stackTrace.toString(); | |
20 } | |
21 } | |
22 | 17 |
23 StackTrace getStackTraceObject() { | 18 // The name of this (trivial) function is verified as part of the test |
24 try { | 19 StackTrace getStackTraceObject() => StackTrace.current; |
25 throw ''; | |
26 } catch (_, stackTrace) { | |
27 return stackTrace; | |
28 } | |
29 } | |
30 | 20 |
31 Frame getCaller([int level]) { | 21 Frame getCaller([int level]) { |
32 if (level == null) return new Frame.caller(); | 22 if (level == null) return new Frame.caller(); |
33 return new Frame.caller(level); | 23 return new Frame.caller(level); |
34 } | 24 } |
35 | 25 |
36 Frame nestedGetCaller(int level) => getCaller(level); | 26 Frame nestedGetCaller(int level) => getCaller(level); |
37 | 27 |
38 Trace getCurrentTrace([int level]) => new Trace.current(level); | 28 Trace getCurrentTrace([int level]) => new Trace.current(level); |
39 | 29 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 | 102 |
113 test('at level 2 returns the grandparent frame', () { | 103 test('at level 2 returns the grandparent frame', () { |
114 expect(nestedGetCaller(2).member, equals('main.<fn>.<fn>')); | 104 expect(nestedGetCaller(2).member, equals('main.<fn>.<fn>')); |
115 }); | 105 }); |
116 | 106 |
117 test('throws an ArgumentError for negative levels', () { | 107 test('throws an ArgumentError for negative levels', () { |
118 expect(() => new Frame.caller(-1), throwsArgumentError); | 108 expect(() => new Frame.caller(-1), throwsArgumentError); |
119 }); | 109 }); |
120 }); | 110 }); |
121 } | 111 } |
OLD | NEW |