31 """Tests Google Test's exception catching behavior. 33 This script invokes gtest_catch_exceptions_test_ and 34 gtest_catch_exceptions_ex_test_ (programs written with 35 Google Test) and verifies their output. 38 __author__ =
'vladl@google.com (Vlad Losev)' 42 import gtest_test_utils
45 FLAG_PREFIX =
'--gtest_' 46 LIST_TESTS_FLAG = FLAG_PREFIX +
'list_tests' 47 NO_CATCH_EXCEPTIONS_FLAG = FLAG_PREFIX +
'catch_exceptions=0' 48 FILTER_FLAG = FLAG_PREFIX +
'filter' 53 'gtest_catch_exceptions_ex_test_')
58 'gtest_catch_exceptions_no_ex_test_')
60 environ = gtest_test_utils.environ
61 SetEnvVar = gtest_test_utils.SetEnvVar
68 SetEnvVar(gtest_test_utils.PREMATURE_EXIT_FILE_ENV_VAR,
None)
71 [EXE_PATH, LIST_TESTS_FLAG], env=environ).output
73 SUPPORTS_SEH_EXCEPTIONS =
'ThrowsSehException' in TEST_LIST
75 if SUPPORTS_SEH_EXCEPTIONS:
79 [EX_EXE_PATH], env=environ).output
83 if SUPPORTS_SEH_EXCEPTIONS:
86 """Tests exception-catching behavior.""" 90 self.assertTrue(
'SEH exception with code 0x2a thrown ' 91 'in the test fixture\'s constructor' 93 self.assertTrue(
'SEH exception with code 0x2a thrown ' 94 'in the test fixture\'s destructor' 96 self.assertTrue(
'SEH exception with code 0x2a thrown in SetUpTestCase()' 98 self.assertTrue(
'SEH exception with code 0x2a thrown in TearDownTestCase()' 100 self.assertTrue(
'SEH exception with code 0x2a thrown in SetUp()' 102 self.assertTrue(
'SEH exception with code 0x2a thrown in TearDown()' 104 self.assertTrue(
'SEH exception with code 0x2a thrown in the test body' 115 """Tests C++ exception-catching behavior. 117 Tests in this test case verify that: 118 * C++ exceptions are caught and logged as C++ (not SEH) exceptions 119 * Exception thrown affect the remainder of the test work flow in the 124 self.assertTrue(
'C++ exception with description ' 125 '"Standard C++ exception" thrown ' 126 'in the test fixture\'s constructor' 128 self.assertTrue(
'unexpected' not in EX_BINARY_OUTPUT,
129 'This failure belongs in this test only if ' 130 '"CxxExceptionInConstructorTest" (no quotes) ' 131 'appears on the same line as words "called unexpectedly"')
133 if (
'CxxExceptionInDestructorTest.ThrowsExceptionInDestructor' in 137 self.assertTrue(
'C++ exception with description ' 138 '"Standard C++ exception" thrown ' 139 'in the test fixture\'s destructor' 141 self.assertTrue(
'CxxExceptionInDestructorTest::TearDownTestCase() ' 142 'called as expected.' 146 self.assertTrue(
'C++ exception with description "Standard C++ exception"' 147 ' thrown in SetUpTestCase()' 149 self.assertTrue(
'CxxExceptionInConstructorTest::TearDownTestCase() ' 150 'called as expected.' 152 self.assertTrue(
'CxxExceptionInSetUpTestCaseTest constructor ' 153 'called as expected.' 155 self.assertTrue(
'CxxExceptionInSetUpTestCaseTest destructor ' 156 'called as expected.' 158 self.assertTrue(
'CxxExceptionInSetUpTestCaseTest::SetUp() ' 159 'called as expected.' 161 self.assertTrue(
'CxxExceptionInSetUpTestCaseTest::TearDown() ' 162 'called as expected.' 164 self.assertTrue(
'CxxExceptionInSetUpTestCaseTest test body ' 165 'called as expected.' 169 self.assertTrue(
'C++ exception with description "Standard C++ exception"' 170 ' thrown in TearDownTestCase()' 174 self.assertTrue(
'C++ exception with description "Standard C++ exception"' 177 self.assertTrue(
'CxxExceptionInSetUpTest::TearDownTestCase() ' 178 'called as expected.' 180 self.assertTrue(
'CxxExceptionInSetUpTest destructor ' 181 'called as expected.' 183 self.assertTrue(
'CxxExceptionInSetUpTest::TearDown() ' 184 'called as expected.' 186 self.assertTrue(
'unexpected' not in EX_BINARY_OUTPUT,
187 'This failure belongs in this test only if ' 188 '"CxxExceptionInSetUpTest" (no quotes) ' 189 'appears on the same line as words "called unexpectedly"')
192 self.assertTrue(
'C++ exception with description "Standard C++ exception"' 193 ' thrown in TearDown()' 195 self.assertTrue(
'CxxExceptionInTearDownTest::TearDownTestCase() ' 196 'called as expected.' 198 self.assertTrue(
'CxxExceptionInTearDownTest destructor ' 199 'called as expected.' 203 self.assertTrue(
'C++ exception with description "Standard C++ exception"' 204 ' thrown in the test body' 206 self.assertTrue(
'CxxExceptionInTestBodyTest::TearDownTestCase() ' 207 'called as expected.' 209 self.assertTrue(
'CxxExceptionInTestBodyTest destructor ' 210 'called as expected.' 212 self.assertTrue(
'CxxExceptionInTestBodyTest::TearDown() ' 213 'called as expected.' 217 self.assertTrue(
'Unknown C++ exception thrown in the test body' 223 FITLER_OUT_SEH_TESTS_FLAG = FILTER_FLAG +
'=-*Seh*' 227 NO_CATCH_EXCEPTIONS_FLAG,
228 FITLER_OUT_SEH_TESTS_FLAG],
231 self.assertTrue(
'Unhandled C++ exception terminating the program' 232 in uncaught_exceptions_ex_binary_output)
233 self.assertTrue(
'unexpected' not in uncaught_exceptions_ex_binary_output)
236 if __name__ ==
'__main__':
def testCatchesCxxExceptionsInTearDown(self)
def testCatchesCxxExceptionsInTestBody(self)
def GetTestExecutablePath(executable_name, build_dir=None)
def testCatchesNonStdCxxExceptions(self)
def testCatchesSehExceptionsWithCxxExceptionsEnabled(self)
def testCatchesCxxExceptionsInSetUpTestCase(self)
def testCatchesSehExceptionsWithCxxExceptionsDisabled(self)
def testUnhandledCxxExceptionsAbortTheProgram(self)
def testCatchesCxxExceptionsInFixtureConstructor(self)
def testCatchesCxxExceptionsInFixtureDestructor(self)
def testCatchesCxxExceptionsInSetUp(self)
def TestSehExceptions(self, test_output)
def testCatchesCxxExceptionsInTearDownTestCase(self)