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

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

Issue 10946038: Fixed a nasty bug in unittest, where is we have a non-async test that throws an exception, followed… (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/test/unittest_test.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 741 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 * Registers that an exception was caught for the current test. 752 * Registers that an exception was caught for the current test.
753 */ 753 */
754 _registerException(testNum, e, [trace]) { 754 _registerException(testNum, e, [trace]) {
755 trace = trace == null ? '' : trace.toString(); 755 trace = trace == null ? '' : trace.toString();
756 if (_tests[testNum].result == null) { 756 if (_tests[testNum].result == null) {
757 String message = (e is ExpectException) ? e.message : 'Caught $e'; 757 String message = (e is ExpectException) ? e.message : 'Caught $e';
758 _tests[testNum].fail(message, trace); 758 _tests[testNum].fail(message, trace);
759 } else { 759 } else {
760 _tests[testNum].error('Caught $e', trace); 760 _tests[testNum].error('Caught $e', trace);
761 } 761 }
762 if (testNum == _currentTest) { 762 if (testNum == _currentTest &&
763 _tests[testNum].callbackFunctionsOutstanding > 0) {
763 _nextTestCase(); 764 _nextTestCase();
764 } 765 }
765 } 766 }
766 767
767 /** 768 /**
768 * Runs a batch of tests, yielding whenever an asynchronous test starts 769 * Runs a batch of tests, yielding whenever an asynchronous test starts
769 * running. Tests will resume executing when such asynchronous test calls 770 * running. Tests will resume executing when such asynchronous test calls
770 * [done] or if it fails with an exception. 771 * [done] or if it fails with an exception.
771 */ 772 */
772 _nextBatch() { 773 _nextBatch() {
773 while (_currentTest < _tests.length) { 774 while (_currentTest < _tests.length) {
774 final testCase = _tests[_currentTest]; 775 final testCase = _tests[_currentTest];
775 guardAsync(() { 776 guardAsync(() {
776 testCase.run(); 777 testCase.run();
777 if (!testCase.isComplete && testCase.callbackFunctionsOutstanding == 0) { 778 if (!testCase.isComplete && testCase.callbackFunctionsOutstanding == 0) {
778 testCase.pass(); 779 testCase.pass();
779 } 780 }
780 }, testNum:_currentTest); 781 }, testNum:_currentTest);
781 782
782 if (!testCase.isComplete && 783 if (!testCase.isComplete &&
783 testCase.callbackFunctionsOutstanding > 0) return; 784 testCase.callbackFunctionsOutstanding > 0) return;
784 _currentTest++; 785 _currentTest++;
785 } 786 }
786 787
787 _completeTests(); 788 _completeTests();
788 } 789 }
789 790
790 /** Publish results on the page and notify controller. */ 791 /** Publish results on the page and notify controller. */
791 _completeTests() { 792 _completeTests() {
793 if (!_initialized) return;
792 int testsPassed_ = 0; 794 int testsPassed_ = 0;
793 int testsFailed_ = 0; 795 int testsFailed_ = 0;
794 int testsErrors_ = 0; 796 int testsErrors_ = 0;
795 797
796 for (TestCase t in _tests) { 798 for (TestCase t in _tests) {
797 switch (t.result) { 799 switch (t.result) {
798 case _PASS: testsPassed_++; break; 800 case _PASS: testsPassed_++; break;
799 case _FAIL: testsFailed_++; break; 801 case _FAIL: testsFailed_++; break;
800 case _ERROR: testsErrors_++; break; 802 case _ERROR: testsErrors_++; break;
801 } 803 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 } 867 }
866 868
867 /** Enable a test by ID. */ 869 /** Enable a test by ID. */
868 void enableTest(int testId) => _setTestEnabledState(testId, true); 870 void enableTest(int testId) => _setTestEnabledState(testId, true);
869 871
870 /** Disable a test by ID. */ 872 /** Disable a test by ID. */
871 void disableTest(int testId) => _setTestEnabledState(testId, false); 873 void disableTest(int testId) => _setTestEnabledState(testId, false);
872 874
873 /** Signature for a test function. */ 875 /** Signature for a test function. */
874 typedef void TestFunction(); 876 typedef void TestFunction();
OLDNEW
« no previous file with comments | « pkg/unittest/test/unittest_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698