Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Side by Side Diff: pkg/unittest/lib/unittest.dart

Issue 22859009: Changes to how we handle fancy stacks: (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698