Bug 483407 - Improve the "mochitest*" harness; (Av1a) SimpleTest.js: Report tests which did not actually check anything, Improve ToDo support; r=dbaron
authorSerge Gautherie <sgautherie.bz@free.fr>
Tue, 12 May 2009 03:38:29 +0200
changeset 28213 9cbd47d7b0251d0e4d193789c3def2c6c062726a
parent 28212 aa3a28d8eb76653d061bb2d07ac6fe94c0e9f17b
child 28214 dc5f29ebaf2e6cb60792371bb35fc39b04e61b8a
push id6946
push usersgautherie.bz@free.fr
push dateTue, 12 May 2009 01:40:25 +0000
treeherdermozilla-central@dc5f29ebaf2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron
bugs483407
milestone1.9.2a1pre
Bug 483407 - Improve the "mochitest*" harness; (Av1a) SimpleTest.js: Report tests which did not actually check anything, Improve ToDo support; r=dbaron
testing/mochitest/tests/SimpleTest/SimpleTest.js
--- a/testing/mochitest/tests/SimpleTest/SimpleTest.js
+++ b/testing/mochitest/tests/SimpleTest/SimpleTest.js
@@ -102,37 +102,46 @@ SimpleTest.todo_isnot = function (a, b, 
 /**
  * Makes a test report, returns it as a DIV element.
 **/
 SimpleTest.report = function () {
     var DIV = MochiKit.DOM.DIV;
     var passed = 0;
     var failed = 0;
     var todo = 0;
+
+    // Report tests which did not actually check anything.
+    if (SimpleTest._tests.length == 0)
+      // ToDo: Do s/todo/ok/ when all the tests are fixed. (Bug 483407)
+      SimpleTest.todo(false, "[SimpleTest.report()] No checks actually run.");
+
     var results = MochiKit.Base.map(
         function (test) {
             var cls, msg;
             if (test.todo && !test.result) {
                 todo++;
                 cls = "test_todo";
                 msg = "todo - " + test.name + " " + test.diag;
-            } else if (test.result &&!test.todo) {
+            } else if (test.result && !test.todo) {
                 passed++;
                 cls = "test_ok";
                 msg = "ok - " + test.name;
             } else {
                 failed++;
                 cls = "test_not_ok";
                 msg = "not ok - " + test.name + " " + test.diag;
             }
             return DIV({"class": cls}, msg);
         },
         SimpleTest._tests
     );
-    var summary_class = ((failed == 0) ? 'all_pass' : 'some_fail');
+
+    var summary_class = failed != 0 ? 'some_fail' :
+                          passed == 0 ? 'todo_only' : 'all_pass';
+
     return DIV({'class': 'tests_report'},
         DIV({'class': 'tests_summary ' + summary_class},
             DIV({'class': 'tests_passed'}, "Passed: " + passed),
             DIV({'class': 'tests_failed'}, "Failed: " + failed),
             DIV({'class': 'tests_todo'}, "Todo: " + todo)),
         results
     );
 };
@@ -158,20 +167,22 @@ SimpleTest.toggleByClass = function (cls
         evt.preventDefault();
 };
 
 /**
  * Shows the report in the browser
 **/
 
 SimpleTest.showReport = function() {
-    var togglePassed = A({'href': '#'}, "Toggle passed tests");
-    var toggleFailed = A({'href': '#'}, "Toggle failed tests");
+    var togglePassed = A({'href': '#'}, "Toggle passed checks");
+    var toggleFailed = A({'href': '#'}, "Toggle failed checks");
+    var toggleTodo = A({'href': '#'}, "Toggle todo checks");
     togglePassed.onclick = partial(SimpleTest.toggleByClass, 'test_ok');
     toggleFailed.onclick = partial(SimpleTest.toggleByClass, 'test_not_ok');
+    toggleTodo.onclick = partial(SimpleTest.toggleByClass, 'test_todo');
     var body = document.body;  // Handles HTML documents
     if (!body) {
 	// Do the XML thing
 	body = document.getElementsByTagNameNS("http://www.w3.org/1999/xhtml",
 					       "body")[0]
     }
     var firstChild = body.childNodes[0];
     var addNode;
@@ -182,16 +193,18 @@ SimpleTest.showReport = function() {
     } else {
         addNode = function (el) {
             body.appendChild(el)
         };
     }
     addNode(togglePassed);
     addNode(SPAN(null, " "));
     addNode(toggleFailed);
+    addNode(SPAN(null, " "));
+    addNode(toggleTodo);
     addNode(SimpleTest.report());
 };
 
 /**
  * Tells SimpleTest to don't finish the test when the document is loaded,
  * useful for asynchronous tests.
  *
  * When SimpleTest.waitForExplicitFinish is called,