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

Side by Side Diff: pkg/unittest/lib/unittest.dart

Issue 13852043: unittest: testCases back to being UnmodifiableListView (Closed) Base URL: https://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
« no previous file with comments | « no previous file | pkg/unittest/test/unittest_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 * To import this library, install the 8 * To import this library, install the
9 * [unittest package](http://pub.dartlang.org/packages/unittest) via the pub 9 * [unittest package](http://pub.dartlang.org/packages/unittest) via the pub
10 * package manager. See the [Getting Started](http://pub.dartlang.org/doc) 10 * package manager. See the [Getting Started](http://pub.dartlang.org/doc)
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 194
195 /** 195 /**
196 * Description text of the current test group. If multiple groups are nested, 196 * Description text of the current test group. If multiple groups are nested,
197 * this will contain all of their text concatenated. 197 * this will contain all of their text concatenated.
198 */ 198 */
199 String _currentGroup = ''; 199 String _currentGroup = '';
200 200
201 /** Separator used between group names and test names. */ 201 /** Separator used between group names and test names. */
202 String groupSep = ' '; 202 String groupSep = ' ';
203 203
204 // TODO(nweiz): present an unmodifiable view of this once issue 8321 is fixed.
205 /** Tests executed in this suite. */ 204 /** Tests executed in this suite. */
nweiz 2013/04/19 18:39:53 This comment should be attached to the public fiel
206 final List<TestCase> testCases = new List<TestCase>(); 205 final List<TestCase> _testCases = new List<TestCase>();
206
207 final testCases = new UnmodifiableListView<TestCase>(_testCases);
207 208
208 /** Setup function called before each test in a group */ 209 /** Setup function called before each test in a group */
209 Function _testSetup; 210 Function _testSetup;
210 211
211 /** Teardown function called after each test in a group */ 212 /** Teardown function called after each test in a group */
212 Function _testTeardown; 213 Function _testTeardown;
213 214
214 int _currentTestCaseIndex = 0; 215 int _currentTestCaseIndex = 0;
215 216
216 /** [TestCase] currently being executed. */ 217 /** [TestCase] currently being executed. */
(...skipping 28 matching lines...) Expand all
245 */ 246 */
246 Map testState = {}; 247 Map testState = {};
247 248
248 /** 249 /**
249 * Creates a new test case with the given description and body. The 250 * Creates a new test case with the given description and body. The
250 * description will include the descriptions of any surrounding group() 251 * description will include the descriptions of any surrounding group()
251 * calls. 252 * calls.
252 */ 253 */
253 void test(String spec, TestFunction body) { 254 void test(String spec, TestFunction body) {
254 ensureInitialized(); 255 ensureInitialized();
255 testCases.add(new TestCase._internal(testCases.length + 1, _fullSpec(spec), 256 _testCases.add(new TestCase._internal(testCases.length + 1, _fullSpec(spec),
256 body)); 257 body));
nweiz 2013/04/19 18:39:53 Indent one more space.
257 } 258 }
258 259
259 /** 260 /**
260 * Creates a new test case with the given description and body. The 261 * Creates a new test case with the given description and body. The
261 * description will include the descriptions of any surrounding group() 262 * description will include the descriptions of any surrounding group()
262 * calls. 263 * calls.
263 * 264 *
264 * "solo_" means that this will be the only test that is run. All other tests 265 * "solo_" means that this will be the only test that is run. All other tests
265 * will be skipped. This is a convenience function to let you quickly isolate 266 * will be skipped. This is a convenience function to let you quickly isolate
266 * a single test by adding "solo_" before it to temporarily disable all other 267 * a single test by adding "solo_" before it to temporarily disable all other
267 * tests. 268 * tests.
268 */ 269 */
269 void solo_test(String spec, TestFunction body) { 270 void solo_test(String spec, TestFunction body) {
270 // TODO(rnystrom): Support multiple solos. If more than one test is solo-ed, 271 // TODO(rnystrom): Support multiple solos. If more than one test is solo-ed,
271 // all of the solo-ed tests and none of the non-solo-ed ones should run. 272 // all of the solo-ed tests and none of the non-solo-ed ones should run.
272 if (_soloTest != null) { 273 if (_soloTest != null) {
273 throw new Exception('Only one test can be soloed right now.'); 274 throw new Exception('Only one test can be soloed right now.');
274 } 275 }
275 276
276 ensureInitialized(); 277 ensureInitialized();
277 278
278 _soloTest = new TestCase._internal(testCases.length + 1, _fullSpec(spec), body ); 279 _soloTest = new TestCase._internal(testCases.length + 1, _fullSpec(spec), body );
279 testCases.add(_soloTest); 280 _testCases.add(_soloTest);
280 } 281 }
281 282
282 /** Sentinel value for [_SpreadArgsHelper]. */ 283 /** Sentinel value for [_SpreadArgsHelper]. */
283 class _Sentinel { 284 class _Sentinel {
284 const _Sentinel(); 285 const _Sentinel();
285 } 286 }
286 287
287 /** Simulates spread arguments using named arguments. */ 288 /** Simulates spread arguments using named arguments. */
288 // TODO(sigmund): remove this class and simply use a closure with named 289 // TODO(sigmund): remove this class and simply use a closure with named
289 // arguments (if still applicable). 290 // arguments (if still applicable).
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 void filterTests(testFilter) { 684 void filterTests(testFilter) {
684 var filterFunction; 685 var filterFunction;
685 if (testFilter is String) { 686 if (testFilter is String) {
686 RegExp re = new RegExp(testFilter); 687 RegExp re = new RegExp(testFilter);
687 filterFunction = (t) => re.hasMatch(t.description); 688 filterFunction = (t) => re.hasMatch(t.description);
688 } else if (testFilter is RegExp) { 689 } else if (testFilter is RegExp) {
689 filterFunction = (t) => testFilter.hasMatch(t.description); 690 filterFunction = (t) => testFilter.hasMatch(t.description);
690 } else if (testFilter is Function) { 691 } else if (testFilter is Function) {
691 filterFunction = testFilter; 692 filterFunction = testFilter;
692 } 693 }
693 testCases.retainWhere(filterFunction); 694 _testCases.retainWhere(filterFunction);
694 } 695 }
695 696
696 /** Runs all queued tests, one at a time. */ 697 /** Runs all queued tests, one at a time. */
697 void runTests() { 698 void runTests() {
698 _ensureInitialized(false); 699 _ensureInitialized(false);
699 _currentTestCaseIndex = 0; 700 _currentTestCaseIndex = 0;
700 _currentGroup = ''; 701 _currentGroup = '';
701 702
702 // If we are soloing a test, remove all the others. 703 // If we are soloing a test, remove all the others.
703 if (_soloTest != null) { 704 if (_soloTest != null) {
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 } 856 }
856 857
857 /** Enable a test by ID. */ 858 /** Enable a test by ID. */
858 void enableTest(int testId) => _setTestEnabledState(testId, true); 859 void enableTest(int testId) => _setTestEnabledState(testId, true);
859 860
860 /** Disable a test by ID. */ 861 /** Disable a test by ID. */
861 void disableTest(int testId) => _setTestEnabledState(testId, false); 862 void disableTest(int testId) => _setTestEnabledState(testId, false);
862 863
863 /** Signature for a test function. */ 864 /** Signature for a test function. */
864 typedef dynamic TestFunction(); 865 typedef dynamic TestFunction();
OLDNEW
« no previous file with comments | « no previous file | pkg/unittest/test/unittest_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698