OLD | NEW |
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 * |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 _handleAllCallbacksDone(); | 353 _handleAllCallbacksDone(); |
354 } | 354 } |
355 } | 355 } |
356 | 356 |
357 _allCallsDone() => _calls == _expectedCalls; | 357 _allCallsDone() => _calls == _expectedCalls; |
358 | 358 |
359 _always() { | 359 _always() { |
360 // Always run except if the test is done. | 360 // Always run except if the test is done. |
361 if (_testCase.isComplete) { | 361 if (_testCase.isComplete) { |
362 _testCase.error( | 362 _testCase.error( |
363 'Callback called after already being marked as done ($_calls)', | 363 'Callback called after already being marked as done ($_calls).', |
364 ''); | 364 ''); |
365 _state = _UNCAUGHT_ERROR; | 365 _state = _UNCAUGHT_ERROR; |
366 return false; | 366 return false; |
367 } else { | 367 } else { |
368 return true; | 368 return true; |
369 } | 369 } |
370 } | 370 } |
371 | 371 |
372 invoke([arg0 = _sentinel, arg1 = _sentinel, arg2 = _sentinel, | 372 invoke([arg0 = _sentinel, arg1 = _sentinel, arg2 = _sentinel, |
373 arg3 = _sentinel, arg4 = _sentinel]) { | 373 arg3 = _sentinel, arg4 = _sentinel]) { |
374 return guardAsync(() { | 374 return guardAsync(() { |
375 ++_calls; | 375 ++_calls; |
376 if (!_shouldCallBack()) { | 376 if (!_shouldCallBack()) { |
377 return; | 377 return; |
378 } else if (arg0 == _sentinel) { | 378 } else if (arg0 == _sentinel) { |
379 return _callback(); | 379 return _callback(); |
380 } else if (arg1 == _sentinel) { | 380 } else if (arg1 == _sentinel) { |
381 return _callback(arg0); | 381 return _callback(arg0); |
382 } else if (arg2 == _sentinel) { | 382 } else if (arg2 == _sentinel) { |
383 return _callback(arg0, arg1); | 383 return _callback(arg0, arg1); |
384 } else if (arg3 == _sentinel) { | 384 } else if (arg3 == _sentinel) { |
385 return _callback(arg0, arg1, arg2); | 385 return _callback(arg0, arg1, arg2); |
386 } else if (arg4 == _sentinel) { | 386 } else if (arg4 == _sentinel) { |
387 return _callback(arg0, arg1, arg2, arg3); | 387 return _callback(arg0, arg1, arg2, arg3); |
388 } else { | 388 } else { |
389 _testCase.error( | 389 _testCase.error( |
390 'unittest lib does not support callbacks with more than 4 arguments', | 390 'unittest lib does not support callbacks with more than' |
| 391 ' 4 arguments.', |
391 ''); | 392 ''); |
392 _state = _UNCAUGHT_ERROR; | 393 _state = _UNCAUGHT_ERROR; |
393 } | 394 } |
394 }, | 395 }, |
395 _after); | 396 _after); |
396 } | 397 } |
397 | 398 |
398 invoke0() { | 399 invoke0() { |
399 return guardAsync( | 400 return guardAsync( |
400 () { | 401 () { |
(...skipping 25 matching lines...) Expand all Loading... |
426 } | 427 } |
427 }, | 428 }, |
428 _after); | 429 _after); |
429 } | 430 } |
430 | 431 |
431 /** Returns false if we exceded the number of expected calls. */ | 432 /** Returns false if we exceded the number of expected calls. */ |
432 bool _checkCallCount() { | 433 bool _checkCallCount() { |
433 if (_calls > _expectedCalls) { | 434 if (_calls > _expectedCalls) { |
434 _testCase.error( | 435 _testCase.error( |
435 'Callback called more times than expected ' | 436 'Callback called more times than expected ' |
436 '($_calls > $_expectedCalls)', | 437 '($_calls > $_expectedCalls).', |
437 ''); | 438 ''); |
438 _state = _UNCAUGHT_ERROR; | 439 _state = _UNCAUGHT_ERROR; |
439 return false; | 440 return false; |
440 } | 441 } |
441 return true; | 442 return true; |
442 } | 443 } |
443 } | 444 } |
444 | 445 |
445 /** | 446 /** |
446 * Indicate that [callback] is expected to be called a [count] number of times | 447 * Indicate that [callback] is expected to be called a [count] number of times |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 // which is recursively invoked in the case of async tests that | 586 // which is recursively invoked in the case of async tests that |
586 // run synchronously. Bad things can then happen. | 587 // run synchronously. Bad things can then happen. |
587 _defer(() { | 588 _defer(() { |
588 _callbacksCalled++; | 589 _callbacksCalled++; |
589 if (_currentTest < _tests.length) { | 590 if (_currentTest < _tests.length) { |
590 final testCase = _tests[_currentTest]; | 591 final testCase = _tests[_currentTest]; |
591 if (_callbacksCalled > testCase.callbacks) { | 592 if (_callbacksCalled > testCase.callbacks) { |
592 final expected = testCase.callbacks; | 593 final expected = testCase.callbacks; |
593 testCase.error( | 594 testCase.error( |
594 'More calls to _handleAllCallbacksDone() than expected. ' | 595 'More calls to _handleAllCallbacksDone() than expected. ' |
595 'Actual: ${_callbacksCalled}, expected: ${expected}', ''); | 596 'Actual: ${_callbacksCalled}, expected: ${expected}.', ''); |
596 _state = _UNCAUGHT_ERROR; | 597 _state = _UNCAUGHT_ERROR; |
597 } else if ((_callbacksCalled == testCase.callbacks) && | 598 } else if ((_callbacksCalled == testCase.callbacks) && |
598 (_state != _RUNNING_TEST)) { | 599 (_state != _RUNNING_TEST)) { |
599 if (testCase.result == null) { | 600 if (testCase.result == null) { |
600 testCase.pass(); | 601 testCase.pass(); |
601 } | 602 } |
602 _currentTest++; | 603 _currentTest++; |
603 _testRunner(); | 604 _testRunner(); |
604 } | 605 } |
605 } | 606 } |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 _config.onInit(); | 778 _config.onInit(); |
778 | 779 |
779 // Immediately queue the suite up. It will run after a timeout (i.e. after | 780 // Immediately queue the suite up. It will run after a timeout (i.e. after |
780 // main() has returned). | 781 // main() has returned). |
781 _defer(_runTests); | 782 _defer(_runTests); |
782 } | 783 } |
783 | 784 |
784 /** Signature for a test function. */ | 785 /** Signature for a test function. */ |
785 typedef void TestFunction(); | 786 typedef void TestFunction(); |
786 | 787 |
OLD | NEW |