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

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

Issue 10441104: New expectation functions plus convert old tests to use these. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 6 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) 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, specify the relative path to 8 * To import this library, specify the relative path to
9 * lib/unittest/unittest.dart. 9 * lib/unittest/unittest.dart.
10 * 10 *
11 * ##Concepts## 11 * ##Concepts##
12 * 12 *
13 * * Tests: Tests are specified via the top-level function [test], they can be 13 * * Tests: Tests are specified via the top-level function [test], they can be
14 * organized together using [group]. 14 * organized together using [group].
15 * * Checks: Test expectations can be specified via [expect] (see methods in 15 * * Checks: Test expectations can be specified via [expect]
16 * [Expectation]), [expectThrow], or using assertions with the [Expect]
17 * class.
18 * * Configuration: The framework can be adapted by calling [configure] with a 16 * * Configuration: The framework can be adapted by calling [configure] with a
19 * [Configuration]. Common configurations can be found in this package 17 * [Configuration]. Common configurations can be found in this package
20 * under: 'dom\_config.dart', 'html\_config.dart', and 'vm\_config.dart'. 18 * under: 'dom\_config.dart', 'html\_config.dart', and 'vm\_config.dart'.
21 * 19 *
22 * ##Examples## 20 * ##Examples##
23 * 21 *
24 * A trivial test: 22 * A trivial test:
25 * 23 *
26 * #import('path-to-dart/lib/unittest/unitest.dart'); 24 * #import('path-to-dart/lib/unittest/unitest.dart');
27 * main() { 25 * main() {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 * // indicate that the asynchronous callback was invoked. 116 * // indicate that the asynchronous callback was invoked.
119 * async.complete(); 117 * async.complete();
120 * }), 0); 118 * }), 0);
121 * }); 119 * });
122 * 120 *
123 */ 121 */
124 #library('unittest'); 122 #library('unittest');
125 123
126 #import('dart:isolate'); 124 #import('dart:isolate');
127 125
126 #source('collection_matchers.dart');
128 #source('config.dart'); 127 #source('config.dart');
129 #source('expectation.dart'); 128 #source('core_matchers.dart');
129 #source('description.dart');
130 #source('expect.dart');
131 #source('interfaces.dart');
132 #source('map_matchers.dart');
133 #source('matcher.dart');
134 #source('numeric_matchers.dart');
135 #source('operator_matchers.dart');
136 #source('string_matchers.dart');
130 #source('test_case.dart'); 137 #source('test_case.dart');
131 138
132 /** [Configuration] used by the unittest library. */ 139 /** [Configuration] used by the unittest library. */
133 Configuration _config = null; 140 Configuration _config = null;
134 141
135 /** Set the [Configuration] used by the unittest library. */ 142 /** Set the [Configuration] used by the unittest library. */
136 void configure(Configuration config) { 143 void configure(Configuration config) {
137 _config = config; 144 _config = config;
138 } 145 }
139 146
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 int _state = _UNINITIALIZED; 179 int _state = _UNINITIALIZED;
173 String _uncaughtErrorMessage = null; 180 String _uncaughtErrorMessage = null;
174 181
175 final _PASS = 'pass'; 182 final _PASS = 'pass';
176 final _FAIL = 'fail'; 183 final _FAIL = 'fail';
177 final _ERROR = 'error'; 184 final _ERROR = 'error';
178 185
179 /** If set, then all other test cases will be ignored. */ 186 /** If set, then all other test cases will be ignored. */
180 TestCase _soloTest; 187 TestCase _soloTest;
181 188
182 /** Creates an expectation for the given value. */
183 Expectation expect(value) => new Expectation(value);
184
185 /** 189 /**
186 * Evaluates the [function] and validates that it throws an exception. If 190 * Evaluates the [function] and validates that it throws an exception. If
187 * [callback] is provided, then it will be invoked with the thrown exception. 191 * [callback] is provided, then it will be invoked with the thrown exception.
188 * The callback may do any validation it wants. In addition, if it returns 192 * The callback may do any validation it wants. In addition, if it returns
189 * `false`, that also indicates an expectation failure. 193 * `false`, that also indicates an expectation failure.
190 */ 194 */
191 void expectThrow(function, [bool callback(exception)]) { 195 void expectThrow(function, [bool callback(exception)]) {
192 bool threw = false; 196 bool threw = false;
193 try { 197 try {
194 function(); 198 function();
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 } 584 }
581 _config.onInit(); 585 _config.onInit();
582 586
583 // Immediately queue the suite up. It will run after a timeout (i.e. after 587 // Immediately queue the suite up. It will run after a timeout (i.e. after
584 // main() has returned). 588 // main() has returned).
585 _defer(_runTests); 589 _defer(_runTests);
586 } 590 }
587 591
588 /** Signature for a test function. */ 592 /** Signature for a test function. */
589 typedef void TestFunction(); 593 typedef void TestFunction();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698