| 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 'dart:io'; |
| 7 import 'dart:uri'; | 8 import 'dart:uri'; |
| 8 | 9 |
| 9 import 'package:pathos/path.dart' as path; | 10 import 'package:pathos/path.dart' as path; |
| 10 import 'package:stack_trace/stack_trace.dart'; | 11 import 'package:stack_trace/stack_trace.dart'; |
| 11 import 'package:unittest/unittest.dart'; | 12 import 'package:unittest/unittest.dart'; |
| 12 | 13 |
| 13 String getStackTraceString() { | 14 String getStackTraceString() { |
| 14 try { | 15 try { |
| 15 throw ''; | 16 throw ''; |
| 16 } catch (_, stackTrace) { | 17 } catch (_, stackTrace) { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 var trace = nestedGetCurrentTrace(2); | 84 var trace = nestedGetCurrentTrace(2); |
| 84 expect(trace.frames.first.member, equals('main.<fn>.<fn>')); | 85 expect(trace.frames.first.member, equals('main.<fn>.<fn>')); |
| 85 }); | 86 }); |
| 86 | 87 |
| 87 test('throws an ArgumentError for negative levels', () { | 88 test('throws an ArgumentError for negative levels', () { |
| 88 expect(() => new Trace.current(-1), throwsArgumentError); | 89 expect(() => new Trace.current(-1), throwsArgumentError); |
| 89 }); | 90 }); |
| 90 }); | 91 }); |
| 91 | 92 |
| 92 test('.toString() nicely formats the stack trace', () { | 93 test('.toString() nicely formats the stack trace', () { |
| 93 var absolute = path.absolute(path.join('foo', 'bar.dart')); | 94 var uri = _pathToFileUri(path.join('foo', 'bar.dart')); |
| 94 var trace = new Trace.parse(''' | 95 var trace = new Trace.parse(''' |
| 95 #0 Foo._bar (file://$absolute:42:21) | 96 #0 Foo._bar ($uri:42:21) |
| 96 #1 zip.<anonymous closure>.zap (dart:async:0:2) | 97 #1 zip.<anonymous closure>.zap (dart:async:0:2) |
| 97 #2 zip.<anonymous closure>.zap (http://pub.dartlang.org/thing.dart:1:100) | 98 #2 zip.<anonymous closure>.zap (http://pub.dartlang.org/thing.dart:1:100) |
| 98 '''); | 99 '''); |
| 99 | 100 |
| 100 expect(trace.toString(), equals(''' | 101 expect(trace.toString(), equals(''' |
| 101 ${path.join('foo', 'bar.dart')} 42:21 Foo._bar | 102 ${path.join('foo', 'bar.dart')} 42:21 Foo._bar |
| 102 dart:async zip.<fn>.zap | 103 dart:async zip.<fn>.zap |
| 103 http://pub.dartlang.org/thing.dart 1:100 zip.<fn>.zap | 104 http://pub.dartlang.org/thing.dart 1:100 zip.<fn>.zap |
| 104 ''')); | 105 ''')); |
| 105 }); | 106 }); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 125 '''); | 126 '''); |
| 126 | 127 |
| 127 expect(trace.terse.toString(), equals(''' | 128 expect(trace.terse.toString(), equals(''' |
| 128 foo.dart 42:21 notCore | 129 foo.dart 42:21 notCore |
| 129 dart:core bottom | 130 dart:core bottom |
| 130 bar.dart 10:20 alsoNotCore | 131 bar.dart 10:20 alsoNotCore |
| 131 dart:async bottom | 132 dart:async bottom |
| 132 ''')); | 133 ''')); |
| 133 }); | 134 }); |
| 134 } | 135 } |
| 136 |
| 137 String _pathToFileUri(String pathString) { |
| 138 pathString = path.absolute(pathString); |
| 139 if (Platform.operatingSystem != 'windows') return 'file://$pathString'; |
| 140 return 'file:///${pathString.replaceAll("\\", "/")}'; |
| 141 } |
| OLD | NEW |