31"""Tests Google Test's exception catching behavior.
33This script invokes googletest-catch-exceptions-test_ and
34googletest-catch-exceptions-ex-test_ (programs written with
35Google Test) and verifies their output.
38import gtest_test_utils
41FLAG_PREFIX =
'--gtest_'
42LIST_TESTS_FLAG = FLAG_PREFIX +
'list_tests'
43NO_CATCH_EXCEPTIONS_FLAG = FLAG_PREFIX +
'catch_exceptions=0'
44FILTER_FLAG = FLAG_PREFIX +
'filter'
49 'googletest-catch-exceptions-ex-test_')
54 'googletest-catch-exceptions-no-ex-test_')
56environ = gtest_test_utils.environ
57SetEnvVar = gtest_test_utils.SetEnvVar
64SetEnvVar(gtest_test_utils.PREMATURE_EXIT_FILE_ENV_VAR,
None)
67 [EXE_PATH, LIST_TESTS_FLAG], env=environ).output
69SUPPORTS_SEH_EXCEPTIONS =
'ThrowsSehException' in TEST_LIST
71if SUPPORTS_SEH_EXCEPTIONS:
75 [EX_EXE_PATH], env=environ).output
79if SUPPORTS_SEH_EXCEPTIONS:
82 """Tests exception-catching behavior."""
86 self.assert_(
'SEH exception with code 0x2a thrown '
87 'in the test fixture\'s constructor'
89 self.assert_(
'SEH exception with code 0x2a thrown '
90 'in the test fixture\'s destructor'
92 self.assert_(
'SEH exception with code 0x2a thrown in SetUpTestSuite()'
94 self.assert_(
'SEH exception with code 0x2a thrown in TearDownTestSuite()'
96 self.assert_(
'SEH exception with code 0x2a thrown in SetUp()'
98 self.assert_(
'SEH exception with code 0x2a thrown in TearDown()'
100 self.assert_(
'SEH exception with code 0x2a thrown in the test body'
111 """Tests C++ exception-catching behavior.
113 Tests in this test case verify that:
114 * C++ exceptions are caught
and logged
as C++ (
not SEH) exceptions
115 * Exception thrown affect the remainder of the test work flow
in the
121 'C++ exception with description '
122 '"Standard C++ exception" thrown '
123 'in the test fixture\'s constructor' in EX_BINARY_OUTPUT,
125 self.assert_(
'unexpected' not in EX_BINARY_OUTPUT,
126 'This failure belongs in this test only if '
127 '"CxxExceptionInConstructorTest" (no quotes) '
128 'appears on the same line as words "called unexpectedly"')
130 if (
'CxxExceptionInDestructorTest.ThrowsExceptionInDestructor' in
135 'C++ exception with description '
136 '"Standard C++ exception" thrown '
137 'in the test fixture\'s destructor' in EX_BINARY_OUTPUT,
140 'CxxExceptionInDestructorTest::TearDownTestSuite() '
141 'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
145 'C++ exception with description "Standard C++ exception"'
146 ' thrown in SetUpTestSuite()' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
148 'CxxExceptionInConstructorTest::TearDownTestSuite() '
149 'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
151 'CxxExceptionInSetUpTestSuiteTest constructor '
152 'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
154 'CxxExceptionInSetUpTestSuiteTest destructor '
155 'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
157 'CxxExceptionInSetUpTestSuiteTest::SetUp() '
158 'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
160 'CxxExceptionInSetUpTestSuiteTest::TearDown() '
161 'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
163 'CxxExceptionInSetUpTestSuiteTest test body '
164 'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
168 'C++ exception with description "Standard C++ exception"'
169 ' thrown in TearDownTestSuite()' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
173 'C++ exception with description "Standard C++ exception"'
174 ' thrown in SetUp()' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
176 'CxxExceptionInSetUpTest::TearDownTestSuite() '
177 'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
179 'CxxExceptionInSetUpTest destructor '
180 'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
182 'CxxExceptionInSetUpTest::TearDown() '
183 'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
184 self.assert_(
'unexpected' not in EX_BINARY_OUTPUT,
185 'This failure belongs in this test only if '
186 '"CxxExceptionInSetUpTest" (no quotes) '
187 'appears on the same line as words "called unexpectedly"')
191 'C++ exception with description "Standard C++ exception"'
192 ' thrown in TearDown()' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
194 'CxxExceptionInTearDownTest::TearDownTestSuite() '
195 'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
197 'CxxExceptionInTearDownTest destructor '
198 'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
202 'C++ exception with description "Standard C++ exception"'
203 ' thrown in the test body' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
205 'CxxExceptionInTestBodyTest::TearDownTestSuite() '
206 'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
208 'CxxExceptionInTestBodyTest destructor '
209 'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
211 'CxxExceptionInTestBodyTest::TearDown() '
212 'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
216 'Unknown C++ exception thrown in the test body' in EX_BINARY_OUTPUT,
222 FITLER_OUT_SEH_TESTS_FLAG = FILTER_FLAG +
'=-*Seh*'
226 NO_CATCH_EXCEPTIONS_FLAG,
227 FITLER_OUT_SEH_TESTS_FLAG],
230 self.assert_(
'Unhandled C++ exception terminating the program'
231 in uncaught_exceptions_ex_binary_output)
232 self.assert_(
'unexpected' not in uncaught_exceptions_ex_binary_output)
235if __name__ ==
'__main__':
def GetTestExecutablePath(executable_name, build_dir=None)
def TestSehExceptions(self, test_output)
def testCatchesSehExceptionsWithCxxExceptionsDisabled(self)
def testCatchesSehExceptionsWithCxxExceptionsEnabled(self)
def testCatchesNonStdCxxExceptions(self)
def testCatchesCxxExceptionsInFixtureConstructor(self)
def testCatchesCxxExceptionsInTestBody(self)
def testUnhandledCxxExceptionsAbortTheProgram(self)
def testCatchesCxxExceptionsInTearDown(self)
def testCatchesCxxExceptionsInSetUpTestCase(self)
def testCatchesCxxExceptionsInTearDownTestCase(self)
def testCatchesCxxExceptionsInFixtureDestructor(self)
def testCatchesCxxExceptionsInSetUp(self)