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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 174
175 // TODO(amouravski): We should not need to import mock here, but it's necessary 175 // TODO(amouravski): We should not need to import mock here, but it's necessary
176 // to enable dartdoc on the mock library, as it's not picked up normally. 176 // to enable dartdoc on the mock library, as it's not picked up normally.
177 import 'mock.dart'; 177 import 'mock.dart';
178 178
179 part 'src/config.dart'; 179 part 'src/config.dart';
180 part 'src/test_case.dart'; 180 part 'src/test_case.dart';
181 181
182 Configuration _config; 182 Configuration _config;
183 183
184 /** [Configuration] used by the unittest library. */ 184 /**
185 Configuration get unittestConfiguration => _config; 185 * [Configuration] used by the unittest library. Note that if a
186 * configuration has not been set, calling this getter will create
187 * 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.
188 Configuration get unittestConfiguration {
189 if (_config == null) {
190 _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.
191 }
192 return _config;
193 }
186 194
187 /** 195 /**
188 * Sets the [Configuration] used by the unittest library. 196 * Sets the [Configuration] used by the unittest library.
189 * 197 *
190 * Throws a [StateError] if there is an existing, incompatible value. 198 * Throws a [StateError] if there is an existing, incompatible value.
191 */ 199 */
192 void set unittestConfiguration(Configuration value) { 200 void set unittestConfiguration(Configuration value) {
193 if(!identical(_config, value)) { 201 if(!identical(_config, value)) {
194 if(_config != null) { 202 if(_config != null) {
195 throw new StateError('unittestConfiguration has already been set'); 203 throw new StateError('unittestConfiguration has already been set');
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 } 860 }
853 861
854 /** Enable a test by ID. */ 862 /** Enable a test by ID. */
855 void enableTest(int testId) => _setTestEnabledState(testId, true); 863 void enableTest(int testId) => _setTestEnabledState(testId, true);
856 864
857 /** Disable a test by ID. */ 865 /** Disable a test by ID. */
858 void disableTest(int testId) => _setTestEnabledState(testId, false); 866 void disableTest(int testId) => _setTestEnabledState(testId, false);
859 867
860 /** Signature for a test function. */ 868 /** Signature for a test function. */
861 typedef dynamic TestFunction(); 869 typedef dynamic TestFunction();
870
871 // Stack formatting utility. Strips extraneous content from a stack trace.
872 // Each original line is of the form #<n> <function> (<location url>).
873 final _nativeFrameRegExp = new RegExp(
874 r'^#\d+\s+([^\s].*) (\(.+:\d+:\d+\))$');
875
876 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
877 var lines;
878 if (stack is StackTrace) {
879 lines = stack.toString().split('\n');
880 } else if (stack is String) {
881 lines = stack.split('\n');
882 } else {
883 return stack.toString();
884 }
885
886 // We remove all entries that have a location in unittest.
887 // We strip out anything before _nextBatch too.
888 var sb = new StringBuffer();
889 var maxlen = 0;
890 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
891 for (var i = 0; i < lines.length; i++) {
892 if (lines[i] == '') continue;
893 var match = _nativeFrameRegExp.firstMatch(lines[i]);
894 if (match == null) {
895 throw new FormatException(
896 "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.
897 }
898 var member = match[1];
899 var location = match[2];
900 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.
901 if (member == '_nextBatch') break;
902 } else if (pass == 0) {
903 // Find max length of first column.
904 if (member.length > maxlen) maxlen = member.length;
905 } else {
906 sb.write(member);
907 // Pad second column to a fixed position.
908 for (var j = 0; j <= maxlen - member.length; j++) {
909 sb.write(' ');
910 }
911 sb.write(location);
912 sb.write('\n');
913 }
914 }
915 }
916 return sb.toString();
917 }
OLDNEW
« pkg/unittest/lib/src/config.dart ('K') | « 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