| 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 trace_test; | 5 library trace_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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 new Frame(Uri.parse('http://dartlang.org/foo.dart'), null, null, 'bar'), | 286 new Frame(Uri.parse('http://dartlang.org/foo.dart'), null, null, 'bar'), |
| 287 new Frame(Uri.parse('dart:async'), 15, null, 'baz'), | 287 new Frame(Uri.parse('dart:async'), 15, null, 'baz'), |
| 288 ]); | 288 ]); |
| 289 | 289 |
| 290 expect(trace.vmTrace.toString(), equals( | 290 expect(trace.vmTrace.toString(), equals( |
| 291 '#1 Foo.<anonymous closure> ($uri:10:20)\n' | 291 '#1 Foo.<anonymous closure> ($uri:10:20)\n' |
| 292 '#2 bar (http://dartlang.org/foo.dart:0:0)\n' | 292 '#2 bar (http://dartlang.org/foo.dart:0:0)\n' |
| 293 '#3 baz (dart:async:15:0)\n')); | 293 '#3 baz (dart:async:15:0)\n')); |
| 294 }); | 294 }); |
| 295 | 295 |
| 296 test('.terse folds core frames together bottom-up', () { | 296 group("folding", () { |
| 297 var trace = new Trace.parse(''' | 297 test('.terse folds core frames together bottom-up', () { |
| 298 var trace = new Trace.parse(''' |
| 298 #1 top (dart:async/future.dart:0:2) | 299 #1 top (dart:async/future.dart:0:2) |
| 299 #2 bottom (dart:core/uri.dart:1:100) | 300 #2 bottom (dart:core/uri.dart:1:100) |
| 300 #0 notCore (foo.dart:42:21) | 301 #0 notCore (foo.dart:42:21) |
| 301 #3 top (dart:io:5:10) | 302 #3 top (dart:io:5:10) |
| 302 #4 bottom (dart:async-patch/future.dart:9:11) | 303 #4 bottom (dart:async-patch/future.dart:9:11) |
| 303 #5 alsoNotCore (bar.dart:10:20) | 304 #5 alsoNotCore (bar.dart:10:20) |
| 304 '''); | 305 '''); |
| 305 | 306 |
| 306 expect(trace.terse.toString(), equals(''' | 307 expect(trace.terse.toString(), equals(''' |
| 307 dart:core bottom | 308 dart:core bottom |
| 308 foo.dart 42:21 notCore | 309 foo.dart 42:21 notCore |
| 309 dart:async bottom | 310 dart:async bottom |
| 310 bar.dart 10:20 alsoNotCore | 311 bar.dart 10:20 alsoNotCore |
| 311 ''')); | 312 ''')); |
| 312 }); | 313 }); |
| 313 | 314 |
| 314 test('.terse folds empty async frames', () { | 315 test('.terse folds empty async frames', () { |
| 315 var trace = new Trace.parse(''' | 316 var trace = new Trace.parse(''' |
| 316 #0 top (dart:async/future.dart:0:2) | 317 #0 top (dart:async/future.dart:0:2) |
| 317 #1 empty.<<anonymous closure>_async_body> (bar.dart) | 318 #1 empty.<<anonymous closure>_async_body> (bar.dart) |
| 318 #2 bottom (dart:async-patch/future.dart:9:11) | 319 #2 bottom (dart:async-patch/future.dart:9:11) |
| 319 #3 notCore (foo.dart:42:21) | 320 #3 notCore (foo.dart:42:21) |
| 320 '''); | 321 '''); |
| 321 | 322 |
| 322 expect(trace.terse.toString(), equals(''' | 323 expect(trace.terse.toString(), equals(''' |
| 323 dart:async bottom | 324 dart:async bottom |
| 324 foo.dart 42:21 notCore | 325 foo.dart 42:21 notCore |
| 325 ''')); | 326 ''')); |
| 326 }); | 327 }); |
| 327 | 328 |
| 328 test('.terse removes the bottom-most async frame', () { | 329 test('.terse removes the bottom-most async frame', () { |
| 329 var trace = new Trace.parse(''' | 330 var trace = new Trace.parse(''' |
| 330 #0 notCore (foo.dart:42:21) | 331 #0 notCore (foo.dart:42:21) |
| 331 #1 top (dart:async/future.dart:0:2) | 332 #1 top (dart:async/future.dart:0:2) |
| 332 #2 bottom (dart:core/uri.dart:1:100) | 333 #2 bottom (dart:core/uri.dart:1:100) |
| 333 #3 top (dart:io:5:10) | 334 #3 top (dart:io:5:10) |
| 334 #4 bottom (dart:async-patch/future.dart:9:11) | 335 #4 bottom (dart:async-patch/future.dart:9:11) |
| 335 '''); | 336 '''); |
| 336 | 337 |
| 337 expect(trace.terse.toString(), equals(''' | 338 expect(trace.terse.toString(), equals(''' |
| 338 foo.dart 42:21 notCore | 339 foo.dart 42:21 notCore |
| 339 ''')); | 340 ''')); |
| 340 }); | 341 }); |
| 341 | 342 |
| 342 test(".terse won't make a trace empty", () { | 343 test(".terse won't make a trace empty", () { |
| 343 var trace = new Trace.parse(''' | 344 var trace = new Trace.parse(''' |
| 344 #1 top (dart:async/future.dart:0:2) | 345 #1 top (dart:async/future.dart:0:2) |
| 345 #2 bottom (dart:core/uri.dart:1:100) | 346 #2 bottom (dart:core/uri.dart:1:100) |
| 346 '''); | 347 '''); |
| 347 | 348 |
| 348 expect(trace.terse.toString(), equals(''' | 349 expect(trace.terse.toString(), equals(''' |
| 349 dart:core bottom | 350 dart:core bottom |
| 350 ''')); | 351 ''')); |
| 351 }); | 352 }); |
| 352 | 353 |
| 353 test(".terse won't panic on an empty trace", () { | 354 test(".terse won't panic on an empty trace", () { |
| 354 var trace = new Trace.parse(''' | 355 expect(Trace.parse("").terse.toString(), equals("")); |
| 355 '''); | 356 }); |
| 356 | 357 |
| 357 expect(trace.terse.toString(), equals(''' | 358 test('.foldFrames folds frames together bottom-up', () { |
| 358 ''')); | 359 var trace = new Trace.parse(''' |
| 359 }); | |
| 360 | |
| 361 test('.foldFrames folds frames together bottom-up', () { | |
| 362 var trace = new Trace.parse(''' | |
| 363 #0 notFoo (foo.dart:42:21) | 360 #0 notFoo (foo.dart:42:21) |
| 364 #1 fooTop (bar.dart:0:2) | 361 #1 fooTop (bar.dart:0:2) |
| 365 #2 fooBottom (foo.dart:1:100) | 362 #2 fooBottom (foo.dart:1:100) |
| 366 #3 alsoNotFoo (bar.dart:10:20) | 363 #3 alsoNotFoo (bar.dart:10:20) |
| 367 #4 fooTop (dart:io/socket.dart:5:10) | 364 #4 fooTop (dart:io/socket.dart:5:10) |
| 368 #5 fooBottom (dart:async-patch/future.dart:9:11) | 365 #5 fooBottom (dart:async-patch/future.dart:9:11) |
| 369 '''); | 366 '''); |
| 370 | 367 |
| 371 var folded = trace.foldFrames((frame) => frame.member.startsWith('foo')); | 368 var folded = trace.foldFrames((frame) => frame.member.startsWith('foo')); |
| 372 expect(folded.toString(), equals(''' | 369 expect(folded.toString(), equals(''' |
| 373 foo.dart 42:21 notFoo | 370 foo.dart 42:21 notFoo |
| 374 foo.dart 1:100 fooBottom | 371 foo.dart 1:100 fooBottom |
| 375 bar.dart 10:20 alsoNotFoo | 372 bar.dart 10:20 alsoNotFoo |
| 376 dart:async-patch/future.dart 9:11 fooBottom | 373 dart:async-patch/future.dart 9:11 fooBottom |
| 377 ''')); | 374 ''')); |
| 378 }); | 375 }); |
| 379 | 376 |
| 380 test('.foldFrames with terse: true folds core frames as well', () { | 377 test('.foldFrames with terse: true folds core frames as well', () { |
| 381 var trace = new Trace.parse(''' | 378 var trace = new Trace.parse(''' |
| 382 #0 notFoo (foo.dart:42:21) | 379 #0 notFoo (foo.dart:42:21) |
| 383 #1 fooTop (bar.dart:0:2) | 380 #1 fooTop (bar.dart:0:2) |
| 384 #2 coreBottom (dart:async/future.dart:0:2) | 381 #2 coreBottom (dart:async/future.dart:0:2) |
| 385 #3 alsoNotFoo (bar.dart:10:20) | 382 #3 alsoNotFoo (bar.dart:10:20) |
| 386 #4 fooTop (foo.dart:9:11) | 383 #4 fooTop (foo.dart:9:11) |
| 387 #5 coreBottom (dart:async-patch/future.dart:9:11) | 384 #5 coreBottom (dart:async-patch/future.dart:9:11) |
| 388 '''); | 385 '''); |
| 389 | 386 |
| 390 var folded = trace.foldFrames((frame) => frame.member.startsWith('foo'), | 387 var folded = trace.foldFrames((frame) => frame.member.startsWith('foo'), |
| 391 terse: true); | 388 terse: true); |
| 392 expect(folded.toString(), equals(''' | 389 expect(folded.toString(), equals(''' |
| 393 foo.dart 42:21 notFoo | 390 foo.dart 42:21 notFoo |
| 394 dart:async coreBottom | 391 dart:async coreBottom |
| 395 bar.dart 10:20 alsoNotFoo | 392 bar.dart 10:20 alsoNotFoo |
| 396 ''')); | 393 ''')); |
| 397 }); | 394 }); |
| 398 | 395 |
| 399 test('.foldFrames with terse: true shortens folded frames', () { | 396 test('.foldFrames with terse: true shortens folded frames', () { |
| 400 var trace = new Trace.parse(''' | 397 var trace = new Trace.parse(''' |
| 401 #0 notFoo (foo.dart:42:21) | 398 #0 notFoo (foo.dart:42:21) |
| 402 #1 fooTop (bar.dart:0:2) | 399 #1 fooTop (bar.dart:0:2) |
| 403 #2 fooBottom (package:foo/bar.dart:0:2) | 400 #2 fooBottom (package:foo/bar.dart:0:2) |
| 404 #3 alsoNotFoo (bar.dart:10:20) | 401 #3 alsoNotFoo (bar.dart:10:20) |
| 405 #4 fooTop (foo.dart:9:11) | 402 #4 fooTop (foo.dart:9:11) |
| 406 #5 fooBottom (foo/bar.dart:9:11) | 403 #5 fooBottom (foo/bar.dart:9:11) |
| 407 '''); | 404 '''); |
| 408 | 405 |
| 409 var folded = trace.foldFrames((frame) => frame.member.startsWith('foo'), | 406 var folded = trace.foldFrames((frame) => frame.member.startsWith('foo'), |
| 410 terse: true); | 407 terse: true); |
| 411 expect(folded.toString(), equals(''' | 408 expect(folded.toString(), equals(''' |
| 412 foo.dart 42:21 notFoo | 409 foo.dart 42:21 notFoo |
| 413 package:foo fooBottom | 410 package:foo fooBottom |
| 414 bar.dart 10:20 alsoNotFoo | 411 bar.dart 10:20 alsoNotFoo |
| 415 foo fooBottom | 412 foo fooBottom |
| 416 ''')); | 413 ''')); |
| 414 }); |
| 415 |
| 416 test('.foldFrames will never fold unparsed frames', () { |
| 417 var trace = new Trace.parse(r''' |
| 418 .g"cs$#:b";a#>sw{*{ul$"$xqwr`p |
| 419 %+j-?uppx<([j@#nu{{>*+$%x-={`{ |
| 420 !e($b{nj)zs?cgr%!;bmw.+$j+pfj~ |
| 421 '''); |
| 422 |
| 423 expect(trace.foldFrames((frame) => true).toString(), equals(r''' |
| 424 .g"cs$#:b";a#>sw{*{ul$"$xqwr`p |
| 425 %+j-?uppx<([j@#nu{{>*+$%x-={`{ |
| 426 !e($b{nj)zs?cgr%!;bmw.+$j+pfj~ |
| 427 ''')); |
| 428 }); |
| 417 }); | 429 }); |
| 418 } | 430 } |
| OLD | NEW |