Index: pkg/unittest/lib/unittest.dart |
=================================================================== |
--- pkg/unittest/lib/unittest.dart (revision 22094) |
+++ pkg/unittest/lib/unittest.dart (working copy) |
@@ -181,8 +181,16 @@ |
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. */ |
Siggi Cherem (dart-lang)
2013/04/27 01:36:08
multiline comment format fix: move */ to it's own
gram
2013/04/29 21:24:18
Done.
|
+Configuration get unittestConfiguration { |
+ if (_config == null) { |
+ _config = new Configuration(); |
Siggi Cherem (dart-lang)
2013/04/27 01:36:08
this is already done just before onInit, why do we
gram
2013/04/29 21:24:18
Yes, it is so they can set values. I don't want th
Siggi Cherem (dart-lang)
2013/04/30 00:42:33
by option 2 I meant to consider replacing lines 83
gram
2013/04/30 01:00:09
Done.
|
+ } |
+ return _config; |
+} |
/** |
* Sets the [Configuration] used by the unittest library. |
@@ -859,3 +867,51 @@ |
/** Signature for a test function. */ |
typedef dynamic TestFunction(); |
+ |
+// Stack formatting utility. Strips extraneous content from a stack trace. |
+// Each original line is of the form #<n> <function> (<location url>). |
+final _nativeFrameRegExp = new RegExp( |
+ r'^#\d+\s+([^\s].*) (\(.+:\d+:\d+\))$'); |
+ |
+String _formatStack(stack) { |
Siggi Cherem (dart-lang)
2013/04/27 01:36:08
as we were discussing offline. why can't we use th
gram
2013/04/29 21:24:18
In the latest version they work in Firefox, Dartiu
|
+ var lines; |
+ if (stack is StackTrace) { |
+ lines = stack.toString().split('\n'); |
+ } else if (stack is String) { |
+ lines = stack.split('\n'); |
+ } else { |
+ return stack.toString(); |
+ } |
+ |
+ // We remove all entries that have a location in unittest. |
+ // We strip out anything before _nextBatch too. |
+ var sb = new StringBuffer(); |
+ var maxlen = 0; |
+ for (var pass = 0; pass < 2; pass++) { |
Siggi Cherem (dart-lang)
2013/04/27 01:36:08
I'd prefer if we split this in 2 loops, so that ea
gram
2013/04/29 21:24:18
The filtering is not that conducive to this now th
|
+ for (var i = 0; i < lines.length; i++) { |
+ if (lines[i] == '') continue; |
+ var match = _nativeFrameRegExp.firstMatch(lines[i]); |
+ if (match == null) { |
+ throw new FormatException( |
+ "Couldn't parse stack trace line '${lines[i]}' from $stack."); |
Siggi Cherem (dart-lang)
2013/04/27 01:36:08
I don't think we should throw if we can't parse a
gram
2013/04/29 21:24:18
Done.
|
+ } |
+ var member = match[1]; |
+ var location = match[2]; |
+ if (location.indexOf('unittest/lib/') >= 0) { |
Siggi Cherem (dart-lang)
2013/04/27 01:36:08
when running things outside of the repo, the stack
gram
2013/04/29 21:24:18
I've addressed this.
|
+ if (member == '_nextBatch') break; |
+ } else if (pass == 0) { |
+ // Find max length of first column. |
+ if (member.length > maxlen) maxlen = member.length; |
+ } else { |
+ sb.write(member); |
+ // Pad second column to a fixed position. |
+ for (var j = 0; j <= maxlen - member.length; j++) { |
+ sb.write(' '); |
+ } |
+ sb.write(location); |
+ sb.write('\n'); |
+ } |
+ } |
+ } |
+ return sb.toString(); |
+} |