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

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

Issue 12340100: Make unit-test not create a fixed-length list of tests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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 | no next file » | 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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, use the pub package manager. 8 * To import this library, use the pub package manager.
9 * Create a pubspec.yaml file in your project and add 9 * Create a pubspec.yaml file in your project and add
10 * a dependency on unittest with the following lines: 10 * a dependency on unittest with the following lines:
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 * } 106 * }
107 * 107 *
108 * expectAsyncX() will wrap the callback code in a try/catch handler to handle 108 * expectAsyncX() will wrap the callback code in a try/catch handler to handle
109 * exceptions (treated as test failures). There may be times when the number of 109 * exceptions (treated as test failures). There may be times when the number of
110 * times a callback should be called is non-deterministic. In this case a dummy 110 * times a callback should be called is non-deterministic. In this case a dummy
111 * callback can be created with expectAsync0((){}) and this can be called from 111 * callback can be created with expectAsync0((){}) and this can be called from
112 * the real callback when it is finally complete. In this case the body of the 112 * the real callback when it is finally complete. In this case the body of the
113 * callback should be protected within a call to guardAsync(); this will ensure 113 * callback should be protected within a call to guardAsync(); this will ensure
114 * that exceptions are properly handled. 114 * that exceptions are properly handled.
115 * 115 *
116 * A variation on this is expectAsyncUntilX(), which takes a callback as the 116 * A variation on this is expectAsyncUntilX(), which takes a callback as the
117 * first parameter and a predicate function as the second parameter; after each 117 * first parameter and a predicate function as the second parameter; after each
118 * time * the callback is called, the predicate function will be called; if it 118 * time * the callback is called, the predicate function will be called; if it
119 * returns false the test will still be considered incomplete. 119 * returns false the test will still be considered incomplete.
120 * 120 *
121 * Test functions can return [Future]s, which provide another way of doing 121 * Test functions can return [Future]s, which provide another way of doing
122 * asynchronous tests. The test framework will handle exceptions thrown by 122 * asynchronous tests. The test framework will handle exceptions thrown by
123 * the Future, and will advance to the next test when the Future is complete. 123 * the Future, and will advance to the next test when the Future is complete.
124 * It is still important to use expectAsync/guardAsync with any parts of the 124 * It is still important to use expectAsync/guardAsync with any parts of the
125 * test that may be invoked from a top level context (for example, with 125 * test that may be invoked from a top level context (for example, with
126 * Timer.run()], as the Future exception handler may not capture exceptions 126 * Timer.run()], as the Future exception handler may not capture exceptions
127 * in such code. 127 * in such code.
128 * 128 *
129 * Note: due to some language limitations we have to use different functions 129 * Note: due to some language limitations we have to use different functions
130 * depending on the number of positional arguments of the callback. In the 130 * depending on the number of positional arguments of the callback. In the
131 * future, we plan to expose a single `expectAsync` function that can be used 131 * future, we plan to expose a single `expectAsync` function that can be used
132 * regardless of the number of positional arguments. This requires new langauge 132 * regardless of the number of positional arguments. This requires new langauge
133 * features or fixes to the current spec (e.g. see 133 * features or fixes to the current spec (e.g. see
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 void filterTests(testFilter) { 718 void filterTests(testFilter) {
719 var filterFunction; 719 var filterFunction;
720 if (testFilter is String) { 720 if (testFilter is String) {
721 RegExp re = new RegExp(testFilter); 721 RegExp re = new RegExp(testFilter);
722 filterFunction = (t) => re.hasMatch(t.description); 722 filterFunction = (t) => re.hasMatch(t.description);
723 } else if (testFilter is RegExp) { 723 } else if (testFilter is RegExp) {
724 filterFunction = (t) => testFilter.hasMatch(t.description); 724 filterFunction = (t) => testFilter.hasMatch(t.description);
725 } else if (testFilter is Function) { 725 } else if (testFilter is Function) {
726 filterFunction = testFilter; 726 filterFunction = testFilter;
727 } 727 }
728 _tests = _tests.where(filterFunction).toList(); 728 _tests.retainMatching(filterFunction);
729 } 729 }
730 730
731 /** Runs all queued tests, one at a time. */ 731 /** Runs all queued tests, one at a time. */
732 runTests() { 732 runTests() {
733 _currentTest = 0; 733 _currentTest = 0;
734 _currentGroup = ''; 734 _currentGroup = '';
735 735
736 // If we are soloing a test, remove all the others. 736 // If we are soloing a test, remove all the others.
737 if (_soloTest != null) { 737 if (_soloTest != null) {
738 filterTests((t) => t == _soloTest); 738 filterTests((t) => t == _soloTest);
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 } 885 }
886 886
887 /** Enable a test by ID. */ 887 /** Enable a test by ID. */
888 void enableTest(int testId) => _setTestEnabledState(testId, true); 888 void enableTest(int testId) => _setTestEnabledState(testId, true);
889 889
890 /** Disable a test by ID. */ 890 /** Disable a test by ID. */
891 void disableTest(int testId) => _setTestEnabledState(testId, false); 891 void disableTest(int testId) => _setTestEnabledState(testId, false);
892 892
893 /** Signature for a test function. */ 893 /** Signature for a test function. */
894 typedef void TestFunction(); 894 typedef void TestFunction();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698