OLD | NEW |
(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 library frame_test; |
| 6 |
| 7 import 'package:path/path.dart' as path; |
| 8 import 'package:stack_trace/stack_trace.dart'; |
| 9 import 'package:test/test.dart'; |
| 10 |
| 11 void main() { |
| 12 group('.parseVM', () { |
| 13 test('parses a stack frame with column correctly', () { |
| 14 var frame = new Frame.parseVM("#1 Foo._bar " |
| 15 "(file:///home/nweiz/code/stuff.dart:42:21)"); |
| 16 expect(frame.uri, |
| 17 equals(Uri.parse("file:///home/nweiz/code/stuff.dart"))); |
| 18 expect(frame.line, equals(42)); |
| 19 expect(frame.column, equals(21)); |
| 20 expect(frame.member, equals('Foo._bar')); |
| 21 }); |
| 22 |
| 23 test('parses a stack frame without column correctly', () { |
| 24 var frame = new Frame.parseVM("#1 Foo._bar " |
| 25 "(file:///home/nweiz/code/stuff.dart:24)"); |
| 26 expect(frame.uri, |
| 27 equals(Uri.parse("file:///home/nweiz/code/stuff.dart"))); |
| 28 expect(frame.line, equals(24)); |
| 29 expect(frame.column, null); |
| 30 expect(frame.member, equals('Foo._bar')); |
| 31 }); |
| 32 |
| 33 // This can happen with async stack traces. See issue 22009. |
| 34 test('parses a stack frame without line or column correctly', () { |
| 35 var frame = new Frame.parseVM("#1 Foo._bar " |
| 36 "(file:///home/nweiz/code/stuff.dart)"); |
| 37 expect(frame.uri, |
| 38 equals(Uri.parse("file:///home/nweiz/code/stuff.dart"))); |
| 39 expect(frame.line, isNull); |
| 40 expect(frame.column, isNull); |
| 41 expect(frame.member, equals('Foo._bar')); |
| 42 }); |
| 43 |
| 44 test('converts "<anonymous closure>" to "<fn>"', () { |
| 45 String parsedMember(String member) => |
| 46 new Frame.parseVM('#0 $member (foo:0:0)').member; |
| 47 |
| 48 expect(parsedMember('Foo.<anonymous closure>'), equals('Foo.<fn>')); |
| 49 expect(parsedMember('<anonymous closure>.<anonymous closure>.bar'), |
| 50 equals('<fn>.<fn>.bar')); |
| 51 }); |
| 52 |
| 53 test('converts "<<anonymous closure>_async_body>" to "<async>"', () { |
| 54 var frame = new Frame.parseVM( |
| 55 '#0 Foo.<<anonymous closure>_async_body> (foo:0:0)'); |
| 56 expect(frame.member, equals('Foo.<async>')); |
| 57 }); |
| 58 |
| 59 test('converts "<function_name_async_body>" to "<async>"', () { |
| 60 var frame = new Frame.parseVM( |
| 61 '#0 Foo.<function_name_async_body> (foo:0:0)'); |
| 62 expect(frame.member, equals('Foo.<async>')); |
| 63 }); |
| 64 |
| 65 test('parses a folded frame correctly', () { |
| 66 var frame = new Frame.parseVM('...'); |
| 67 |
| 68 expect(frame.member, equals('...')); |
| 69 expect(frame.uri, equals(new Uri())); |
| 70 expect(frame.line, isNull); |
| 71 expect(frame.column, isNull); |
| 72 }); |
| 73 |
| 74 test('returns an UnparsedFrame for malformed frames', () { |
| 75 expectIsUnparsed((text) => new Frame.parseV8(text), ''); |
| 76 expectIsUnparsed((text) => new Frame.parseV8(text), '#1'); |
| 77 expectIsUnparsed((text) => new Frame.parseV8(text), '#1 Foo'); |
| 78 expectIsUnparsed((text) => new Frame.parseV8(text), |
| 79 '#1 (dart:async/future.dart:10:15)'); |
| 80 expectIsUnparsed((text) => new Frame.parseV8(text), |
| 81 'Foo (dart:async/future.dart:10:15)'); |
| 82 }); |
| 83 }); |
| 84 |
| 85 group('.parseV8', () { |
| 86 test('parses a stack frame correctly', () { |
| 87 var frame = new Frame.parseV8(" at VW.call\$0 " |
| 88 "(http://pub.dartlang.org/stuff.dart.js:560:28)"); |
| 89 expect(frame.uri, |
| 90 equals(Uri.parse("http://pub.dartlang.org/stuff.dart.js"))); |
| 91 expect(frame.line, equals(560)); |
| 92 expect(frame.column, equals(28)); |
| 93 expect(frame.member, equals('VW.call\$0')); |
| 94 }); |
| 95 |
| 96 test('parses a stack frame with an absolute POSIX path correctly', () { |
| 97 var frame = new Frame.parseV8(" at VW.call\$0 " |
| 98 "(/path/to/stuff.dart.js:560:28)"); |
| 99 expect(frame.uri, equals(Uri.parse("file:///path/to/stuff.dart.js"))); |
| 100 expect(frame.line, equals(560)); |
| 101 expect(frame.column, equals(28)); |
| 102 expect(frame.member, equals('VW.call\$0')); |
| 103 }); |
| 104 |
| 105 test('parses a stack frame with an absolute Windows path correctly', () { |
| 106 var frame = new Frame.parseV8(" at VW.call\$0 " |
| 107 r"(C:\path\to\stuff.dart.js:560:28)"); |
| 108 expect(frame.uri, equals(Uri.parse("file:///C:/path/to/stuff.dart.js"))); |
| 109 expect(frame.line, equals(560)); |
| 110 expect(frame.column, equals(28)); |
| 111 expect(frame.member, equals('VW.call\$0')); |
| 112 }); |
| 113 |
| 114 test('parses a stack frame with a Windows UNC path correctly', () { |
| 115 var frame = new Frame.parseV8(" at VW.call\$0 " |
| 116 r"(\\mount\path\to\stuff.dart.js:560:28)"); |
| 117 expect(frame.uri, |
| 118 equals(Uri.parse("file://mount/path/to/stuff.dart.js"))); |
| 119 expect(frame.line, equals(560)); |
| 120 expect(frame.column, equals(28)); |
| 121 expect(frame.member, equals('VW.call\$0')); |
| 122 }); |
| 123 |
| 124 test('parses a stack frame with a relative POSIX path correctly', () { |
| 125 var frame = new Frame.parseV8(" at VW.call\$0 " |
| 126 "(path/to/stuff.dart.js:560:28)"); |
| 127 expect(frame.uri, equals(Uri.parse("path/to/stuff.dart.js"))); |
| 128 expect(frame.line, equals(560)); |
| 129 expect(frame.column, equals(28)); |
| 130 expect(frame.member, equals('VW.call\$0')); |
| 131 }); |
| 132 |
| 133 test('parses a stack frame with a relative Windows path correctly', () { |
| 134 var frame = new Frame.parseV8(" at VW.call\$0 " |
| 135 r"(path\to\stuff.dart.js:560:28)"); |
| 136 expect(frame.uri, equals(Uri.parse("path/to/stuff.dart.js"))); |
| 137 expect(frame.line, equals(560)); |
| 138 expect(frame.column, equals(28)); |
| 139 expect(frame.member, equals('VW.call\$0')); |
| 140 }); |
| 141 |
| 142 test('parses an anonymous stack frame correctly', () { |
| 143 var frame = new Frame.parseV8( |
| 144 " at http://pub.dartlang.org/stuff.dart.js:560:28"); |
| 145 expect(frame.uri, |
| 146 equals(Uri.parse("http://pub.dartlang.org/stuff.dart.js"))); |
| 147 expect(frame.line, equals(560)); |
| 148 expect(frame.column, equals(28)); |
| 149 expect(frame.member, equals('<fn>')); |
| 150 }); |
| 151 |
| 152 test('parses a native stack frame correctly', () { |
| 153 var frame = new Frame.parseV8( |
| 154 " at Object.stringify (native)"); |
| 155 expect(frame.uri, Uri.parse('native')); |
| 156 expect(frame.line, isNull); |
| 157 expect(frame.column, isNull); |
| 158 expect(frame.member, equals('Object.stringify')); |
| 159 }); |
| 160 |
| 161 test('parses a stack frame with [as ...] correctly', () { |
| 162 // Ignore "[as ...]", since other stack trace formats don't support a |
| 163 // similar construct. |
| 164 var frame = new Frame.parseV8(" at VW.call\$0 [as call\$4] " |
| 165 "(http://pub.dartlang.org/stuff.dart.js:560:28)"); |
| 166 expect(frame.uri, |
| 167 equals(Uri.parse("http://pub.dartlang.org/stuff.dart.js"))); |
| 168 expect(frame.line, equals(560)); |
| 169 expect(frame.column, equals(28)); |
| 170 expect(frame.member, equals('VW.call\$0')); |
| 171 }); |
| 172 |
| 173 test('parses a basic eval stack frame correctly', () { |
| 174 var frame = new Frame.parseV8(" at eval (eval at <anonymous> " |
| 175 "(http://pub.dartlang.org/stuff.dart.js:560:28))"); |
| 176 expect(frame.uri, |
| 177 equals(Uri.parse("http://pub.dartlang.org/stuff.dart.js"))); |
| 178 expect(frame.line, equals(560)); |
| 179 expect(frame.column, equals(28)); |
| 180 expect(frame.member, equals('eval')); |
| 181 }); |
| 182 |
| 183 test('parses an IE10 eval stack frame correctly', () { |
| 184 var frame = new Frame.parseV8(" at eval (eval at Anonymous function " |
| 185 "(http://pub.dartlang.org/stuff.dart.js:560:28))"); |
| 186 expect(frame.uri, |
| 187 equals(Uri.parse("http://pub.dartlang.org/stuff.dart.js"))); |
| 188 expect(frame.line, equals(560)); |
| 189 expect(frame.column, equals(28)); |
| 190 expect(frame.member, equals('eval')); |
| 191 }); |
| 192 |
| 193 test('parses an eval stack frame with inner position info correctly', () { |
| 194 var frame = new Frame.parseV8(" at eval (eval at <anonymous> " |
| 195 "(http://pub.dartlang.org/stuff.dart.js:560:28), <anonymous>:3:28)"); |
| 196 expect(frame.uri, |
| 197 equals(Uri.parse("http://pub.dartlang.org/stuff.dart.js"))); |
| 198 expect(frame.line, equals(560)); |
| 199 expect(frame.column, equals(28)); |
| 200 expect(frame.member, equals('eval')); |
| 201 }); |
| 202 |
| 203 test('parses a nested eval stack frame correctly', () { |
| 204 var frame = new Frame.parseV8(" at eval (eval at <anonymous> " |
| 205 "(eval at sub (http://pub.dartlang.org/stuff.dart.js:560:28)))"); |
| 206 expect(frame.uri, |
| 207 equals(Uri.parse("http://pub.dartlang.org/stuff.dart.js"))); |
| 208 expect(frame.line, equals(560)); |
| 209 expect(frame.column, equals(28)); |
| 210 expect(frame.member, equals('eval')); |
| 211 }); |
| 212 |
| 213 test('converts "<anonymous>" to "<fn>"', () { |
| 214 String parsedMember(String member) => |
| 215 new Frame.parseV8(' at $member (foo:0:0)').member; |
| 216 |
| 217 expect(parsedMember('Foo.<anonymous>'), equals('Foo.<fn>')); |
| 218 expect(parsedMember('<anonymous>.<anonymous>.bar'), |
| 219 equals('<fn>.<fn>.bar')); |
| 220 }); |
| 221 |
| 222 test('returns an UnparsedFrame for malformed frames', () { |
| 223 expectIsUnparsed((text) => new Frame.parseV8(text), ''); |
| 224 expectIsUnparsed((text) => new Frame.parseV8(text), ' at'); |
| 225 expectIsUnparsed((text) => new Frame.parseV8(text), ' at Foo'); |
| 226 expectIsUnparsed((text) => new Frame.parseV8(text), |
| 227 ' at Foo (dart:async/future.dart)'); |
| 228 expectIsUnparsed((text) => new Frame.parseV8(text), |
| 229 ' at (dart:async/future.dart:10:15)'); |
| 230 expectIsUnparsed((text) => new Frame.parseV8(text), |
| 231 'Foo (dart:async/future.dart:10:15)'); |
| 232 expectIsUnparsed((text) => new Frame.parseV8(text), |
| 233 ' at dart:async/future.dart'); |
| 234 expectIsUnparsed((text) => new Frame.parseV8(text), |
| 235 ' at dart:async/future.dart:10'); |
| 236 expectIsUnparsed((text) => new Frame.parseV8(text), |
| 237 'dart:async/future.dart:10:15'); |
| 238 }); |
| 239 }); |
| 240 |
| 241 group('.parseFirefox/.parseSafari', () { |
| 242 test('parses a simple stack frame correctly', () { |
| 243 var frame = new Frame.parseFirefox( |
| 244 ".VW.call\$0@http://pub.dartlang.org/stuff.dart.js:560"); |
| 245 expect(frame.uri, |
| 246 equals(Uri.parse("http://pub.dartlang.org/stuff.dart.js"))); |
| 247 expect(frame.line, equals(560)); |
| 248 expect(frame.column, isNull); |
| 249 expect(frame.member, equals('VW.call\$0')); |
| 250 }); |
| 251 |
| 252 test('parses a stack frame with an absolute POSIX path correctly', () { |
| 253 var frame = new Frame.parseFirefox( |
| 254 ".VW.call\$0@/path/to/stuff.dart.js:560"); |
| 255 expect(frame.uri, equals(Uri.parse("file:///path/to/stuff.dart.js"))); |
| 256 expect(frame.line, equals(560)); |
| 257 expect(frame.column, isNull); |
| 258 expect(frame.member, equals('VW.call\$0')); |
| 259 }); |
| 260 |
| 261 test('parses a stack frame with an absolute Windows path correctly', () { |
| 262 var frame = new Frame.parseFirefox( |
| 263 r".VW.call$0@C:\path\to\stuff.dart.js:560"); |
| 264 expect(frame.uri, equals(Uri.parse("file:///C:/path/to/stuff.dart.js"))); |
| 265 expect(frame.line, equals(560)); |
| 266 expect(frame.column, isNull); |
| 267 expect(frame.member, equals('VW.call\$0')); |
| 268 }); |
| 269 |
| 270 test('parses a stack frame with a Windows UNC path correctly', () { |
| 271 var frame = new Frame.parseFirefox( |
| 272 r".VW.call$0@\\mount\path\to\stuff.dart.js:560"); |
| 273 expect(frame.uri, |
| 274 equals(Uri.parse("file://mount/path/to/stuff.dart.js"))); |
| 275 expect(frame.line, equals(560)); |
| 276 expect(frame.column, isNull); |
| 277 expect(frame.member, equals('VW.call\$0')); |
| 278 }); |
| 279 |
| 280 test('parses a stack frame with a relative POSIX path correctly', () { |
| 281 var frame = new Frame.parseFirefox( |
| 282 ".VW.call\$0@path/to/stuff.dart.js:560"); |
| 283 expect(frame.uri, equals(Uri.parse("path/to/stuff.dart.js"))); |
| 284 expect(frame.line, equals(560)); |
| 285 expect(frame.column, isNull); |
| 286 expect(frame.member, equals('VW.call\$0')); |
| 287 }); |
| 288 |
| 289 test('parses a stack frame with a relative Windows path correctly', () { |
| 290 var frame = new Frame.parseFirefox( |
| 291 r".VW.call$0@path\to\stuff.dart.js:560"); |
| 292 expect(frame.uri, equals(Uri.parse("path/to/stuff.dart.js"))); |
| 293 expect(frame.line, equals(560)); |
| 294 expect(frame.column, isNull); |
| 295 expect(frame.member, equals('VW.call\$0')); |
| 296 }); |
| 297 |
| 298 test('parses a simple anonymous stack frame correctly', () { |
| 299 var frame = new Frame.parseFirefox( |
| 300 "@http://pub.dartlang.org/stuff.dart.js:560"); |
| 301 expect(frame.uri, |
| 302 equals(Uri.parse("http://pub.dartlang.org/stuff.dart.js"))); |
| 303 expect(frame.line, equals(560)); |
| 304 expect(frame.column, isNull); |
| 305 expect(frame.member, equals("<fn>")); |
| 306 }); |
| 307 |
| 308 test('parses a nested anonymous stack frame correctly', () { |
| 309 var frame = new Frame.parseFirefox( |
| 310 ".foo/<@http://pub.dartlang.org/stuff.dart.js:560"); |
| 311 expect(frame.uri, |
| 312 equals(Uri.parse("http://pub.dartlang.org/stuff.dart.js"))); |
| 313 expect(frame.line, equals(560)); |
| 314 expect(frame.column, isNull); |
| 315 expect(frame.member, equals("foo.<fn>")); |
| 316 |
| 317 frame = new Frame.parseFirefox( |
| 318 ".foo/@http://pub.dartlang.org/stuff.dart.js:560"); |
| 319 expect(frame.uri, |
| 320 equals(Uri.parse("http://pub.dartlang.org/stuff.dart.js"))); |
| 321 expect(frame.line, equals(560)); |
| 322 expect(frame.column, isNull); |
| 323 expect(frame.member, equals("foo.<fn>")); |
| 324 }); |
| 325 |
| 326 test('parses a named nested anonymous stack frame correctly', () { |
| 327 var frame = new Frame.parseFirefox( |
| 328 ".foo/.name<@http://pub.dartlang.org/stuff.dart.js:560"); |
| 329 expect(frame.uri, |
| 330 equals(Uri.parse("http://pub.dartlang.org/stuff.dart.js"))); |
| 331 expect(frame.line, equals(560)); |
| 332 expect(frame.column, isNull); |
| 333 expect(frame.member, equals("foo.<fn>")); |
| 334 |
| 335 frame = new Frame.parseFirefox( |
| 336 ".foo/.name@http://pub.dartlang.org/stuff.dart.js:560"); |
| 337 expect(frame.uri, |
| 338 equals(Uri.parse("http://pub.dartlang.org/stuff.dart.js"))); |
| 339 expect(frame.line, equals(560)); |
| 340 expect(frame.column, isNull); |
| 341 expect(frame.member, equals("foo.<fn>")); |
| 342 }); |
| 343 |
| 344 test('parses a stack frame with parameters correctly', () { |
| 345 var frame = new Frame.parseFirefox( |
| 346 '.foo(12, "@)()/<")@http://pub.dartlang.org/stuff.dart.js:560'); |
| 347 expect(frame.uri, |
| 348 equals(Uri.parse("http://pub.dartlang.org/stuff.dart.js"))); |
| 349 expect(frame.line, equals(560)); |
| 350 expect(frame.column, isNull); |
| 351 expect(frame.member, equals("foo")); |
| 352 }); |
| 353 |
| 354 test('parses a nested anonymous stack frame with parameters correctly', () { |
| 355 var frame = new Frame.parseFirefox( |
| 356 '.foo(12, "@)()/<")/.fn<@' |
| 357 'http://pub.dartlang.org/stuff.dart.js:560'); |
| 358 expect(frame.uri, |
| 359 equals(Uri.parse("http://pub.dartlang.org/stuff.dart.js"))); |
| 360 expect(frame.line, equals(560)); |
| 361 expect(frame.column, isNull); |
| 362 expect(frame.member, equals("foo.<fn>")); |
| 363 }); |
| 364 |
| 365 test('parses a deeply-nested anonymous stack frame with parameters ' |
| 366 'correctly', () { |
| 367 var frame = new Frame.parseFirefox( |
| 368 '.convertDartClosureToJS/\$function</<@' |
| 369 'http://pub.dartlang.org/stuff.dart.js:560'); |
| 370 expect(frame.uri, |
| 371 equals(Uri.parse("http://pub.dartlang.org/stuff.dart.js"))); |
| 372 expect(frame.line, equals(560)); |
| 373 expect(frame.column, isNull); |
| 374 expect(frame.member, equals("convertDartClosureToJS.<fn>.<fn>")); |
| 375 }); |
| 376 |
| 377 test('returns an UnparsedFrame for malformed frames', () { |
| 378 expectIsUnparsed((text) => new Frame.parseFirefox(text), ''); |
| 379 expectIsUnparsed((text) => new Frame.parseFirefox(text), '.foo'); |
| 380 expectIsUnparsed((text) => new Frame.parseFirefox(text), |
| 381 '.foo@dart:async/future.dart'); |
| 382 expectIsUnparsed((text) => new Frame.parseFirefox(text), |
| 383 '.foo(@dart:async/future.dart:10'); |
| 384 expectIsUnparsed((text) => new Frame.parseFirefox(text), |
| 385 '@dart:async/future.dart'); |
| 386 }); |
| 387 |
| 388 test('parses a simple stack frame correctly', () { |
| 389 var frame = new Frame.parseFirefox( |
| 390 "foo\$bar@http://dartlang.org/foo/bar.dart:10:11"); |
| 391 expect(frame.uri, equals(Uri.parse("http://dartlang.org/foo/bar.dart"))); |
| 392 expect(frame.line, equals(10)); |
| 393 expect(frame.column, equals(11)); |
| 394 expect(frame.member, equals('foo\$bar')); |
| 395 }); |
| 396 |
| 397 test('parses an anonymous stack frame correctly', () { |
| 398 var frame = new Frame.parseFirefox( |
| 399 "http://dartlang.org/foo/bar.dart:10:11"); |
| 400 expect(frame.uri, equals(Uri.parse("http://dartlang.org/foo/bar.dart"))); |
| 401 expect(frame.line, equals(10)); |
| 402 expect(frame.column, equals(11)); |
| 403 expect(frame.member, equals('<fn>')); |
| 404 }); |
| 405 |
| 406 test('parses a stack frame with no line correctly', () { |
| 407 var frame = new Frame.parseFirefox( |
| 408 "foo\$bar@http://dartlang.org/foo/bar.dart::11"); |
| 409 expect(frame.uri, equals(Uri.parse("http://dartlang.org/foo/bar.dart"))); |
| 410 expect(frame.line, isNull); |
| 411 expect(frame.column, equals(11)); |
| 412 expect(frame.member, equals('foo\$bar')); |
| 413 }); |
| 414 |
| 415 test('parses a stack frame with no column correctly', () { |
| 416 var frame = new Frame.parseFirefox( |
| 417 "foo\$bar@http://dartlang.org/foo/bar.dart:10:"); |
| 418 expect(frame.uri, equals(Uri.parse("http://dartlang.org/foo/bar.dart"))); |
| 419 expect(frame.line, equals(10)); |
| 420 expect(frame.column, isNull); |
| 421 expect(frame.member, equals('foo\$bar')); |
| 422 }); |
| 423 |
| 424 test('parses a stack frame with no line or column correctly', () { |
| 425 var frame = new Frame.parseFirefox( |
| 426 "foo\$bar@http://dartlang.org/foo/bar.dart:10:11"); |
| 427 expect(frame.uri, equals(Uri.parse("http://dartlang.org/foo/bar.dart"))); |
| 428 expect(frame.line, equals(10)); |
| 429 expect(frame.column, equals(11)); |
| 430 expect(frame.member, equals('foo\$bar')); |
| 431 }); |
| 432 }); |
| 433 |
| 434 group('.parseFriendly', () { |
| 435 test('parses a simple stack frame correctly', () { |
| 436 var frame = new Frame.parseFriendly( |
| 437 "http://dartlang.org/foo/bar.dart 10:11 Foo.<fn>.bar"); |
| 438 expect(frame.uri, equals(Uri.parse("http://dartlang.org/foo/bar.dart"))); |
| 439 expect(frame.line, equals(10)); |
| 440 expect(frame.column, equals(11)); |
| 441 expect(frame.member, equals('Foo.<fn>.bar')); |
| 442 }); |
| 443 |
| 444 test('parses a stack frame with no line or column correctly', () { |
| 445 var frame = new Frame.parseFriendly( |
| 446 "http://dartlang.org/foo/bar.dart Foo.<fn>.bar"); |
| 447 expect(frame.uri, equals(Uri.parse("http://dartlang.org/foo/bar.dart"))); |
| 448 expect(frame.line, isNull); |
| 449 expect(frame.column, isNull); |
| 450 expect(frame.member, equals('Foo.<fn>.bar')); |
| 451 }); |
| 452 |
| 453 test('parses a stack frame with no line correctly', () { |
| 454 var frame = new Frame.parseFriendly( |
| 455 "http://dartlang.org/foo/bar.dart 10 Foo.<fn>.bar"); |
| 456 expect(frame.uri, equals(Uri.parse("http://dartlang.org/foo/bar.dart"))); |
| 457 expect(frame.line, equals(10)); |
| 458 expect(frame.column, isNull); |
| 459 expect(frame.member, equals('Foo.<fn>.bar')); |
| 460 }); |
| 461 |
| 462 test('parses a stack frame with a relative path correctly', () { |
| 463 var frame = new Frame.parseFriendly("foo/bar.dart 10:11 Foo.<fn>.bar"); |
| 464 expect(frame.uri, equals( |
| 465 path.toUri(path.absolute(path.join('foo', 'bar.dart'))))); |
| 466 expect(frame.line, equals(10)); |
| 467 expect(frame.column, equals(11)); |
| 468 expect(frame.member, equals('Foo.<fn>.bar')); |
| 469 }); |
| 470 |
| 471 test('returns an UnparsedFrame for malformed frames', () { |
| 472 expectIsUnparsed((text) => new Frame.parseFriendly(text), ''); |
| 473 expectIsUnparsed((text) => new Frame.parseFriendly(text), 'foo/bar.dart'); |
| 474 expectIsUnparsed((text) => new Frame.parseFriendly(text), |
| 475 'foo/bar.dart 10:11'); |
| 476 }); |
| 477 }); |
| 478 |
| 479 test('only considers dart URIs to be core', () { |
| 480 bool isCore(String library) => |
| 481 new Frame.parseVM('#0 Foo ($library:0:0)').isCore; |
| 482 |
| 483 expect(isCore('dart:core'), isTrue); |
| 484 expect(isCore('dart:async'), isTrue); |
| 485 expect(isCore('dart:core/uri.dart'), isTrue); |
| 486 expect(isCore('dart:async/future.dart'), isTrue); |
| 487 expect(isCore('bart:core'), isFalse); |
| 488 expect(isCore('sdart:core'), isFalse); |
| 489 expect(isCore('darty:core'), isFalse); |
| 490 expect(isCore('bart:core/uri.dart'), isFalse); |
| 491 }); |
| 492 |
| 493 group('.library', () { |
| 494 test('returns the URI string for non-file URIs', () { |
| 495 expect(new Frame.parseVM('#0 Foo (dart:async/future.dart:0:0)').library, |
| 496 equals('dart:async/future.dart')); |
| 497 expect(new Frame.parseVM('#0 Foo ' |
| 498 '(http://dartlang.org/stuff/thing.dart:0:0)').library, |
| 499 equals('http://dartlang.org/stuff/thing.dart')); |
| 500 }); |
| 501 |
| 502 test('returns the relative path for file URIs', () { |
| 503 expect(new Frame.parseVM('#0 Foo (foo/bar.dart:0:0)').library, |
| 504 equals(path.join('foo', 'bar.dart'))); |
| 505 }); |
| 506 |
| 507 test('truncates data: URIs', () { |
| 508 var frame = new Frame.parseVM( |
| 509 '#0 Foo (data:application/dart;charset=utf-8,blah:0:0)'); |
| 510 expect(frame.library, equals('data:...')); |
| 511 }); |
| 512 }); |
| 513 |
| 514 group('.location', () { |
| 515 test('returns the library and line/column numbers for non-core ' |
| 516 'libraries', () { |
| 517 expect(new Frame.parseVM('#0 Foo ' |
| 518 '(http://dartlang.org/thing.dart:5:10)').location, |
| 519 equals('http://dartlang.org/thing.dart 5:10')); |
| 520 expect(new Frame.parseVM('#0 Foo (foo/bar.dart:1:2)').location, |
| 521 equals('${path.join('foo', 'bar.dart')} 1:2')); |
| 522 }); |
| 523 }); |
| 524 |
| 525 group('.package', () { |
| 526 test('returns null for non-package URIs', () { |
| 527 expect(new Frame.parseVM('#0 Foo (dart:async/future.dart:0:0)').package, |
| 528 isNull); |
| 529 expect(new Frame.parseVM('#0 Foo ' |
| 530 '(http://dartlang.org/stuff/thing.dart:0:0)').package, |
| 531 isNull); |
| 532 }); |
| 533 |
| 534 test('returns the package name for package: URIs', () { |
| 535 expect(new Frame.parseVM('#0 Foo (package:foo/foo.dart:0:0)').package, |
| 536 equals('foo')); |
| 537 expect(new Frame.parseVM('#0 Foo (package:foo/zap/bar.dart:0:0)').package, |
| 538 equals('foo')); |
| 539 }); |
| 540 }); |
| 541 |
| 542 group('.toString()', () { |
| 543 test('returns the library and line/column numbers for non-core ' |
| 544 'libraries', () { |
| 545 expect(new Frame.parseVM('#0 Foo (http://dartlang.org/thing.dart:5:10)') |
| 546 .toString(), |
| 547 equals('http://dartlang.org/thing.dart 5:10 in Foo')); |
| 548 }); |
| 549 |
| 550 test('converts "<anonymous closure>" to "<fn>"', () { |
| 551 expect(new Frame.parseVM('#0 Foo.<anonymous closure> ' |
| 552 '(dart:core/uri.dart:5:10)').toString(), |
| 553 equals('dart:core/uri.dart 5:10 in Foo.<fn>')); |
| 554 }); |
| 555 |
| 556 test('prints a frame without a column correctly', () { |
| 557 expect(new Frame.parseVM('#0 Foo (dart:core/uri.dart:5)').toString(), |
| 558 equals('dart:core/uri.dart 5 in Foo')); |
| 559 }); |
| 560 |
| 561 test('prints relative paths as relative', () { |
| 562 var relative = path.normalize('relative/path/to/foo.dart'); |
| 563 expect(new Frame.parseFriendly('$relative 5:10 Foo').toString(), |
| 564 equals('$relative 5:10 in Foo')); |
| 565 }); |
| 566 }); |
| 567 } |
| 568 |
| 569 void expectIsUnparsed(Frame constructor(String text), String text) { |
| 570 var frame = constructor(text); |
| 571 expect(frame, new isInstanceOf<UnparsedFrame>()); |
| 572 expect(frame.toString(), equals(text)); |
| 573 } |
OLD | NEW |