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