Bug 483407 - Improve the "mochitest*" harness; (Av1a) SimpleTest.js: Report tests which did not actually check anything, Improve ToDo support; r=dbaron
--- 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,