From 7e37f21a175bf401c118bde483b7f4420fe79264 Mon Sep 17 00:00:00 2001 From: Ed Morley Date: Tue, 11 Dec 2012 20:29:18 +0000 Subject: [PATCH] Backout fac650c31656 & 907a846d368f (bug 819033) for xpcshell failures --- testing/xpcshell/head.js | 84 ++--------- testing/xpcshell/selftest.py | 140 ------------------ .../tests/unit/test_sql_guid_functions.js | 3 +- 3 files changed, 17 insertions(+), 210 deletions(-) diff --git a/testing/xpcshell/head.js b/testing/xpcshell/head.js index d262a27b77ef..6b5f800777d4 100644 --- a/testing/xpcshell/head.js +++ b/testing/xpcshell/head.js @@ -863,86 +863,32 @@ function run_test_in_child(testFile, optionalCallback) * * @return the test function that was passed in. */ -let _gTests = []; +let gTests = []; function add_test(func) { - _gTests.push([false, func]); + gTests.push(func); return func; } -// We lazy import Task.jsm so we don't incur a run-time penalty for all tests. -let _Task; - -/** - * Add a test function which is a Task function. - * - * Task functions are functions fed into Task.jsm's Task.spawn(). They are - * generators that emit promises. - * - * If an exception is thrown, a do_check_* comparison fails, or if a rejected - * promise is yielded, the test function aborts immediately and the test is - * reported as a failure. - * - * Unlike add_test(), there is no need to call run_next_test(). The next test - * will run automatically as soon the task function is exhausted. To trigger - * premature (but successful) termination of the function, simply return or - * throw a Task.Result instance. - * - * Example usage: - * - * add_task(function test() { - * let result = yield Promise.resolve(true); - * - * do_check_true(result); - * - * let secondary = yield someFunctionThatReturnsAPromise(result); - * do_check_eq(secondary, "expected value"); - * }); - * - * add_task(function test_early_return() { - * let result = yield somethingThatReturnsAPromise(); - * - * if (!result) { - * // Test is ended immediately, with success. - * return; - * } - * - * do_check_eq(result, "foo"); - * }); - */ -function add_task(func) { - if (!_Task) { - let ns = {}; - _Task = Components.utils.import("resource://gre/modules/Task.jsm", ns).Task; - } - - _gTests.push([true, func]); -} - /** * Runs the next test function from the list of async tests. */ -let _gRunningTest = null; -let _gTestIndex = 0; // The index of the currently running test. +let gRunningTest = null; +let gTestIndex = 0; // The index of the currently running test. function run_next_test() { function _run_next_test() { - if (_gTestIndex < _gTests.length) { + if (gTestIndex < gTests.length) { do_test_pending(); - let _isTask; - [_isTask, _gRunningTest] = _gTests[_gTestIndex++]; - print("TEST-INFO | " + _TEST_FILE + " | Starting " + _gRunningTest.name); - - if (_isTask) { - _Task.spawn(_gRunningTest) - .then(run_next_test, do_report_unexpected_exception); - } else { - // Exceptions do not kill asynchronous tests, so they'll time out. - try { - _gRunningTest(); - } catch (e) { - do_throw(e); - } + gRunningTest = gTests[gTestIndex++]; + print("TEST-INFO | " + _TEST_FILE + " | Starting " + + gRunningTest.name); + // Exceptions do not kill asynchronous tests, so they'll time out. + try { + gRunningTest(); + } + catch (e) { + do_throw(e); } } } @@ -953,7 +899,7 @@ function run_next_test() // (do_execute_soon bumps that counter). do_execute_soon(_run_next_test); - if (_gRunningTest !== null) { + if (gRunningTest !== null) { // Close the previous test do_test_pending call. do_test_finished(); } diff --git a/testing/xpcshell/selftest.py b/testing/xpcshell/selftest.py index 7d7bfc2ebb5a..26792672ccca 100644 --- a/testing/xpcshell/selftest.py +++ b/testing/xpcshell/selftest.py @@ -19,71 +19,6 @@ if sys.platform == "win32": SIMPLE_PASSING_TEST = "function run_test() { do_check_true(true); }" SIMPLE_FAILING_TEST = "function run_test() { do_check_true(false); }" -ADD_TEST_SIMPLE = ''' -function run_test() { run_next_test(); } - -add_test(function test_simple() { - do_check_true(true); - run_next_test(); -}); -''' - -ADD_TEST_FAILING = ''' -function run_test() { run_next_test(); } - -add_test(function test_failing() { - do_check_true(false); - run_next_test(); -}); -''' - -ADD_TASK_SINGLE = ''' -Components.utils.import("resource://gre/modules/commonjs/promise/core.js"); - -function run_test() { run_next_test(); } - -add_task(function test_task() { - yield Promise.resolve(true); - yield Promise.resolve(false); -}); -''' - -ADD_TASK_MULTIPLE = ''' -Components.utils.import("resource://gre/modules/commonjs/promise/core.js"); - -function run_test() { run_next_test(); } - -add_task(function test_task() { - yield Promise.resolve(true); -}); - -add_task(function test_2() { - yield Promise.resolve(true); -}); -''' - -ADD_TASK_REJECTED = ''' -Components.utils.import("resource://gre/modules/commonjs/promise/core.js"); - -function run_test() { run_next_test(); } - -add_task(function test_failing() { - yield Promise.reject(new Error("I fail.")); -}); -''' - -ADD_TASK_FAILURE_INSIDE = ''' -Components.utils.import("resource://gre/modules/commonjs/promise/core.js"); - -function run_test() { run_next_test(); } - -add_task(function test() { - let result = yield Promise.resolve(false); - - do_check_true(result); -}); -''' - class XPCShellTestsTests(unittest.TestCase): """ Yes, these are unit tests for a unit test harness. @@ -277,81 +212,6 @@ tail = self.assertInLog("TEST-UNEXPECTED-FAIL") self.assertNotInLog("TEST-PASS") - def testAddTestSimple(self): - """ - Ensure simple add_test() works. - """ - self.writeFile("test_add_test_simple.js", ADD_TEST_SIMPLE) - self.writeManifest(["test_add_test_simple.js"]) - - self.assertTestResult(True) - self.assertEquals(1, self.x.testCount) - self.assertEquals(1, self.x.passCount) - self.assertEquals(0, self.x.failCount) - - def testAddTestFailing(self): - """ - Ensure add_test() with a failing test is reported. - """ - self.writeFile("test_add_test_failing.js", ADD_TEST_FAILING) - self.writeManifest(["test_add_test_failing.js"]) - - self.assertTestResult(False) - self.assertEquals(1, self.x.testCount) - self.assertEquals(0, self.x.passCount) - self.assertEquals(1, self.x.failCount) - - def testAddTaskTestSingle(self): - """ - Ensure add_test_task() with a single passing test works. - """ - self.writeFile("test_add_task_simple.js", ADD_TASK_SINGLE) - self.writeManifest(["test_add_task_simple.js"]) - - self.assertTestResult(True) - self.assertEquals(1, self.x.testCount) - self.assertEquals(1, self.x.passCount) - self.assertEquals(0, self.x.failCount) - - def testAddTaskTestMultiple(self): - """ - Ensure multiple calls to add_test_task() work as expected. - """ - self.writeFile("test_add_task_multiple.js", - ADD_TASK_MULTIPLE) - self.writeManifest(["test_add_task_multiple.js"]) - - self.assertTestResult(True) - self.assertEquals(1, self.x.testCount) - self.assertEquals(1, self.x.passCount) - self.assertEquals(0, self.x.failCount) - - def testAddTaskTestRejected(self): - """ - Ensure rejected task reports as failure. - """ - self.writeFile("test_add_task_rejected.js", - ADD_TASK_REJECTED) - self.writeManifest(["test_add_task_rejected.js"]) - - self.assertTestResult(False) - self.assertEquals(1, self.x.testCount) - self.assertEquals(0, self.x.passCount) - self.assertEquals(1, self.x.failCount) - - def testAddTaskTestFailureInside(self): - """ - Ensure tests inside task are reported as failures. - """ - self.writeFile("test_add_task_failure_inside.js", - ADD_TASK_FAILURE_INSIDE) - self.writeManifest(["test_add_task_failure_inside.js"]) - - self.assertTestResult(False) - self.assertEquals(1, self.x.testCount) - self.assertEquals(0, self.x.passCount) - self.assertEquals(1, self.x.failCount) - def testMissingHeadFile(self): """ Ensure that missing head file results in fatal error. diff --git a/toolkit/components/places/tests/unit/test_sql_guid_functions.js b/toolkit/components/places/tests/unit/test_sql_guid_functions.js index a81cefa37674..ff8c971a84dc 100644 --- a/toolkit/components/places/tests/unit/test_sql_guid_functions.js +++ b/toolkit/components/places/tests/unit/test_sql_guid_functions.js @@ -14,7 +14,8 @@ */ function check_invariants(aGuid) { - do_print("Checking guid '" + aGuid + "'"); + print("TEST-INFO | " + gRunningTest.name + " | Checking guid '" + + aGuid + "'"); do_check_valid_places_guid(aGuid); }