Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(721)

Side by Side Diff: test/vm_test.dart

Issue 1653603002: pkg/stack_trace: Use StackTrace.current (Closed) Base URL: https://github.com/dart-lang/stack_trace.git@master
Patch Set: nits Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/trace_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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() {
16 try {
17 throw '';
18 } catch (_, stackTrace) {
19 return stackTrace.toString();
20 }
21 }
22
23 StackTrace getStackTraceObject() {
24 try {
25 throw '';
26 } catch (_, stackTrace) {
27 return stackTrace;
28 }
29 }
30
31 Frame getCaller([int level]) { 15 Frame getCaller([int level]) {
32 if (level == null) return new Frame.caller(); 16 if (level == null) return new Frame.caller();
33 return new Frame.caller(level); 17 return new Frame.caller(level);
34 } 18 }
35 19
36 Frame nestedGetCaller(int level) => getCaller(level); 20 Frame nestedGetCaller(int level) => getCaller(level);
37 21
38 Trace getCurrentTrace([int level]) => new Trace.current(level); 22 Trace getCurrentTrace([int level]) => new Trace.current(level);
39 23
40 Trace nestedGetCurrentTrace(int level) => getCurrentTrace(level); 24 Trace nestedGetCurrentTrace(int level) => getCurrentTrace(level);
41 25
42 void main() { 26 void main() {
43 group('Trace', () { 27 group('Trace', () {
44 test('.parse parses a real stack trace correctly', () { 28 test('.parse parses a real stack trace correctly', () {
45 var string = getStackTraceString(); 29 var string = StackTrace.current.toString();
46 var trace = new Trace.parse(string); 30 var trace = new Trace.parse(string);
47 expect(path.url.basename(trace.frames.first.uri.path), 31 expect(path.url.basename(trace.frames.first.uri.path),
48 equals('vm_test.dart')); 32 equals('vm_test.dart'));
49 expect(trace.frames.first.member, equals('getStackTraceString')); 33 expect(trace.frames.first.member, equals('getStackTraceString'));
50 }); 34 });
51 35
52 test('converts from a native stack trace correctly', () { 36 test('converts from a native stack trace correctly', () {
53 var trace = new Trace.from(getStackTraceObject()); 37 var trace = new Trace.from(StackTrace.current);
54 expect(path.url.basename(trace.frames.first.uri.path), 38 expect(path.url.basename(trace.frames.first.uri.path),
55 equals('vm_test.dart')); 39 equals('vm_test.dart'));
56 expect(trace.frames.first.member, equals('getStackTraceObject')); 40 expect(trace.frames.first.member, equals('getStackTraceObject'));
57 }); 41 });
58 42
59 test('.from handles a stack overflow trace correctly', () { 43 test('.from handles a stack overflow trace correctly', () {
60 overflow() => overflow(); 44 overflow() => overflow();
61 45
62 var trace; 46 var trace;
63 try { 47 try {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 96
113 test('at level 2 returns the grandparent frame', () { 97 test('at level 2 returns the grandparent frame', () {
114 expect(nestedGetCaller(2).member, equals('main.<fn>.<fn>')); 98 expect(nestedGetCaller(2).member, equals('main.<fn>.<fn>'));
115 }); 99 });
116 100
117 test('throws an ArgumentError for negative levels', () { 101 test('throws an ArgumentError for negative levels', () {
118 expect(() => new Frame.caller(-1), throwsArgumentError); 102 expect(() => new Frame.caller(-1), throwsArgumentError);
119 }); 103 });
120 }); 104 });
121 } 105 }
OLDNEW
« no previous file with comments | « test/trace_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698