| 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 library frame_test; | 5 library frame_test; |
| 6 | 6 |
| 7 import 'package:path/path.dart' as path; | 7 import 'package:path/path.dart' as path; |
| 8 import 'package:stack_trace/stack_trace.dart'; | 8 import 'package:stack_trace/stack_trace.dart'; |
| 9 import 'package:test/test.dart'; | 9 import 'package:test/test.dart'; |
| 10 | 10 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 | 64 |
| 65 test('parses a folded frame correctly', () { | 65 test('parses a folded frame correctly', () { |
| 66 var frame = new Frame.parseVM('...'); | 66 var frame = new Frame.parseVM('...'); |
| 67 | 67 |
| 68 expect(frame.member, equals('...')); | 68 expect(frame.member, equals('...')); |
| 69 expect(frame.uri, equals(new Uri())); | 69 expect(frame.uri, equals(new Uri())); |
| 70 expect(frame.line, isNull); | 70 expect(frame.line, isNull); |
| 71 expect(frame.column, isNull); | 71 expect(frame.column, isNull); |
| 72 }); | 72 }); |
| 73 | 73 |
| 74 test('throws a FormatException for malformed frames', () { | 74 test('returns an UnparsedFrame for malformed frames', () { |
| 75 expect(() => new Frame.parseVM(''), throwsFormatException); | 75 expectIsUnparsed((text) => new Frame.parseV8(text), ''); |
| 76 expect(() => new Frame.parseVM('#1'), throwsFormatException); | 76 expectIsUnparsed((text) => new Frame.parseV8(text), '#1'); |
| 77 expect(() => new Frame.parseVM('#1 Foo'), throwsFormatException); | 77 expectIsUnparsed((text) => new Frame.parseV8(text), '#1 Foo'); |
| 78 expect(() => new Frame.parseVM('#1 (dart:async/future.dart:10:15)'), | 78 expectIsUnparsed((text) => new Frame.parseV8(text), |
| 79 throwsFormatException); | 79 '#1 (dart:async/future.dart:10:15)'); |
| 80 expect(() => new Frame.parseVM('Foo (dart:async/future.dart:10:15)'), | 80 expectIsUnparsed((text) => new Frame.parseV8(text), |
| 81 throwsFormatException); | 81 'Foo (dart:async/future.dart:10:15)'); |
| 82 }); | 82 }); |
| 83 }); | 83 }); |
| 84 | 84 |
| 85 group('.parseV8', () { | 85 group('.parseV8', () { |
| 86 test('parses a stack frame correctly', () { | 86 test('parses a stack frame correctly', () { |
| 87 var frame = new Frame.parseV8(" at VW.call\$0 " | 87 var frame = new Frame.parseV8(" at VW.call\$0 " |
| 88 "(http://pub.dartlang.org/stuff.dart.js:560:28)"); | 88 "(http://pub.dartlang.org/stuff.dart.js:560:28)"); |
| 89 expect(frame.uri, | 89 expect(frame.uri, |
| 90 equals(Uri.parse("http://pub.dartlang.org/stuff.dart.js"))); | 90 equals(Uri.parse("http://pub.dartlang.org/stuff.dart.js"))); |
| 91 expect(frame.line, equals(560)); | 91 expect(frame.line, equals(560)); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 | 212 |
| 213 test('converts "<anonymous>" to "<fn>"', () { | 213 test('converts "<anonymous>" to "<fn>"', () { |
| 214 String parsedMember(String member) => | 214 String parsedMember(String member) => |
| 215 new Frame.parseV8(' at $member (foo:0:0)').member; | 215 new Frame.parseV8(' at $member (foo:0:0)').member; |
| 216 | 216 |
| 217 expect(parsedMember('Foo.<anonymous>'), equals('Foo.<fn>')); | 217 expect(parsedMember('Foo.<anonymous>'), equals('Foo.<fn>')); |
| 218 expect(parsedMember('<anonymous>.<anonymous>.bar'), | 218 expect(parsedMember('<anonymous>.<anonymous>.bar'), |
| 219 equals('<fn>.<fn>.bar')); | 219 equals('<fn>.<fn>.bar')); |
| 220 }); | 220 }); |
| 221 | 221 |
| 222 test('throws a FormatException for malformed frames', () { | 222 test('returns an UnparsedFrame for malformed frames', () { |
| 223 expect(() => new Frame.parseV8(''), throwsFormatException); | 223 expectIsUnparsed((text) => new Frame.parseV8(text), ''); |
| 224 expect(() => new Frame.parseV8(' at'), throwsFormatException); | 224 expectIsUnparsed((text) => new Frame.parseV8(text), ' at'); |
| 225 expect(() => new Frame.parseV8(' at Foo'), throwsFormatException); | 225 expectIsUnparsed((text) => new Frame.parseV8(text), ' at Foo'); |
| 226 expect(() => new Frame.parseV8(' at Foo (dart:async/future.dart)'), | 226 expectIsUnparsed((text) => new Frame.parseV8(text), |
| 227 throwsFormatException); | 227 ' at Foo (dart:async/future.dart)'); |
| 228 expect(() => new Frame.parseV8(' at Foo (dart:async/future.dart:10)'), | 228 expectIsUnparsed((text) => new Frame.parseV8(text), |
| 229 throwsFormatException); | 229 ' at (dart:async/future.dart:10:15)'); |
| 230 expect(() => new Frame.parseV8(' at (dart:async/future.dart:10:15)'), | 230 expectIsUnparsed((text) => new Frame.parseV8(text), |
| 231 throwsFormatException); | 231 'Foo (dart:async/future.dart:10:15)'); |
| 232 expect(() => new Frame.parseV8('Foo (dart:async/future.dart:10:15)'), | 232 expectIsUnparsed((text) => new Frame.parseV8(text), |
| 233 throwsFormatException); | 233 ' at dart:async/future.dart'); |
| 234 expect(() => new Frame.parseV8(' at dart:async/future.dart'), | 234 expectIsUnparsed((text) => new Frame.parseV8(text), |
| 235 throwsFormatException); | 235 ' at dart:async/future.dart:10'); |
| 236 expect(() => new Frame.parseV8(' at dart:async/future.dart:10'), | 236 expectIsUnparsed((text) => new Frame.parseV8(text), |
| 237 throwsFormatException); | 237 'dart:async/future.dart:10:15'); |
| 238 expect(() => new Frame.parseV8('dart:async/future.dart:10:15'), | |
| 239 throwsFormatException); | |
| 240 }); | 238 }); |
| 241 }); | 239 }); |
| 242 | 240 |
| 243 group('.parseFirefox/.parseSafari', () { | 241 group('.parseFirefox/.parseSafari', () { |
| 244 test('parses a simple stack frame correctly', () { | 242 test('parses a simple stack frame correctly', () { |
| 245 var frame = new Frame.parseFirefox( | 243 var frame = new Frame.parseFirefox( |
| 246 ".VW.call\$0@http://pub.dartlang.org/stuff.dart.js:560"); | 244 ".VW.call\$0@http://pub.dartlang.org/stuff.dart.js:560"); |
| 247 expect(frame.uri, | 245 expect(frame.uri, |
| 248 equals(Uri.parse("http://pub.dartlang.org/stuff.dart.js"))); | 246 equals(Uri.parse("http://pub.dartlang.org/stuff.dart.js"))); |
| 249 expect(frame.line, equals(560)); | 247 expect(frame.line, equals(560)); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 var frame = new Frame.parseFirefox( | 367 var frame = new Frame.parseFirefox( |
| 370 '.convertDartClosureToJS/\$function</<@' | 368 '.convertDartClosureToJS/\$function</<@' |
| 371 'http://pub.dartlang.org/stuff.dart.js:560'); | 369 'http://pub.dartlang.org/stuff.dart.js:560'); |
| 372 expect(frame.uri, | 370 expect(frame.uri, |
| 373 equals(Uri.parse("http://pub.dartlang.org/stuff.dart.js"))); | 371 equals(Uri.parse("http://pub.dartlang.org/stuff.dart.js"))); |
| 374 expect(frame.line, equals(560)); | 372 expect(frame.line, equals(560)); |
| 375 expect(frame.column, isNull); | 373 expect(frame.column, isNull); |
| 376 expect(frame.member, equals("convertDartClosureToJS.<fn>.<fn>")); | 374 expect(frame.member, equals("convertDartClosureToJS.<fn>.<fn>")); |
| 377 }); | 375 }); |
| 378 | 376 |
| 379 test('throws a FormatException for malformed frames', () { | 377 test('returns an UnparsedFrame for malformed frames', () { |
| 380 expect(() => new Frame.parseFirefox(''), throwsFormatException); | 378 expectIsUnparsed((text) => new Frame.parseFirefox(text), ''); |
| 381 expect(() => new Frame.parseFirefox('.foo'), throwsFormatException); | 379 expectIsUnparsed((text) => new Frame.parseFirefox(text), '.foo'); |
| 382 expect(() => new Frame.parseFirefox('.foo@dart:async/future.dart'), | 380 expectIsUnparsed((text) => new Frame.parseFirefox(text), |
| 383 throwsFormatException); | 381 '.foo@dart:async/future.dart'); |
| 384 expect(() => new Frame.parseFirefox('.foo(@dart:async/future.dart:10'), | 382 expectIsUnparsed((text) => new Frame.parseFirefox(text), |
| 385 throwsFormatException); | 383 '.foo(@dart:async/future.dart:10'); |
| 386 expect(() => new Frame.parseFirefox('@dart:async/future.dart'), | 384 expectIsUnparsed((text) => new Frame.parseFirefox(text), |
| 387 throwsFormatException); | 385 '@dart:async/future.dart'); |
| 388 }); | 386 }); |
| 389 | 387 |
| 390 test('parses a simple stack frame correctly', () { | 388 test('parses a simple stack frame correctly', () { |
| 391 var frame = new Frame.parseFirefox( | 389 var frame = new Frame.parseFirefox( |
| 392 "foo\$bar@http://dartlang.org/foo/bar.dart:10:11"); | 390 "foo\$bar@http://dartlang.org/foo/bar.dart:10:11"); |
| 393 expect(frame.uri, equals(Uri.parse("http://dartlang.org/foo/bar.dart"))); | 391 expect(frame.uri, equals(Uri.parse("http://dartlang.org/foo/bar.dart"))); |
| 394 expect(frame.line, equals(10)); | 392 expect(frame.line, equals(10)); |
| 395 expect(frame.column, equals(11)); | 393 expect(frame.column, equals(11)); |
| 396 expect(frame.member, equals('foo\$bar')); | 394 expect(frame.member, equals('foo\$bar')); |
| 397 }); | 395 }); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 | 461 |
| 464 test('parses a stack frame with a relative path correctly', () { | 462 test('parses a stack frame with a relative path correctly', () { |
| 465 var frame = new Frame.parseFriendly("foo/bar.dart 10:11 Foo.<fn>.bar"); | 463 var frame = new Frame.parseFriendly("foo/bar.dart 10:11 Foo.<fn>.bar"); |
| 466 expect(frame.uri, equals( | 464 expect(frame.uri, equals( |
| 467 path.toUri(path.absolute(path.join('foo', 'bar.dart'))))); | 465 path.toUri(path.absolute(path.join('foo', 'bar.dart'))))); |
| 468 expect(frame.line, equals(10)); | 466 expect(frame.line, equals(10)); |
| 469 expect(frame.column, equals(11)); | 467 expect(frame.column, equals(11)); |
| 470 expect(frame.member, equals('Foo.<fn>.bar')); | 468 expect(frame.member, equals('Foo.<fn>.bar')); |
| 471 }); | 469 }); |
| 472 | 470 |
| 473 test('throws a FormatException for malformed frames', () { | 471 test('returns an UnparsedFrame for malformed frames', () { |
| 474 expect(() => new Frame.parseFriendly(''), throwsFormatException); | 472 expectIsUnparsed((text) => new Frame.parseFriendly(text), ''); |
| 475 expect(() => new Frame.parseFriendly('foo/bar.dart'), | 473 expectIsUnparsed((text) => new Frame.parseFriendly(text), 'foo/bar.dart'); |
| 476 throwsFormatException); | 474 expectIsUnparsed((text) => new Frame.parseFriendly(text), |
| 477 expect(() => new Frame.parseFriendly('foo/bar.dart 10:11'), | 475 'foo/bar.dart 10:11'); |
| 478 throwsFormatException); | |
| 479 }); | 476 }); |
| 480 }); | 477 }); |
| 481 | 478 |
| 482 test('only considers dart URIs to be core', () { | 479 test('only considers dart URIs to be core', () { |
| 483 bool isCore(String library) => | 480 bool isCore(String library) => |
| 484 new Frame.parseVM('#0 Foo ($library:0:0)').isCore; | 481 new Frame.parseVM('#0 Foo ($library:0:0)').isCore; |
| 485 | 482 |
| 486 expect(isCore('dart:core'), isTrue); | 483 expect(isCore('dart:core'), isTrue); |
| 487 expect(isCore('dart:async'), isTrue); | 484 expect(isCore('dart:async'), isTrue); |
| 488 expect(isCore('dart:core/uri.dart'), isTrue); | 485 expect(isCore('dart:core/uri.dart'), isTrue); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 equals('dart:core/uri.dart 5 in Foo')); | 552 equals('dart:core/uri.dart 5 in Foo')); |
| 556 }); | 553 }); |
| 557 | 554 |
| 558 test('prints relative paths as relative', () { | 555 test('prints relative paths as relative', () { |
| 559 var relative = path.normalize('relative/path/to/foo.dart'); | 556 var relative = path.normalize('relative/path/to/foo.dart'); |
| 560 expect(new Frame.parseFriendly('$relative 5:10 Foo').toString(), | 557 expect(new Frame.parseFriendly('$relative 5:10 Foo').toString(), |
| 561 equals('$relative 5:10 in Foo')); | 558 equals('$relative 5:10 in Foo')); |
| 562 }); | 559 }); |
| 563 }); | 560 }); |
| 564 } | 561 } |
| 562 |
| 563 void expectIsUnparsed(Frame constructor(String text), String text) { |
| 564 var frame = constructor(text); |
| 565 expect(frame, new isInstanceOf<UnparsedFrame>()); |
| 566 expect(frame.toString(), equals(text)); |
| 567 } |
| OLD | NEW |