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 unittest.utils; | 5 library unittest.utils; |
6 | 6 |
| 7 import 'dart:async'; |
| 8 |
7 import 'package:stack_trace/stack_trace.dart'; | 9 import 'package:stack_trace/stack_trace.dart'; |
8 | 10 |
| 11 /// A typedef for a possibly-asynchronous function. |
| 12 /// |
| 13 /// The return type should only ever by [Future] or void. |
| 14 typedef AsyncFunction(); |
| 15 |
9 /// Indent each line in [str] by two spaces. | 16 /// Indent each line in [str] by two spaces. |
10 String indent(String str) => | 17 String indent(String str) => |
11 str.replaceAll(new RegExp("^", multiLine: true), " "); | 18 str.replaceAll(new RegExp("^", multiLine: true), " "); |
12 | 19 |
13 /// A pair of values. | 20 /// A pair of values. |
14 class Pair<E, F> { | 21 class Pair<E, F> { |
15 final E first; | 22 final E first; |
16 final F last; | 23 final F last; |
17 | 24 |
18 Pair(this.first, this.last); | 25 Pair(this.first, this.last); |
(...skipping 23 matching lines...) Loading... |
42 | 49 |
43 if (!filterStacks) return trace; | 50 if (!filterStacks) return trace; |
44 | 51 |
45 // Format the stack trace by removing everything above TestCase._runTest, | 52 // Format the stack trace by removing everything above TestCase._runTest, |
46 // which is usually going to be irrelevant. Also fold together unittest and | 53 // which is usually going to be irrelevant. Also fold together unittest and |
47 // core library calls so only the function the user called is visible. | 54 // core library calls so only the function the user called is visible. |
48 return new Trace(trace.frames.takeWhile((frame) { | 55 return new Trace(trace.frames.takeWhile((frame) { |
49 return frame.package != 'unittest' || frame.member != 'TestCase._runTest'; | 56 return frame.package != 'unittest' || frame.member != 'TestCase._runTest'; |
50 })).terse.foldFrames((frame) => frame.package == 'unittest' || frame.isCore); | 57 })).terse.foldFrames((frame) => frame.package == 'unittest' || frame.isCore); |
51 } | 58 } |
OLD | NEW |