| 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 /** | 5 /** |
| 6 * A library for writing dart unit tests. | 6 * A library for writing dart unit tests. |
| 7 * | 7 * |
| 8 * ## Installing ## | 8 * ## Installing ## |
| 9 * | 9 * |
| 10 * Use [pub][] to install this package. Add the following to your `pubspec.yaml` | 10 * Use [pub][] to install this package. Add the following to your `pubspec.yaml` |
| (...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 typedef dynamic TestFunction(); | 843 typedef dynamic TestFunction(); |
| 844 | 844 |
| 845 /** | 845 /** |
| 846 * A flag that controls whether we hide unittest and core library details in | 846 * A flag that controls whether we hide unittest and core library details in |
| 847 * exception stacks. | 847 * exception stacks. |
| 848 * | 848 * |
| 849 * Useful to disable when debugging unittest or matcher customizations. | 849 * Useful to disable when debugging unittest or matcher customizations. |
| 850 */ | 850 */ |
| 851 bool formatStacks = true; | 851 bool formatStacks = true; |
| 852 | 852 |
| 853 /** Returns a Trace object from a StackTrace object or a String. */ | 853 /** |
| 854 * A flag that controls whether we try to filter out irrelevant frames from |
| 855 * the stack trce. Requires formatStacks to be set. |
| 856 */ |
| 857 bool filterStacks = true; |
| 858 |
| 859 /** |
| 860 * Returns a Trace object from a StackTrace object or a String, or the |
| 861 * unchanged input if formatStacks is false; |
| 862 */ |
| 854 Trace _getTrace(stack) { | 863 Trace _getTrace(stack) { |
| 855 Trace trace; | 864 Trace trace; |
| 856 if (stack == null) return null; | 865 if (stack == null || !formatStacks) return null; |
| 857 if (stack is String) { | 866 if (stack is String) { |
| 858 trace = new Trace.parse(stack); | 867 trace = new Trace.parse(stack); |
| 859 } else if (stack is StackTrace) { | 868 } else if (stack is StackTrace) { |
| 860 trace = new Trace.from(stack); | 869 trace = new Trace.from(stack); |
| 861 } else { | 870 } else { |
| 862 throw new Exception('Invalid stack type ${stack.runtimeType} for $stack.'); | 871 throw new Exception('Invalid stack type ${stack.runtimeType} for $stack.'); |
| 863 } | 872 } |
| 864 | 873 |
| 865 if (!formatStacks) return trace; | 874 if (!filterStacks) return trace; |
| 866 | 875 |
| 867 // Format the stack trace by removing everything above TestCase._runTest, | 876 // Format the stack trace by removing everything above TestCase._runTest, |
| 868 // which is usually going to be irrelevant. Also fold together unittest and | 877 // which is usually going to be irrelevant. Also fold together unittest and |
| 869 // core library calls so only the function the user called is visible. | 878 // core library calls so only the function the user called is visible. |
| 870 return new Trace(trace.frames.takeWhile((frame) { | 879 return new Trace(trace.frames.takeWhile((frame) { |
| 871 return frame.package != 'unittest' || frame.member != 'TestCase._runTest'; | 880 return frame.package != 'unittest' || frame.member != 'TestCase._runTest'; |
| 872 })).terse.foldFrames((frame) => frame.package == 'unittest' || frame.isCore); | 881 })).terse.foldFrames((frame) => frame.package == 'unittest' || frame.isCore); |
| 873 } | 882 } |
| OLD | NEW |