From 8d48f55b964873fcd5dd28bf07bfdbc8c6d3996f Mon Sep 17 00:00:00 2001 From: Cameron McCormack Date: Mon, 27 Jun 2011 11:05:02 +1200 Subject: [PATCH] Bug 667155 - Ensure uncaught exceptions do cause test failures in plain mochitests. r=ted --- testing/mochitest/tests/SimpleTest/SimpleTest.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/testing/mochitest/tests/SimpleTest/SimpleTest.js b/testing/mochitest/tests/SimpleTest/SimpleTest.js index aa5af84c9aa..4bd052cb00c 100644 --- a/testing/mochitest/tests/SimpleTest/SimpleTest.js +++ b/testing/mochitest/tests/SimpleTest/SimpleTest.js @@ -790,21 +790,22 @@ var isDeeply = SimpleTest.isDeeply; var gOldOnError = window.onerror; window.onerror = function simpletestOnerror(errorMsg, url, lineNumber) { var funcIdentifier = "[SimpleTest/SimpleTest.js, window.onerror]"; + var isPlainMochitest = window.location.protocol != "chrome:"; // Log the message. // XXX Chrome mochitests sometimes trigger this window.onerror handler, // but there are a number of uncaught JS exceptions from those tests // currently, so we can't log them as errors just yet. For now, when - // parentRunner is null, just dump it so that the error is visible but + // not in a plain mochitest, just dump it so that the error is visible but // doesn't cause a test failure. See bug 652494. - function logInfo(message) { - if (parentRunner) { - SimpleTest._logInfo(funcIdentifier, message); + function logError(message) { + if (isPlainMochitest) { + SimpleTest.ok(false, funcIdentifier, message); } else { dump(funcIdentifier + " " + message); } } - logInfo("An error occurred: " + errorMsg + " at " + url + ":" + lineNumber); + logError("An error occurred: " + errorMsg + " at " + url + ":" + lineNumber); // There is no Components.stack.caller to log. (See bug 511888.) // Call previous handler. @@ -814,10 +815,10 @@ window.onerror = function simpletestOnerror(errorMsg, url, lineNumber) { gOldOnError(errorMsg, url, lineNumber); } catch (e) { // Log the error. - logInfo("Exception thrown by gOldOnError(): " + e); + logError("Exception thrown by gOldOnError(): " + e); // Log its stack. if (e.stack) { - logInfo("JavaScript error stack:\n" + e.stack); + logError("JavaScript error stack:\n" + e.stack); } } }