From ef13835bfedd532f7948483ed199c58a8f1b9a54 Mon Sep 17 00:00:00 2001 From: Robert Konigsberg Date: Sat, 7 Jan 2012 10:15:45 -0500 Subject: [PATCH] Can run all tests in one fell swoop. --- auto_tests/misc/local.html | 69 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 17 deletions(-) diff --git a/auto_tests/misc/local.html b/auto_tests/misc/local.html index a7efaf6..d24cab8 100644 --- a/auto_tests/misc/local.html +++ b/auto_tests/misc/local.html @@ -62,6 +62,7 @@ var test = args.test; var command = args.command; + // args.testCaseName uses the string name of the test. if (args.testCaseName) { var testCases = getAllTestCases(); name = args.testCaseName; @@ -73,28 +74,49 @@ break; } } - } else if (args.testCase) { + } else if (args.testCase) { // The class name of the test. name = args.testCase; eval("tc = new " + args.testCase + "()"); } + + // If the test class is defined. if (tc != null) { - if (args.command) { - if (args.command == "runAllTests") { - console.log("Running all tests for " + args.testCase); - postResults(tc.runAllTests()); - } - if (args.command == "runTest") { - console.log("Running test " + args.testCase + "." + args.test); - postResults(tc.runTest(args.test)); + if (args.command == "runAllTests") { + console.log("Running all tests for " + args.testCase); + postResults(tc.runAllTests()); + } + if (args.command == "runTest") { + console.log("Running test " + args.testCase + "." + args.test); + postResults(tc.runTest(args.test)); + } + } else { + if (args.command == "runAllTests") { + console.log("Running all tests for all test cases"); + var testCases = getAllTestCases(); + var results = {}; + for (var idx in testCases) { + var entry = testCases[idx]; + var prototype = entry.testCase; + tc = new entry.testCase(); + results[entry.name] = tc.runAllTests(); } + postResults(results); } } } - function postResults(results) { - var body = document.getElementsByTagName("body")[0]; - var div = document.createElement("div"); - body.insertBefore(div, body.firstChild); + function postResults(results, title, div) { + var first = false; + if (div == null) { + var body = document.getElementsByTagName("body")[0]; + div = document.createElement("div"); + div.innerHTML = "Test results:"; + if (typeof(results) != "boolean"); { + div.innerHTML = "Test results:
"; + } + body.insertBefore(div, body.firstChild); + first = true; + } var resultToHtml = function(result) { return result ? @@ -103,17 +125,29 @@ } if (typeof(results) == "boolean") { - div.innerHTML = "Test results: " + resultToHtml(results); + var elem = document.createElement("div"); + if (title) { + elem.innerHTML = title + ": " + resultToHtml(results); + } else { + elem.innerHTML = resultToHtml(results); + } + div.appendChild(elem); } else { // hash var html = ""; for (var key in results) { if (results.hasOwnProperty(key)) { - html = html + key + ": " + resultToHtml(results[key]) + "
"; + var elem = results[key]; + if (typeof(elem) == "boolean" && title) { + postResults(results[key], title + "." + key, div); + } else { + postResults(results[key], key, div); + } } } - div.innerHTML = "Test results:
" + html; } - div.appendChild(document.createElement("hr")); + if (first) { + div.appendChild(document.createElement("hr")); + } } @@ -159,6 +193,7 @@ if (selector != null) { // running a test if (tc == null) { description.innerHTML = "Test cases:"; var testCases = getAllTestCases(); + createLink(list, "(run all tests)", document.URL + "?command=runAllTests"); for (var idx in testCases) { var entryName = testCases[idx].name; createLink(list, entryName, document.URL + "?testCaseName=" + entryName); -- 2.7.4