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.assert_(
'SEH exception with code 0x2a thrown '
91 'in the test fixture\'s constructor'
93 self.assert_(
'SEH exception with code 0x2a thrown '
94 'in the test fixture\'s destructor'
96 self.assert_(
'SEH exception with code 0x2a thrown in SetUpTestCase()'
98 self.assert_(
'SEH exception with code 0x2a thrown in TearDownTestCase()'
100 self.assert_(
'SEH exception with code 0x2a thrown in SetUp()'
102 self.assert_(
'SEH exception with code 0x2a thrown in TearDown()'
104 self.assert_(
'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.assert_(
'C++ exception with description '
125 '"Standard C++ exception" thrown '
126 'in the test fixture\'s constructor'
128 self.assert_(
'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.assert_(
'C++ exception with description '
138 '"Standard C++ exception" thrown '
139 'in the test fixture\'s destructor'
141 self.assert_(
'CxxExceptionInDestructorTest::TearDownTestCase() '
142 'called as expected.'
146 self.assert_(
'C++ exception with description "Standard C++ exception"'
147 ' thrown in SetUpTestCase()'
149 self.assert_(
'CxxExceptionInConstructorTest::TearDownTestCase() '
150 'called as expected.'
152 self.assert_(
'CxxExceptionInSetUpTestCaseTest constructor '
153 'called as expected.'
155 self.assert_(
'CxxExceptionInSetUpTestCaseTest destructor '
156 'called as expected.'
158 self.assert_(
'CxxExceptionInSetUpTestCaseTest::SetUp() '
159 'called as expected.'
161 self.assert_(
'CxxExceptionInSetUpTestCaseTest::TearDown() '
162 'called as expected.'
164 self.assert_(
'CxxExceptionInSetUpTestCaseTest test body '
165 'called as expected.'
169 self.assert_(
'C++ exception with description "Standard C++ exception"'
170 ' thrown in TearDownTestCase()'
174 self.assert_(
'C++ exception with description "Standard C++ exception"'
177 self.assert_(
'CxxExceptionInSetUpTest::TearDownTestCase() '
178 'called as expected.'
180 self.assert_(
'CxxExceptionInSetUpTest destructor '
181 'called as expected.'
183 self.assert_(
'CxxExceptionInSetUpTest::TearDown() '
184 'called as expected.'
186 self.assert_(
'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.assert_(
'C++ exception with description "Standard C++ exception"'
193 ' thrown in TearDown()'
195 self.assert_(
'CxxExceptionInTearDownTest::TearDownTestCase() '
196 'called as expected.'
198 self.assert_(
'CxxExceptionInTearDownTest destructor '
199 'called as expected.'
203 self.assert_(
'C++ exception with description "Standard C++ exception"'
204 ' thrown in the test body'
206 self.assert_(
'CxxExceptionInTestBodyTest::TearDownTestCase() '
207 'called as expected.'
209 self.assert_(
'CxxExceptionInTestBodyTest destructor '
210 'called as expected.'
212 self.assert_(
'CxxExceptionInTestBodyTest::TearDown() '
213 'called as expected.'
217 self.assert_(
'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.assert_(
'Unhandled C++ exception terminating the program'
232 in uncaught_exceptions_ex_binary_output)
233 self.assert_(
'unexpected' not in uncaught_exceptions_ex_binary_output)
236 if __name__ ==
'__main__':