|
1 | 1 | /*!
|
2 | 2 | * Tyrtle - A JavaScript Unit Testing Framework
|
3 | 3 | *
|
4 |
| - * Copyright (c) 2011 Nick Fisher |
| 4 | + * Copyright (c) 2011-2012 Nick Fisher |
5 | 5 | * Distributed under the terms of the LGPL
|
6 | 6 | * http://www.gnu.org/licenses/lgpl.html
|
7 | 7 | */
|
|
26 | 26 | setParams,
|
27 | 27 | root,
|
28 | 28 | runningInNode,
|
29 |
| - moduleAssertions = null, // the extra assertions added by an individual module |
30 |
| - currentTestAssertions // a counter for the number of assertions run in an individual test |
| 29 | + unexecutedAssertions = 0, // the count of assertions created minus the number of assertions executed. |
| 30 | + moduleAssertions = null, // the extra assertions added by an individual module |
| 31 | + currentTestAssertions // a counter for the number of assertions run in an individual test |
31 | 32 | ;
|
32 | 33 | // Gets the global object, regardless of whether run as ES3, ES5 or ES5 Strict Mode.
|
33 | 34 | root = (function () {
|
|
784 | 785 | * @protected
|
785 | 786 | */
|
786 | 787 | run : function (callback) {
|
787 |
| - var start, success, handleError, test = this; |
| 788 | + var start, success, handleError, test = this, originalUnexecutedAssertions; |
788 | 789 | success = function () {
|
789 | 790 | test.runTime = new Date() - start;
|
790 | 791 | test.status = PASS;
|
|
812 | 813 | this.body(function (variables) {
|
813 | 814 | variables = variables || {};
|
814 | 815 | try {
|
815 |
| - currentTestAssertions = 0; // this is incremented by the `since` function |
| 816 | + // this is incremented by the `since` function |
| 817 | + currentTestAssertions = 0; |
| 818 | + |
| 819 | + // remember how many unexecuted assertion there were at the start |
| 820 | + originalUnexecutedAssertions = unexecutedAssertions; |
816 | 821 | test.asyncFn.call(variables, assert);
|
| 822 | + |
817 | 823 | if (test.expectedAssertions !== -1) {
|
818 | 824 | assert.that(currentTestAssertions)
|
819 | 825 | .is(test.expectedAssertions)
|
820 | 826 | .since("Incorrect number of assertions made by this test.")
|
821 | 827 | ;
|
822 | 828 | }
|
| 829 | + // check that no assertions were left unexecuted. |
| 830 | + assert |
| 831 | + .that(unexecutedAssertions - originalUnexecutedAssertions) |
| 832 | + .is(0) |
| 833 | + .since("This test defines assertions which are never executed"); |
| 834 | + |
823 | 835 | success();
|
824 | 836 | } catch (ee) {
|
825 | 837 | handleError(ee);
|
826 | 838 | }
|
827 | 839 | });
|
828 | 840 | } else {
|
829 | 841 | currentTestAssertions = 0;
|
| 842 | + originalUnexecutedAssertions = unexecutedAssertions; |
830 | 843 | this.body(assert);
|
831 | 844 | if (test.expectedAssertions !== -1) {
|
832 | 845 | assert.that(currentTestAssertions)
|
833 | 846 | .is(test.expectedAssertions)
|
834 | 847 | .since("Incorrect number of assertions made by this test.")
|
835 | 848 | ;
|
836 | 849 | }
|
| 850 | + // check that no assertions were left unexecuted. |
| 851 | + assert |
| 852 | + .that(unexecutedAssertions - originalUnexecutedAssertions) |
| 853 | + .is(0) |
| 854 | + .since("This test defines assertions which are never executed"); |
837 | 855 | success();
|
838 | 856 | }
|
839 | 857 | } catch (e) {
|
|
887 | 905 | // Assertions //
|
888 | 906 | //////////////////
|
889 | 907 | (function () {
|
890 |
| - var assertions, build, handleAssertionResult, internalAssertionCount = 0; |
| 908 | + var assertions, |
| 909 | + build, |
| 910 | + handleAssertionResult, |
| 911 | + internalAssertionCount = 0; |
891 | 912 | assertions = {
|
892 | 913 | /**
|
893 | 914 | * Assert that two values are not identical. Uses strict equality checking: `!==`.
|
|
1273 | 1294 | */
|
1274 | 1295 | build = function (condition, message/*, args */) {
|
1275 | 1296 | var args = Array.prototype.slice.call(arguments, 2),
|
1276 |
| - since |
1277 |
| - ; |
| 1297 | + since; |
| 1298 | + ++unexecutedAssertions; |
1278 | 1299 | since = function (userMessage) {
|
1279 | 1300 | try {
|
1280 | 1301 | if (internalAssertionCount++ === 0) {
|
1281 | 1302 | ++currentTestAssertions;
|
1282 | 1303 | }
|
| 1304 | + // if this is the first time we've executed this assertion, then decrease the counter, and don't count this |
| 1305 | + // one again |
| 1306 | + if (!since.executed) { |
| 1307 | + --unexecutedAssertions; |
| 1308 | + since.executed = true; |
| 1309 | + } |
1283 | 1310 | handleAssertionResult(condition.apply(assert, args), args, message, userMessage);
|
1284 | 1311 | } finally {
|
1285 | 1312 | --internalAssertionCount;
|
1286 | 1313 | }
|
1287 | 1314 | };
|
| 1315 | + since.executed = false; |
1288 | 1316 | since.since = since;
|
1289 | 1317 | return since;
|
1290 | 1318 | };
|
|
0 commit comments