From 4b1ee195c1ec5a16851b9e6b5330147ec7d6aaf7 Mon Sep 17 00:00:00 2001 From: "gavin@gavinsharp.com" Date: Thu, 12 Jul 2007 07:29:33 -0700 Subject: [PATCH] Bug 387455: adjust browser chrome test harness output (provide summary, don't fail if there are no tests), r=robcee --- testing/mochitest/browser-harness.xul | 39 +++++++++++++++++---------- testing/mochitest/browser-test.js | 20 +++++++------- 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/testing/mochitest/browser-harness.xul b/testing/mochitest/browser-harness.xul index 227b66d05c5e..b4d481c0246c 100644 --- a/testing/mochitest/browser-harness.xul +++ b/testing/mochitest/browser-harness.xul @@ -102,14 +102,18 @@ function browserTestFile(aTestFile) { this.path = aTestFile; - this.exception = null; - this.timedOut = false; this.tests = []; this.scope = null; } browserTestFile.prototype = { - get allPassed() { - return !this.tests.some(function (t) !t.pass); + get passCount() { + return this.tests.filter(function (t) !t.todo && t.pass).length; + }, + get todoCount() { + return this.tests.filter(function (t) t.todo && t.pass).length; + }, + get failCount() { + return this.tests.filter(function (t) !t.pass).length; }, get log() { return this.tests.map(function (t) t.msg).join("\n"); @@ -154,16 +158,23 @@ } function getLogFromTests(aTests) { - return aTests.map(function (f) { - var output = f.path + "\n"; - if (f.log) - output += f.log + "\n"; - if (f.exception) - output += "\tFAIL - Exception thrown: " + f.exception + "\n"; - if (f.timedOut) - output += "\tFAIL - Timed out\n"; - return output; - }).join(""); + if (!aTests.length) + return "PASS - No tests to run"; + + var log = aTests.map(function (f) { + var output = f.path + "\n"; + if (f.log) + output += f.log + "\n"; + return output; + }).join(""); + log += "\nBrowser Chrome Test Summary\n"; + function sum(a, b){ return a + b; } + var passCount = aTests.map(function (f) f.passCount).reduce(sum); + var failCount = aTests.map(function (f) f.failCount).reduce(sum); + var todoCount = aTests.map(function (f) f.todoCount).reduce(sum); + log += "\tPass: " + passCount + "\n\tFail: " + failCount + "\n\tTodo: " + todoCount + "\n"; + + return log; } function testsFinished(aTests) { diff --git a/testing/mochitest/browser-test.js b/testing/mochitest/browser-test.js index b1ab27aef92b..bd8af159d43a 100644 --- a/testing/mochitest/browser-test.js +++ b/testing/mochitest/browser-test.js @@ -70,13 +70,12 @@ Tester.prototype = { try { this.currentTest.scope.test(); } catch (ex) { - this.currentTest.exception = ex; + this.currentTest.tests.push(new testResult(false, "Exception thrown", ex, false)); } - // If the test ran synchronously, set the result and move to the next test, + // If the test ran synchronously, move to the next test, // otherwise start a poller to monitor it's progress. if (this.currentTest.scope.done) { - this.currentTest.result = this.currentTest.scope.result; this.execTest(); } else { var self = this; @@ -90,9 +89,13 @@ function testResult(aCondition, aName, aDiag, aIsTodo) { aName = aName || ""; this.pass = !!aCondition; - if (this.pass) - this.msg = "\tPASS - " + aName; - else { + this.todo = aIsTodo; + if (this.pass) { + if (aIsTodo) + this.msg = "\tTODO PASS - " + aName; + else + this.msg = "\tPASS - " + aName; + } else { this.msg = "\tFAIL - "; if (aIsTodo) this.msg += "TODO Worked? - "; @@ -158,14 +161,11 @@ resultPoller.prototype = { self.loopCount++; if (self.loopCount > MAX_LOOP_COUNT) { - self.test.timedOut = true; + self.test.tests.push(new testResult(false, "Timed out", "", false)); self.test.scope.done = true; } if (self.test.scope.done) { - // Set the result - self.test.result = self.test.scope.result; - clearInterval(self.interval); // Notify the callback