Chromium Code Reviews| 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() => StackTrace.current.toString(); | |
|
nweiz
2016/02/01 22:46:46
Add comments explaining why these have to be wrapp
kevmoo
2016/02/01 22:48:55
Done.
| |
| 16 | |
| 17 StackTrace getStackTraceObject() => StackTrace.current; | |
| 18 | |
| 15 Frame getCaller([int level]) { | 19 Frame getCaller([int level]) { |
| 16 if (level == null) return new Frame.caller(); | 20 if (level == null) return new Frame.caller(); |
| 17 return new Frame.caller(level); | 21 return new Frame.caller(level); |
| 18 } | 22 } |
| 19 | 23 |
| 20 Frame nestedGetCaller(int level) => getCaller(level); | 24 Frame nestedGetCaller(int level) => getCaller(level); |
| 21 | 25 |
| 22 Trace getCurrentTrace([int level]) => new Trace.current(level); | 26 Trace getCurrentTrace([int level]) => new Trace.current(level); |
| 23 | 27 |
| 24 Trace nestedGetCurrentTrace(int level) => getCurrentTrace(level); | 28 Trace nestedGetCurrentTrace(int level) => getCurrentTrace(level); |
| 25 | 29 |
| 26 void main() { | 30 void main() { |
| 27 group('Trace', () { | 31 group('Trace', () { |
| 28 test('.parse parses a real stack trace correctly', () { | 32 test('.parse parses a real stack trace correctly', () { |
| 29 var string = StackTrace.current.toString(); | 33 var string = getStackTraceString(); |
| 30 var trace = new Trace.parse(string); | 34 var trace = new Trace.parse(string); |
| 31 expect(path.url.basename(trace.frames.first.uri.path), | 35 expect(path.url.basename(trace.frames.first.uri.path), |
| 32 equals('vm_test.dart')); | 36 equals('vm_test.dart')); |
| 33 expect(trace.frames.first.member, equals('getStackTraceString')); | 37 expect(trace.frames.first.member, equals('getStackTraceString')); |
| 34 }); | 38 }); |
| 35 | 39 |
| 36 test('converts from a native stack trace correctly', () { | 40 test('converts from a native stack trace correctly', () { |
| 37 var trace = new Trace.from(StackTrace.current); | 41 var trace = new Trace.from(getStackTraceObject()); |
| 38 expect(path.url.basename(trace.frames.first.uri.path), | 42 expect(path.url.basename(trace.frames.first.uri.path), |
| 39 equals('vm_test.dart')); | 43 equals('vm_test.dart')); |
| 40 expect(trace.frames.first.member, equals('getStackTraceObject')); | 44 expect(trace.frames.first.member, equals('getStackTraceObject')); |
| 41 }); | 45 }); |
| 42 | 46 |
| 43 test('.from handles a stack overflow trace correctly', () { | 47 test('.from handles a stack overflow trace correctly', () { |
| 44 overflow() => overflow(); | 48 overflow() => overflow(); |
| 45 | 49 |
| 46 var trace; | 50 var trace; |
| 47 try { | 51 try { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 | 100 |
| 97 test('at level 2 returns the grandparent frame', () { | 101 test('at level 2 returns the grandparent frame', () { |
| 98 expect(nestedGetCaller(2).member, equals('main.<fn>.<fn>')); | 102 expect(nestedGetCaller(2).member, equals('main.<fn>.<fn>')); |
| 99 }); | 103 }); |
| 100 | 104 |
| 101 test('throws an ArgumentError for negative levels', () { | 105 test('throws an ArgumentError for negative levels', () { |
| 102 expect(() => new Frame.caller(-1), throwsArgumentError); | 106 expect(() => new Frame.caller(-1), throwsArgumentError); |
| 103 }); | 107 }); |
| 104 }); | 108 }); |
| 105 } | 109 } |
| OLD | NEW |