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

Side by Side Diff: pkg/stack_trace/test/dartium_test.dart

Issue 17765004: Add support for V8 and Firefox stack traces in pkg/stack_trace. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Make tests run on the browser bots. Created 7 years, 5 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 /// This file tests stack_trace's ability to parse live stack traces. It's a
6 /// dual of vm_test.dart, since method names can differ somewhat from platform
7 /// to platform. No similar file exists for dart2js since the specific method
8 /// names there are implementation details.
9
10 import 'package:pathos/path.dart' as path;
11 import 'package:stack_trace/stack_trace.dart';
12 import 'package:unittest/unittest.dart';
13
14 String getStackTraceString() {
15 try {
16 throw '';
17 } catch (_, stackTrace) {
18 return stackTrace.toString();
19 }
20 }
21
22 StackTrace getStackTraceObject() {
23 try {
24 throw '';
25 } catch (_, stackTrace) {
26 return stackTrace;
27 }
28 }
29
30 Frame getCaller([int level]) {
31 if (level == null) return new Frame.caller();
32 return new Frame.caller(level);
33 }
34
35 Frame nestedGetCaller(int level) => getCaller(level);
36
37 Trace getCurrentTrace([int level]) => new Trace.current(level);
38
39 Trace nestedGetCurrentTrace(int level) => getCurrentTrace(level);
40
41 void main() {
42 group('Trace', () {
43 test('.parse parses a real stack trace correctly', () {
44 var string = getStackTraceString();
45 var trace = new Trace.parse(string);
46 var builder = new path.Builder(style: path.Style.url);
47 expect(builder.basename(trace.frames.first.uri.path),
48 equals('dartium_test.dart'));
49 expect(trace.frames.first.member, equals('getStackTraceString'));
50 });
51
52 test('converts from a native stack trace correctly', () {
53 var trace = new Trace.from(getStackTraceObject());
54 var builder = new path.Builder(style: path.Style.url);
55 expect(builder.basename(trace.frames.first.uri.path),
56 equals('dartium_test.dart'));
57 expect(trace.frames.first.member, equals('getStackTraceObject'));
58 });
59
60 group('.current()', () {
61 test('with no argument returns a trace starting at the current frame', () {
Bob Nystrom 2013/06/26 17:01:05 Long line.
nweiz 2013/06/26 20:08:01 Done.
62 var trace = new Trace.current();
63 expect(trace.frames.first.member, equals('main.main.<fn>.<fn>.<fn>'));
64 });
65
66 test('at level 0 returns a trace starting at the current frame', () {
67 var trace = new Trace.current(0);
68 expect(trace.frames.first.member, equals('main.main.<fn>.<fn>.<fn>'));
69 });
70
71 test('at level 1 returns a trace starting at the parent frame', () {
72 var trace = getCurrentTrace(1);
73 expect(trace.frames.first.member, equals('main.main.<fn>.<fn>.<fn>'));
74 });
75
76 test('at level 2 returns a trace starting at the grandparent frame', () {
77 var trace = nestedGetCurrentTrace(2);
78 expect(trace.frames.first.member, equals('main.main.<fn>.<fn>.<fn>'));
79 });
80
81 test('throws an ArgumentError for negative levels', () {
82 expect(() => new Trace.current(-1), throwsArgumentError);
83 });
84 });
85 });
86
87 group('Frame.caller()', () {
88 test('with no argument returns the parent frame', () {
89 expect(getCaller().member, equals('main.main.<fn>.<fn>'));
90 });
91
92 test('at level 0 returns the current frame', () {
93 expect(getCaller(0).member, equals('getCaller'));
94 });
95
96 test('at level 1 returns the current frame', () {
97 expect(getCaller(1).member, equals('main.main.<fn>.<fn>'));
98 });
99
100 test('at level 2 returns the grandparent frame', () {
101 expect(nestedGetCaller(2).member, equals('main.main.<fn>.<fn>'));
102 });
103
104 test('throws an ArgumentError for negative levels', () {
105 expect(() => new Frame.caller(-1), throwsArgumentError);
106 });
107 });
108 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698