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

Side by Side Diff: pkg/stack_trace/test/trace_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
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 group('.parse', () {
35 var trace = new Trace.parse(''' 33 test('.parse parses a VM stack trace correctly', () {
36 #0 Foo._bar (file:///home/nweiz/code/stuff.dart:42:21) 34 var trace = new Trace.parse(
37 #1 zip.<anonymous closure>.zap (dart:async/future.dart:0:2) 35 '#0 Foo._bar (file:///home/nweiz/code/stuff.dart:42:21)\n'
38 #2 zip.<anonymous closure>.zap (http://pub.dartlang.org/thing.dart:1:100) 36 '#1 zip.<anonymous closure>.zap (dart:async/future.dart:0:2)\n'
39 '''); 37 '#2 zip.<anonymous closure>.zap (http://pub.dartlang.org/thing.'
38 'dart:1:100)');
40 39
41 expect(trace.frames[0].uri, 40 expect(trace.frames[0].uri,
42 equals(Uri.parse("file:///home/nweiz/code/stuff.dart"))); 41 equals(Uri.parse("file:///home/nweiz/code/stuff.dart")));
43 expect(trace.frames[1].uri, equals(Uri.parse("dart:async/future.dart"))); 42 expect(trace.frames[1].uri, equals(Uri.parse("dart:async/future.dart")));
44 expect(trace.frames[2].uri, 43 expect(trace.frames[2].uri,
45 equals(Uri.parse("http://pub.dartlang.org/thing.dart"))); 44 equals(Uri.parse("http://pub.dartlang.org/thing.dart")));
46 });
47
48 test('parses a real stack trace correctly', () {
49 var trace = new Trace.parse(getStackTraceString());
50 // TODO(nweiz): use URL-style paths when such a thing exists.
51 var builder = new path.Builder(style: path.Style.posix);
52 expect(builder.basename(trace.frames.first.uri.path),
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 }); 45 });
71 46
72 test('at level 0 returns a trace starting at the current frame', () { 47 test('parses a V8 stack trace correctly', () {
73 var trace = new Trace.current(0); 48 var trace = new Trace.parse(
74 expect(trace.frames.first.member, equals('main.<fn>.<fn>')); 49 'Error\n'
50 ' at Foo._bar (http://pub.dartlang.org/stuff.js:42:21)\n'
51 ' at http://pub.dartlang.org/stuff.js:0:2\n'
52 ' at zip.<anonymous>.zap '
53 '(http://pub.dartlang.org/thing.js:1:100)');
54
55 expect(trace.frames[0].uri,
56 equals(Uri.parse("http://pub.dartlang.org/stuff.js")));
57 expect(trace.frames[1].uri,
58 equals(Uri.parse("http://pub.dartlang.org/stuff.js")));
59 expect(trace.frames[2].uri,
60 equals(Uri.parse("http://pub.dartlang.org/thing.js")));
75 }); 61 });
76 62
77 test('at level 1 returns a trace starting at the parent frame', () { 63 test('parses a Firefox stack trace correctly', () {
78 var trace = getCurrentTrace(1); 64 var trace = new Trace.parse(
79 expect(trace.frames.first.member, equals('main.<fn>.<fn>')); 65 'Foo._bar@http://pub.dartlang.org/stuff.js:42\n'
80 }); 66 'zip/<@http://pub.dartlang.org/stuff.js:0\n'
67 'zip.zap(12, "@)()/<")@http://pub.dartlang.org/thing.js:1');
81 68
82 test('at level 2 returns a trace starting at the grandparent frame', () { 69 expect(trace.frames[0].uri,
83 var trace = nestedGetCurrentTrace(2); 70 equals(Uri.parse("http://pub.dartlang.org/stuff.js")));
84 expect(trace.frames.first.member, equals('main.<fn>.<fn>')); 71 expect(trace.frames[1].uri,
85 }); 72 equals(Uri.parse("http://pub.dartlang.org/stuff.js")));
86 73 expect(trace.frames[2].uri,
87 test('throws an ArgumentError for negative levels', () { 74 equals(Uri.parse("http://pub.dartlang.org/thing.js")));
88 expect(() => new Trace.current(-1), throwsArgumentError);
89 }); 75 });
90 }); 76 });
91 77
92 test('.toString() nicely formats the stack trace', () { 78 test('.toString() nicely formats the stack trace', () {
93 var trace = new Trace.parse(''' 79 var trace = new Trace.parse('''
94 #0 Foo._bar (foo/bar.dart:42:21) 80 #0 Foo._bar (foo/bar.dart:42:21)
95 #1 zip.<anonymous closure>.zap (dart:async/future.dart:0:2) 81 #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) 82 #2 zip.<anonymous closure>.zap (http://pub.dartlang.org/thing.dart:1:100)
97 '''); 83 ''');
98 84
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 129
144 var folded = trace.foldFrames((frame) => frame.member.startsWith('foo')); 130 var folded = trace.foldFrames((frame) => frame.member.startsWith('foo'));
145 expect(folded.toString(), equals(''' 131 expect(folded.toString(), equals('''
146 foo.dart 42:21 notFoo 132 foo.dart 42:21 notFoo
147 foo.dart 1:100 fooBottom 133 foo.dart 1:100 fooBottom
148 bar.dart 10:20 alsoNotFoo 134 bar.dart 10:20 alsoNotFoo
149 dart:async-patch/future.dart 9:11 fooBottom 135 dart:async-patch/future.dart 9:11 fooBottom
150 ''')); 136 '''));
151 }); 137 });
152 } 138 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698