Index: pkg/unittest/lib/unittest.dart |
=================================================================== |
--- pkg/unittest/lib/unittest.dart (revision 22128) |
+++ pkg/unittest/lib/unittest.dart (working copy) |
@@ -181,8 +181,17 @@ |
Configuration _config; |
-/** [Configuration] used by the unittest library. */ |
-Configuration get unittestConfiguration => _config; |
+/** |
+ * [Configuration] used by the unittest library. Note that if a |
+ * configuration has not been set, calling this getter will create |
+ * a default configuration. |
+ */ |
+Configuration get unittestConfiguration { |
+ if (_config == null) { |
+ _config = new Configuration(); |
+ } |
+ return _config; |
+} |
/** |
* Sets the [Configuration] used by the unittest library. |
@@ -859,3 +868,69 @@ |
/** Signature for a test function. */ |
typedef dynamic TestFunction(); |
+ |
+// Stack formatting utility. Strips extraneous content from a stack trace. |
+// Stack fram lines are parsed with a regexp, which has been tested |
Siggi Cherem (dart-lang)
2013/04/30 00:42:33
fram => frame
gram
2013/04/30 01:00:09
Done.
|
+// in Chrome, Firefox and the VM. If a line fails to be parsed it is |
+// included in the output to be conservative. |
+// |
+// The output stack consists of everything after the call to TestCase._run. |
+// If we see an 'expect' in the frame we will prune everything above that |
+// as well. |
+final _frameRegExp = new RegExp( |
+ r'^\s*(?:(?:#\d+\s*)|(?:at )|(?:))(.+)\s*[@\(]((?:.+:\/\/.+\/[^:]*)|(?:dart:[^:]*)|(?:package:[^:]*)):([:\d]+)[\)]?$'); |
Siggi Cherem (dart-lang)
2013/04/30 00:42:33
is there a way to split this string in pieces to m
gram
2013/04/30 01:00:09
Done.
|
+ |
+String _formatStack(stack) { |
+ var lines; |
+ if (stack is StackTrace) { |
+ lines = stack.toString().split('\n'); |
+ } else if (stack is String) { |
+ lines = stack.split('\n'); |
+ } else { |
+ return stack.toString(); |
+ } |
+ |
+ // Calculate the max width of first column so we can |
+ // pad to align the second columns. |
+ int padding = lines.fold(0, (n, line) { |
+ var match = _frameRegExp.firstMatch(line); |
+ if (match == null) return n; |
+ return match[1].length + 1; |
Siggi Cherem (dart-lang)
2013/04/30 00:42:33
missing call to max(n, *) here?
gram
2013/04/30 01:00:09
Done.
|
+ }); |
+ |
+ // We remove all entries that have a location in unittest. |
+ // We strip out anything before _nextBatch too. |
+ var sb = new StringBuffer(); |
+ for (var i = 0; i < lines.length; i++) { |
+ var line = lines[i]; |
+ if (line == '') continue; |
+ var match = _frameRegExp.firstMatch(line); |
+ if (match == null) { |
+ sb.write(line); |
+ sb.write('\n'); |
+ } else { |
+ var member = match[1]; |
+ var location = match[2]; |
+ var position = match[3]; |
+ if (member.indexOf('TestCase._runTest') >= 0) { |
+ // Don't include anything after this. |
+ break; |
+ } else if (member.indexOf('expect') >= 0) { |
+ // It looks like this was an expect() failure; |
+ // drop all the frames up to here. |
+ sb.clear(); |
+ } else { |
+ sb.write(member); |
+ // Pad second column to a fixed position. |
+ for (var j = 0; j <= padding - member.length; j++) { |
+ sb.write(' '); |
+ } |
+ sb.write(location); |
+ sb.write(' '); |
+ sb.write(position); |
+ sb.write('\n'); |
+ } |
+ } |
+ } |
+ return sb.toString(); |
+} |