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 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
716 | 716 |
717 /** | 717 /** |
718 * Run [tryBody] guarded in a try-catch block. If an exception is thrown, update | 718 * Run [tryBody] guarded in a try-catch block. If an exception is thrown, update |
719 * the [_currentTest] status accordingly. | 719 * the [_currentTest] status accordingly. |
720 */ | 720 */ |
721 guardAsync(tryBody, [finallyBody, testNum = -1]) { | 721 guardAsync(tryBody, [finallyBody, testNum = -1]) { |
722 if (testNum < 0) testNum = _currentTest; | 722 if (testNum < 0) testNum = _currentTest; |
723 try { | 723 try { |
724 return tryBody(); | 724 return tryBody(); |
725 } catch (var e, var trace) { | 725 } catch (var e, var trace) { |
726 registerException(testNum, e, trace); | 726 _registerException(testNum, e, trace); |
727 } finally { | 727 } finally { |
728 if (finallyBody != null) finallyBody(); | 728 if (finallyBody != null) finallyBody(); |
729 } | 729 } |
730 } | 730 } |
731 | 731 |
732 /** | 732 /** |
733 * Registers that an exception was caught for the current test. | 733 * Registers that an exception was caught for the current test. |
734 */ | 734 */ |
735 registerException(testNum, e, [trace]) { | 735 registerException(e, [trace]) { |
| 736 _registerException(_currentTest, e, trace); |
| 737 } |
| 738 |
| 739 /** |
| 740 * Registers that an exception was caught for the current test. |
| 741 */ |
| 742 _registerException(testNum, e, [trace]) { |
736 trace = trace == null ? '' : trace.toString(); | 743 trace = trace == null ? '' : trace.toString(); |
737 if (_tests[testNum].result == null) { | 744 if (_tests[testNum].result == null) { |
738 String message = (e is ExpectException) ? e.message : 'Caught $e'; | 745 String message = (e is ExpectException) ? e.message : 'Caught $e'; |
739 _tests[testNum].fail(message, trace); | 746 _tests[testNum].fail(message, trace); |
740 } else { | 747 } else { |
741 _tests[testNum].error('Caught $e', trace); | 748 _tests[testNum].error('Caught $e', trace); |
742 } | 749 } |
743 if (testNum == _currentTest) { | 750 if (testNum == _currentTest) { |
744 _nextTestCase(); | 751 _nextTestCase(); |
745 } | 752 } |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
844 } | 851 } |
845 | 852 |
846 /** Enable a test by ID. */ | 853 /** Enable a test by ID. */ |
847 void enableTest(int testId) => _setTestEnabledState(testId, true); | 854 void enableTest(int testId) => _setTestEnabledState(testId, true); |
848 | 855 |
849 /** Disable a test by ID. */ | 856 /** Disable a test by ID. */ |
850 void disableTest(int testId) => _setTestEnabledState(testId, false); | 857 void disableTest(int testId) => _setTestEnabledState(testId, false); |
851 | 858 |
852 /** Signature for a test function. */ | 859 /** Signature for a test function. */ |
853 typedef void TestFunction(); | 860 typedef void TestFunction(); |
OLD | NEW |