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

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

Issue 10766005: Allow asynchronous tests to explicitly register exceptions along with stack traces. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 5 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 | utils/tests/pub/test_pub.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 * 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 651 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 }); 662 });
663 } 663 }
664 664
665 /** 665 /**
666 * Run [tryBody] guarded in a try-catch block. If an exception is thrown, update 666 * Run [tryBody] guarded in a try-catch block. If an exception is thrown, update
667 * the [_currentTest] status accordingly. 667 * the [_currentTest] status accordingly.
668 */ 668 */
669 guardAsync(tryBody, [finallyBody]) { 669 guardAsync(tryBody, [finallyBody]) {
670 try { 670 try {
671 return tryBody(); 671 return tryBody();
672 } catch (ExpectException e, var trace) { 672 } catch (var e, var trace) {
673 registerException(e, trace);
674 } finally {
675 _state = _READY;
676 if (finallyBody != null) finallyBody();
677 }
678 }
679
680 /**
681 * Registers that an exception was caught for the current test.
682 */
683 registerException(e, [trace]) {
684 if (e is ExpectException) {
673 Expect.isTrue(_currentTest < _tests.length); 685 Expect.isTrue(_currentTest < _tests.length);
674 if (_state != _UNCAUGHT_ERROR) { 686 if (_state != _UNCAUGHT_ERROR) {
675 _tests[_currentTest].fail(e.message, 687 _tests[_currentTest].fail(e.message,
676 trace == null ? '' : trace.toString()); 688 trace == null ? '' : trace.toString());
677 } 689 }
678 } catch (var e, var trace) { 690 } else {
679 if (_state == _RUNNING_TEST) { 691 if (_state == _RUNNING_TEST) {
680 // If a random exception is thrown from within a test, we consider that 692 // If a random exception is thrown from within a test, we consider that
681 // a test failure too. A test case implicitly has an expectation that it 693 // a test failure too. A test case implicitly has an expectation that it
682 // will run to completion without an uncaught exception being thrown. 694 // will run to completion without an uncaught exception being thrown.
683 _tests[_currentTest].fail('Caught $e', 695 _tests[_currentTest].fail('Caught $e',
684 trace == null ? '' : trace.toString()); 696 trace == null ? '' : trace.toString());
685 } else if (_state != _UNCAUGHT_ERROR) { 697 } else if (_state != _UNCAUGHT_ERROR) {
686 _tests[_currentTest].error('Caught $e', 698 _tests[_currentTest].error('Caught $e',
687 trace == null ? '' : trace.toString()); 699 trace == null ? '' : trace.toString());
688 } 700 }
689 } finally {
690 _state = _READY;
691 if (finallyBody != null) finallyBody();
692 } 701 }
693 } 702 }
694 703
695 /** 704 /**
696 * Runs a batch of tests, yielding whenever an asynchronous test starts 705 * Runs a batch of tests, yielding whenever an asynchronous test starts
697 * running. Tests will resume executing when such asynchronous test calls 706 * running. Tests will resume executing when such asynchronous test calls
698 * [done] or if it fails with an exception. 707 * [done] or if it fails with an exception.
699 */ 708 */
700 _nextBatch() { 709 _nextBatch() {
701 while (_currentTest < _tests.length) { 710 while (_currentTest < _tests.length) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 _config.onInit(); 777 _config.onInit();
769 778
770 // Immediately queue the suite up. It will run after a timeout (i.e. after 779 // Immediately queue the suite up. It will run after a timeout (i.e. after
771 // main() has returned). 780 // main() has returned).
772 _defer(_runTests); 781 _defer(_runTests);
773 } 782 }
774 783
775 /** Signature for a test function. */ 784 /** Signature for a test function. */
776 typedef void TestFunction(); 785 typedef void TestFunction();
777 786
OLDNEW
« no previous file with comments | « no previous file | utils/tests/pub/test_pub.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698