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