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

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

Issue 10948005: Reverting 12485 and 12480 just for the sake of mocking, (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 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 | « pkg/unittest/mock.dart ('k') | 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, specify the relative path to 8 * To import this library, specify the relative path to
9 * pkg/unittest/unittest.dart. 9 * pkg/unittest/unittest.dart.
10 * 10 *
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 if (_soloTest != null) { 286 if (_soloTest != null) {
287 throw new Exception('Only one test can be soloed right now.'); 287 throw new Exception('Only one test can be soloed right now.');
288 } 288 }
289 289
290 ensureInitialized(); 290 ensureInitialized();
291 291
292 _soloTest = new TestCase(_tests.length + 1, _fullSpec(spec), body, 0); 292 _soloTest = new TestCase(_tests.length + 1, _fullSpec(spec), body, 0);
293 _tests.add(_soloTest); 293 _tests.add(_soloTest);
294 } 294 }
295 295
296 /** Sentinel value for [_SpreadArgsHelper]. */
297 class _Sentinel {
298 const _Sentinel();
299 }
300
301 // TODO(sigmund): make a singleton const field when frog supports passing those
302 // as default values to named arguments.
303 const _sentinel = const _Sentinel();
304
296 /** Simulates spread arguments using named arguments. */ 305 /** Simulates spread arguments using named arguments. */
297 // TODO(sigmund): remove this class and simply use a closure with named 306 // TODO(sigmund): remove this class and simply use a closure with named
298 // arguments (if still applicable). 307 // arguments (if still applicable).
299 class _SpreadArgsHelper { 308 class _SpreadArgsHelper {
300 Function _callback; 309 Function _callback;
301 int _expectedCalls; 310 int _expectedCalls;
302 int _actualCalls = 0; 311 int _actualCalls = 0;
303 int _testNum; 312 int _testNum;
304 TestCase _testCase; 313 TestCase _testCase;
305 Function _shouldCallBack; 314 Function _shouldCallBack;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 if (_testCase.isComplete) { 358 if (_testCase.isComplete) {
350 _testCase.error( 359 _testCase.error(
351 'Callback called after already being marked as done ($_actualCalls).', 360 'Callback called after already being marked as done ($_actualCalls).',
352 ''); 361 '');
353 return false; 362 return false;
354 } else { 363 } else {
355 return true; 364 return true;
356 } 365 }
357 } 366 }
358 367
359 invoke([arg0, arg1, arg2, arg3, arg4]) { 368 invoke([arg0 = _sentinel, arg1 = _sentinel, arg2 = _sentinel,
369 arg3 = _sentinel, arg4 = _sentinel]) {
360 return guardAsync(() { 370 return guardAsync(() {
361 ++_actualCalls; 371 ++_actualCalls;
362 if (!_shouldCallBack()) return; 372 if (!_shouldCallBack()) {
363 if (!?arg0) return _callback(); 373 return;
364 if (!?arg1) return _callback(arg0); 374 } else if (arg0 == _sentinel) {
365 if (!?arg2) return _callback(arg0, arg1); 375 return _callback();
366 if (!?arg3) return _callback(arg0, arg1, arg2); 376 } else if (arg1 == _sentinel) {
367 if (!?arg4) return _callback(arg0, arg1, arg2, arg3); 377 return _callback(arg0);
368 _testCase.error( 378 } else if (arg2 == _sentinel) {
369 'unittest lib does not support callbacks with more than' 379 return _callback(arg0, arg1);
370 ' 4 arguments.', 380 } else if (arg3 == _sentinel) {
371 ''); 381 return _callback(arg0, arg1, arg2);
372 }, 382 } else if (arg4 == _sentinel) {
373 _after, _testNum); 383 return _callback(arg0, arg1, arg2, arg3);
384 } else {
385 _testCase.error(
386 'unittest lib does not support callbacks with more than'
387 ' 4 arguments.',
388 '');
389 }
390 },
391 _after, _testNum);
374 } 392 }
375 393
376 invoke0() { 394 invoke0() {
377 return guardAsync( 395 return guardAsync(
378 () { 396 () {
379 ++_actualCalls; 397 ++_actualCalls;
380 if (_shouldCallBack()) { 398 if (_shouldCallBack()) {
381 return _callback(); 399 return _callback();
382 } 400 }
383 }, 401 },
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 } 865 }
848 866
849 /** Enable a test by ID. */ 867 /** Enable a test by ID. */
850 void enableTest(int testId) => _setTestEnabledState(testId, true); 868 void enableTest(int testId) => _setTestEnabledState(testId, true);
851 869
852 /** Disable a test by ID. */ 870 /** Disable a test by ID. */
853 void disableTest(int testId) => _setTestEnabledState(testId, false); 871 void disableTest(int testId) => _setTestEnabledState(testId, false);
854 872
855 /** Signature for a test function. */ 873 /** Signature for a test function. */
856 typedef void TestFunction(); 874 typedef void TestFunction();
OLDNEW
« no previous file with comments | « pkg/unittest/mock.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698