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

Unified Diff: pkg/unittest/lib/unittest.dart

Issue 14021021: Unit test improvements. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/unittest/lib/src/test_case.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
+}
« no previous file with comments | « pkg/unittest/lib/src/test_case.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698