Bug 982852 - Add cases to check that tests without run_test() work; r=gps

Four new test cases have been added to testing/xpcshell/selftest.py.
These new tests check that tests where run_test() is not defined
work properly.

The test cases check the following cases:
1. when only add_test() is used.
2. when only add_task() is used.
3. when both add_task() and add_test() is used.
4. when a test file is empty, i.e. contains no add_test(), add_task() or
  run_test().

Test bodies only consist of do_check_true(true) calls to make up a minimal
test without run_test() in the same vein as the other simple tests defined
previously.

Also, broke a comment up that was too long.

--HG--
extra : rebase_source : 48d055680ba8108816ecbe07008496c5281f46cc
This commit is contained in:
Krishnashish Gogoi 2015-04-03 01:43:54 +05:30
Родитель a80b42da44
Коммит bf13167dea
1 изменённых файлов: 91 добавлений и 0 удалений

Просмотреть файл

@ -287,6 +287,39 @@ function run_test() {
}
'''
# A test to check that add_test() tests run without run_test()
NO_RUN_TEST_ADD_TEST = '''
add_test(function no_run_test_add_test() {
do_check_true(true);
run_next_test();
});
'''
# A test to check that add_task() tests run without run_test()
NO_RUN_TEST_ADD_TASK = '''
add_task(function no_run_test_add_task() {
do_check_true(true);
});
'''
# A test to check that both add_task() and add_test() work without run_test()
NO_RUN_TEST_ADD_TEST_ADD_TASK = '''
add_test(function no_run_test_add_test() {
do_check_true(true);
run_next_test();
});
add_task(function no_run_test_add_task() {
do_check_true(true);
});
'''
# A test to check that an empty test file without run_test(),
# add_test() or add_task() works.
NO_RUN_TEST_EMPTY_TEST = '''
// This is an empty test file.
'''
class XPCShellTestsTests(unittest.TestCase):
"""
@ -892,5 +925,63 @@ tail =
self.assertInLog("At this stage, the test has succeeded")
self.assertInLog("Throwing an error to force displaying the log")
def testNoRunTestAddTest(self):
"""
Check that add_test() works fine without run_test() in the test file.
"""
self.writeFile("test_noRunTestAddTest.js", NO_RUN_TEST_ADD_TEST)
self.writeManifest(["test_noRunTestAddTest.js"])
self.assertTestResult(True)
self.assertEquals(1, self.x.testCount)
self.assertEquals(1, self.x.passCount)
self.assertEquals(0, self.x.failCount)
self.assertInLog(TEST_PASS_STRING)
self.assertNotInLog(TEST_FAIL_STRING)
def testNoRunTestAddTask(self):
"""
Check that add_task() works fine without run_test() in the test file.
"""
self.writeFile("test_noRunTestAddTask.js", NO_RUN_TEST_ADD_TASK)
self.writeManifest(["test_noRunTestAddTask.js"])
self.assertTestResult(True)
self.assertEquals(1, self.x.testCount)
self.assertEquals(1, self.x.passCount)
self.assertEquals(0, self.x.failCount)
self.assertInLog(TEST_PASS_STRING)
self.assertNotInLog(TEST_FAIL_STRING)
def testNoRunTestAddTestAddTask(self):
"""
Check that both add_test() and add_task() work without run_test()
in the test file.
"""
self.writeFile("test_noRunTestAddTestAddTask.js", NO_RUN_TEST_ADD_TEST_ADD_TASK)
self.writeManifest(["test_noRunTestAddTestAddTask.js"])
self.assertTestResult(True)
self.assertEquals(1, self.x.testCount)
self.assertEquals(1, self.x.passCount)
self.assertEquals(0, self.x.failCount)
self.assertInLog(TEST_PASS_STRING)
self.assertNotInLog(TEST_FAIL_STRING)
def testNoRunTestEmptyTest(self):
"""
Check that the test passes on an empty file that contains neither
run_test() nor add_test(), add_task().
"""
self.writeFile("test_noRunTestEmptyTest.js", NO_RUN_TEST_EMPTY_TEST)
self.writeManifest(["test_noRunTestEmptyTest.js"])
self.assertTestResult(True)
self.assertEquals(1, self.x.testCount)
self.assertEquals(1, self.x.passCount)
self.assertEquals(0, self.x.failCount)
self.assertInLog(TEST_PASS_STRING)
self.assertNotInLog(TEST_FAIL_STRING)
if __name__ == "__main__":
unittest.main(verbosity=3)