Chromium Code Reviews| 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 845 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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) { | |
|
Siggi Cherem (dart-lang)
2013/06/14 01:20:56
nit: use fast-exit pattern
if (!formatStacks) ret
| |
| 896 return "$stack"; | |
| 897 } | |
| 889 var lines; | 898 var lines; |
| 890 if (stack is StackTrace) { | 899 if (stack is StackTrace) { |
| 891 lines = stack.toString().split('\n'); | 900 lines = stack.toString().split('\n'); |
| 892 } else if (stack is String) { | 901 } else if (stack is String) { |
| 893 lines = stack.split('\n'); | 902 lines = stack.split('\n'); |
| 894 } else { | 903 } else { |
| 895 return stack.toString(); | 904 return stack.toString(); |
| 896 } | 905 } |
| 897 | 906 |
| 898 // Calculate the max width of first column so we can | 907 // Calculate the max width of first column so we can |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 932 } | 941 } |
| 933 sb.write(location); | 942 sb.write(location); |
| 934 sb.write(' '); | 943 sb.write(' '); |
| 935 sb.write(position); | 944 sb.write(position); |
| 936 sb.write('\n'); | 945 sb.write('\n'); |
| 937 } | 946 } |
| 938 } | 947 } |
| 939 } | 948 } |
| 940 return sb.toString(); | 949 return sb.toString(); |
| 941 } | 950 } |
| OLD | NEW |