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

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

Issue 18167002: 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 the browser tests work. 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
« no previous file with comments | « pkg/stack_trace/test/frame_test.dart ('k') | pkg/stack_trace/test/vm_test.dart » ('j') | 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 library trace_test; 5 library trace_test;
6 6
7 import 'dart:io';
8
9 import 'package:pathos/path.dart' as path; 7 import 'package:pathos/path.dart' as path;
10 import 'package:stack_trace/stack_trace.dart'; 8 import 'package:stack_trace/stack_trace.dart';
11 import 'package:unittest/unittest.dart'; 9 import 'package:unittest/unittest.dart';
12 10
13 String getStackTraceString() { 11 String getStackTraceString() {
14 try { 12 try {
15 throw ''; 13 throw '';
16 } catch (_, stackTrace) { 14 } catch (_, stackTrace) {
17 return stackTrace.toString(); 15 return stackTrace.toString();
18 } 16 }
19 } 17 }
20 18
21 StackTrace getStackTraceObject() { 19 StackTrace getStackTraceObject() {
22 try { 20 try {
23 throw ''; 21 throw '';
24 } catch (_, stackTrace) { 22 } catch (_, stackTrace) {
25 return stackTrace; 23 return stackTrace;
26 } 24 }
27 } 25 }
28 26
29 Trace getCurrentTrace([int level]) => new Trace.current(level); 27 Trace getCurrentTrace([int level]) => new Trace.current(level);
30 28
31 Trace nestedGetCurrentTrace(int level) => getCurrentTrace(level); 29 Trace nestedGetCurrentTrace(int level) => getCurrentTrace(level);
32 30
33 void main() { 31 void main() {
34 test('parses a stack trace correctly', () { 32 // This just shouldn't crash.
35 var trace = new Trace.parse(''' 33 test('a native stack trace is parseable', () => new Trace.current());
36 #0 Foo._bar (file:///home/nweiz/code/stuff.dart:42:21)
37 #1 zip.<anonymous closure>.zap (dart:async/future.dart:0:2)
38 #2 zip.<anonymous closure>.zap (http://pub.dartlang.org/thing.dart:1:100)
39 ''');
40 34
41 expect(trace.frames[0].uri, 35 group('.parse', () {
42 equals(Uri.parse("file:///home/nweiz/code/stuff.dart"))); 36 test('.parse parses a VM stack trace correctly', () {
43 expect(trace.frames[1].uri, equals(Uri.parse("dart:async/future.dart"))); 37 var trace = new Trace.parse(
44 expect(trace.frames[2].uri, 38 '#0 Foo._bar (file:///home/nweiz/code/stuff.dart:42:21)\n'
45 equals(Uri.parse("http://pub.dartlang.org/thing.dart"))); 39 '#1 zip.<anonymous closure>.zap (dart:async/future.dart:0:2)\n'
46 }); 40 '#2 zip.<anonymous closure>.zap (http://pub.dartlang.org/thing.'
41 'dart:1:100)');
47 42
48 test('parses a real stack trace correctly', () { 43 expect(trace.frames[0].uri,
49 var trace = new Trace.parse(getStackTraceString()); 44 equals(Uri.parse("file:///home/nweiz/code/stuff.dart")));
50 // TODO(nweiz): use URL-style paths when such a thing exists. 45 expect(trace.frames[1].uri, equals(Uri.parse("dart:async/future.dart")));
51 var builder = new path.Builder(style: path.Style.posix); 46 expect(trace.frames[2].uri,
52 expect(builder.basename(trace.frames.first.uri.path), 47 equals(Uri.parse("http://pub.dartlang.org/thing.dart")));
53 equals('trace_test.dart'));
54 expect(trace.frames.first.member, equals('getStackTraceString'));
55 });
56
57 test('converts from a native stack trace correctly', () {
58 var trace = new Trace.from(getStackTraceObject());
59 // TODO(nweiz): use URL-style paths when such a thing exists.
60 var builder = new path.Builder(style: path.Style.posix);
61 expect(builder.basename(trace.frames.first.uri.path),
62 equals('trace_test.dart'));
63 expect(trace.frames.first.member, equals('getStackTraceObject'));
64 });
65
66 group('.current()', () {
67 test('with no argument returns a trace starting at the current frame', () {
68 var trace = new Trace.current();
69 expect(trace.frames.first.member, equals('main.<fn>.<fn>'));
70 }); 48 });
71 49
72 test('at level 0 returns a trace starting at the current frame', () { 50 test('parses a V8 stack trace correctly', () {
73 var trace = new Trace.current(0); 51 var trace = new Trace.parse(
74 expect(trace.frames.first.member, equals('main.<fn>.<fn>')); 52 'Error\n'
53 ' at Foo._bar (http://pub.dartlang.org/stuff.js:42:21)\n'
54 ' at http://pub.dartlang.org/stuff.js:0:2\n'
55 ' at zip.<anonymous>.zap '
56 '(http://pub.dartlang.org/thing.js:1:100)');
57
58 expect(trace.frames[0].uri,
59 equals(Uri.parse("http://pub.dartlang.org/stuff.js")));
60 expect(trace.frames[1].uri,
61 equals(Uri.parse("http://pub.dartlang.org/stuff.js")));
62 expect(trace.frames[2].uri,
63 equals(Uri.parse("http://pub.dartlang.org/thing.js")));
75 }); 64 });
76 65
77 test('at level 1 returns a trace starting at the parent frame', () { 66 test('parses a Firefox stack trace correctly', () {
78 var trace = getCurrentTrace(1); 67 var trace = new Trace.parse(
79 expect(trace.frames.first.member, equals('main.<fn>.<fn>')); 68 'Foo._bar@http://pub.dartlang.org/stuff.js:42\n'
69 'zip/<@http://pub.dartlang.org/stuff.js:0\n'
70 'zip.zap(12, "@)()/<")@http://pub.dartlang.org/thing.js:1');
71
72 expect(trace.frames[0].uri,
73 equals(Uri.parse("http://pub.dartlang.org/stuff.js")));
74 expect(trace.frames[1].uri,
75 equals(Uri.parse("http://pub.dartlang.org/stuff.js")));
76 expect(trace.frames[2].uri,
77 equals(Uri.parse("http://pub.dartlang.org/thing.js")));
78
79 trace = new Trace.parse(
80 'zip/<@http://pub.dartlang.org/stuff.js:0\n'
81 'Foo._bar@http://pub.dartlang.org/stuff.js:42\n'
82 'zip.zap(12, "@)()/<")@http://pub.dartlang.org/thing.js:1');
83
84 expect(trace.frames[0].uri,
85 equals(Uri.parse("http://pub.dartlang.org/stuff.js")));
86 expect(trace.frames[1].uri,
87 equals(Uri.parse("http://pub.dartlang.org/stuff.js")));
88 expect(trace.frames[2].uri,
89 equals(Uri.parse("http://pub.dartlang.org/thing.js")));
90
91 trace = new Trace.parse(
92 'zip.zap(12, "@)()/<")@http://pub.dartlang.org/thing.js:1\n'
93 'zip/<@http://pub.dartlang.org/stuff.js:0\n'
94 'Foo._bar@http://pub.dartlang.org/stuff.js:42');
95
96 expect(trace.frames[0].uri,
97 equals(Uri.parse("http://pub.dartlang.org/thing.js")));
98 expect(trace.frames[1].uri,
99 equals(Uri.parse("http://pub.dartlang.org/stuff.js")));
100 expect(trace.frames[2].uri,
101 equals(Uri.parse("http://pub.dartlang.org/stuff.js")));
80 }); 102 });
81 103
82 test('at level 2 returns a trace starting at the grandparent frame', () { 104 test('parses an empty string correctly', () {
83 var trace = nestedGetCurrentTrace(2); 105 expect(new Trace.parse('').frames, isEmpty);
84 expect(trace.frames.first.member, equals('main.<fn>.<fn>'));
85 });
86
87 test('throws an ArgumentError for negative levels', () {
88 expect(() => new Trace.current(-1), throwsArgumentError);
89 }); 106 });
90 }); 107 });
91 108
92 test('.toString() nicely formats the stack trace', () { 109 test('.toString() nicely formats the stack trace', () {
93 var trace = new Trace.parse(''' 110 var trace = new Trace.parse('''
94 #0 Foo._bar (foo/bar.dart:42:21) 111 #0 Foo._bar (foo/bar.dart:42:21)
95 #1 zip.<anonymous closure>.zap (dart:async/future.dart:0:2) 112 #1 zip.<anonymous closure>.zap (dart:async/future.dart:0:2)
96 #2 zip.<anonymous closure>.zap (http://pub.dartlang.org/thing.dart:1:100) 113 #2 zip.<anonymous closure>.zap (http://pub.dartlang.org/thing.dart:1:100)
97 '''); 114 ''');
98 115
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 160
144 var folded = trace.foldFrames((frame) => frame.member.startsWith('foo')); 161 var folded = trace.foldFrames((frame) => frame.member.startsWith('foo'));
145 expect(folded.toString(), equals(''' 162 expect(folded.toString(), equals('''
146 foo.dart 42:21 notFoo 163 foo.dart 42:21 notFoo
147 foo.dart 1:100 fooBottom 164 foo.dart 1:100 fooBottom
148 bar.dart 10:20 alsoNotFoo 165 bar.dart 10:20 alsoNotFoo
149 dart:async-patch/future.dart 9:11 fooBottom 166 dart:async-patch/future.dart 9:11 fooBottom
150 ''')); 167 '''));
151 }); 168 });
152 } 169 }
OLDNEW
« no previous file with comments | « pkg/stack_trace/test/frame_test.dart ('k') | pkg/stack_trace/test/vm_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698