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

Side by Side Diff: client/testing/unittest/shared.dart

Issue 8905021: Dartest CL - Please review (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years 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 | « client/testing/dartest/resources/min.png ('k') | client/testing/unittest/unittest.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) 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 * Description text of the current test group. If multiple groups are nested, 6 * Description text of the current test group. If multiple groups are nested,
7 * this will contain all of their text concatenated. 7 * this will contain all of their text concatenated.
8 */ 8 */
9 String _currentGroup = ''; 9 String _currentGroup = '';
10 10
11 /** Tests executed in this suite. */ 11 /** Tests executed in this suite. */
12 List<TestCase> _tests; 12 List<TestCase> _tests;
13 13
14 /**
15 * Callback used to run tests. Entrypoints can replace this with their own
16 * if they want.
17 */
18 Function _testRunner;
19
14 /** Whether this is run within dartium layout tests. */ 20 /** Whether this is run within dartium layout tests. */
15 bool _isLayoutTest = false; 21 bool _isLayoutTest = false;
16 22
17 /** Current test being executed. */ 23 /** Current test being executed. */
18 int _currentTest = 0; 24 int _currentTest = 0;
19 25
20 /** Total number of callbacks that have been executed in the current test. */ 26 /** Total number of callbacks that have been executed in the current test. */
21 int _callbacksCalled = 0; 27 int _callbacksCalled = 0;
22 28
23 final _UNINITIALIZED = 0; 29 final _UNINITIALIZED = 0;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 } else if (_callbacksCalled > testCase.callbacks) { 137 } else if (_callbacksCalled > testCase.callbacks) {
132 final expected = testCase.callbacks; 138 final expected = testCase.callbacks;
133 testCase.error( 139 testCase.error(
134 'More calls to callbackDone() than expected. ' 140 'More calls to callbackDone() than expected. '
135 + 'Actual: ${_callbacksCalled}, expected: ${expected}', ''); 141 + 'Actual: ${_callbacksCalled}, expected: ${expected}', '');
136 _state = _UNCAUGHT_ERROR; 142 _state = _UNCAUGHT_ERROR;
137 } else if ((_callbacksCalled == testCase.callbacks) && 143 } else if ((_callbacksCalled == testCase.callbacks) &&
138 (_state != _RUNNING_TEST)) { 144 (_state != _RUNNING_TEST)) {
139 testCase.pass(); 145 testCase.pass();
140 _currentTest++; 146 _currentTest++;
141 _nextBatch(); 147 _testRunner();
142 } 148 }
143 } 149 }
144 150
145 void forLayoutTests() { 151 void forLayoutTests() {
146 _isLayoutTest = true; 152 _isLayoutTest = true;
147 } 153 }
148 154
149 /** Runs all queued tests, one at a time. */ 155 /** Runs all queued tests, one at a time. */
150 _runTests() { 156 _runTests() {
151 _platformStartTests(); 157 _platformStartTests();
152 158
153 _platformDefer(() { 159 _platformDefer(() {
154 assert (_currentTest == 0); 160 assert (_currentTest == 0);
155 _nextBatch(); 161 _testRunner();
156 }); 162 });
157 } 163 }
158 164
159 /** Runs a single test. */ 165 /** Runs a single test. */
160 _runTest(TestCase testCase) { 166 _runTest(TestCase testCase) {
161 try { 167 try {
162 _callbacksCalled = 0; 168 _callbacksCalled = 0;
163 _state = _RUNNING_TEST; 169 _state = _RUNNING_TEST;
164 170
165 testCase.test(); 171 testCase.test();
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 236
231 /** 237 /**
232 * Lazily initializes the test library if not already initialized. 238 * Lazily initializes the test library if not already initialized.
233 */ 239 */
234 _ensureInitialized() { 240 _ensureInitialized() {
235 if (_state != _UNINITIALIZED) return; 241 if (_state != _UNINITIALIZED) return;
236 242
237 _tests = <TestCase>[]; 243 _tests = <TestCase>[];
238 _currentGroup = ''; 244 _currentGroup = '';
239 _state = _READY; 245 _state = _READY;
240 246 _testRunner = _nextBatch;
247
241 _platformInitialize(); 248 _platformInitialize();
242 249
243 // Immediately queue the suite up. It will run after a timeout (i.e. after 250 // Immediately queue the suite up. It will run after a timeout (i.e. after
244 // main() has returned). 251 // main() has returned).
245 _platformDefer(_runTests); 252 _platformDefer(_runTests);
246 } 253 }
247 254
248 /** 255 /**
249 * Wraps an value and provides an "==" operator that can be used to verify that 256 * Wraps an value and provides an "==" operator that can be used to verify that
250 * the value matches a given expectation. 257 * the value matches a given expectation.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 /** Error or failure message. */ 327 /** Error or failure message. */
321 String message = ''; 328 String message = '';
322 329
323 /** 330 /**
324 * One of [_PASS], [_FAIL], or [_ERROR] or [null] if the test hasn't run yet. 331 * One of [_PASS], [_FAIL], or [_ERROR] or [null] if the test hasn't run yet.
325 */ 332 */
326 String result; 333 String result;
327 334
328 /** Stack trace associated with this test, or null if it succeeded. */ 335 /** Stack trace associated with this test, or null if it succeeded. */
329 String stackTrace; 336 String stackTrace;
337
338 Date startTime;
339
340 Duration runningTime;
330 341
331 TestCase(this.id, this.description, this.test, this.callbacks); 342 TestCase(this.id, this.description, this.test, this.callbacks);
332 343
333 bool get isComplete() => result != null; 344 bool get isComplete() => result != null;
334 345
335 void pass() { 346 void pass() {
336 result = _PASS; 347 result = _PASS;
337 } 348 }
338 349
339 void fail(String message, String stackTrace) { 350 void fail(String message, String stackTrace) {
340 result = _FAIL; 351 result = _FAIL;
341 this.message = message; 352 this.message = message;
342 this.stackTrace = stackTrace; 353 this.stackTrace = stackTrace;
343 } 354 }
344 355
345 void error(String message, String stackTrace) { 356 void error(String message, String stackTrace) {
346 result = _ERROR; 357 result = _ERROR;
347 this.message = message; 358 this.message = message;
348 this.stackTrace = stackTrace; 359 this.stackTrace = stackTrace;
349 } 360 }
350 } 361 }
351 362
352 typedef void TestFunction(); 363 typedef void TestFunction();
OLDNEW
« no previous file with comments | « client/testing/dartest/resources/min.png ('k') | client/testing/unittest/unittest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698