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

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

Issue 16408019: Improved error messages from unittest. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 6 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
« no previous file with comments | « pkg/unittest/lib/src/string_matchers.dart ('k') | pkg/unittest/test/instance_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 845 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 856
857 /** Enable a test by ID. */ 857 /** Enable a test by ID. */
858 void enableTest(int testId) => _setTestEnabledState(testId, true); 858 void enableTest(int testId) => _setTestEnabledState(testId, true);
859 859
860 /** Disable a test by ID. */ 860 /** Disable a test by ID. */
861 void disableTest(int testId) => _setTestEnabledState(testId, false); 861 void disableTest(int testId) => _setTestEnabledState(testId, false);
862 862
863 /** Signature for a test function. */ 863 /** Signature for a test function. */
864 typedef dynamic TestFunction(); 864 typedef dynamic TestFunction();
865 865
866 /**
867 * A flag that controls whether we hide unittest details in exception stacks.
868 * Useful to disable when debugging unittest or matcher customizations.
869 */
870 bool formatStacks = true;
871
866 // Stack formatting utility. Strips extraneous content from a stack trace. 872 // Stack formatting utility. Strips extraneous content from a stack trace.
867 // Stack frame lines are parsed with a regexp, which has been tested 873 // Stack frame lines are parsed with a regexp, which has been tested
868 // in Chrome, Firefox and the VM. If a line fails to be parsed it is 874 // in Chrome, Firefox and the VM. If a line fails to be parsed it is
869 // included in the output to be conservative. 875 // included in the output to be conservative.
870 // 876 //
871 // The output stack consists of everything after the call to TestCase._run. 877 // The output stack consists of everything after the call to TestCase._run.
872 // If we see an 'expect' in the frame we will prune everything above that 878 // If we see an 'expect' in the frame we will prune everything above that
873 // as well. 879 // as well.
874 final _frameRegExp = new RegExp( 880 final _frameRegExp = new RegExp(
875 r'^\s*' // Skip leading spaces. 881 r'^\s*' // Skip leading spaces.
876 r'(?:' // Group of choices for the prefix. 882 r'(?:' // Group of choices for the prefix.
877 r'(?:#\d+\s*)|' // Skip VM's #<frameNumber>. 883 r'(?:#\d+\s*)|' // Skip VM's #<frameNumber>.
878 r'(?:at )|' // Skip Firefox's 'at '. 884 r'(?:at )|' // Skip Firefox's 'at '.
879 r'(?:))' // Other environments have nothing here. 885 r'(?:))' // Other environments have nothing here.
880 r'(.+)' // Extract the function/method. 886 r'(.+)' // Extract the function/method.
881 r'\s*[@\(]' // Skip space and @ or (. 887 r'\s*[@\(]' // Skip space and @ or (.
882 r'(' // This group of choices is for the source file. 888 r'(' // This group of choices is for the source file.
883 r'(?:.+:\/\/.+\/[^:]*)|' // Handle file:// or http:// URLs. 889 r'(?:.+:\/\/.+\/[^:]*)|' // Handle file:// or http:// URLs.
884 r'(?:dart:[^:]*)|' // Handle dart:<lib>. 890 r'(?:dart:[^:]*)|' // Handle dart:<lib>.
885 r'(?:package:[^:]*)' // Handle package:<path> 891 r'(?:package:[^:]*)' // Handle package:<path>
886 r'):([:\d]+)[\)]?$'); // Get the line number and optional column number. 892 r'):([:\d]+)[\)]?$'); // Get the line number and optional column number.
887 893
888 String _formatStack(stack) { 894 String _formatStack(stack) {
895 if (!formatStacks) return "$stack";
889 var lines; 896 var lines;
890 if (stack is StackTrace) { 897 if (stack is StackTrace) {
891 lines = stack.toString().split('\n'); 898 lines = stack.toString().split('\n');
892 } else if (stack is String) { 899 } else if (stack is String) {
893 lines = stack.split('\n'); 900 lines = stack.split('\n');
894 } else { 901 } else {
895 return stack.toString(); 902 return stack.toString();
896 } 903 }
897 904
898 // Calculate the max width of first column so we can 905 // Calculate the max width of first column so we can
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 } 939 }
933 sb.write(location); 940 sb.write(location);
934 sb.write(' '); 941 sb.write(' ');
935 sb.write(position); 942 sb.write(position);
936 sb.write('\n'); 943 sb.write('\n');
937 } 944 }
938 } 945 }
939 } 946 }
940 return sb.toString(); 947 return sb.toString();
941 } 948 }
OLDNEW
« no previous file with comments | « pkg/unittest/lib/src/string_matchers.dart ('k') | pkg/unittest/test/instance_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698