31 """Tests Google Test's exception catching behavior.
33 This script invokes googletest-catch-exceptions-test_ and
34 googletest-catch-exceptions-ex-test_ (programs written with
35 Google Test) and verifies their output.
38 import gtest_test_utils
41 FLAG_PREFIX =
'--gtest_'
42 LIST_TESTS_FLAG = FLAG_PREFIX +
'list_tests'
43 NO_CATCH_EXCEPTIONS_FLAG = FLAG_PREFIX +
'catch_exceptions=0'
44 FILTER_FLAG = FLAG_PREFIX +
'filter'
49 'googletest-catch-exceptions-ex-test_')
54 'googletest-catch-exceptions-no-ex-test_')
56 environ = gtest_test_utils.environ
57 SetEnvVar = gtest_test_utils.SetEnvVar
64 SetEnvVar(gtest_test_utils.PREMATURE_EXIT_FILE_ENV_VAR,
None)
67 [EXE_PATH, LIST_TESTS_FLAG], env=environ).output
69 SUPPORTS_SEH_EXCEPTIONS =
'ThrowsSehException' in TEST_LIST
71 if SUPPORTS_SEH_EXCEPTIONS:
75 [EX_EXE_PATH], env=environ).output
79 if 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
120 self.assert_(
'C++ exception with description '
121 '"Standard C++ exception" thrown '
122 'in the test fixture\'s constructor'
124 self.assert_(
'unexpected' not in EX_BINARY_OUTPUT,
125 'This failure belongs in this test only if '
126 '"CxxExceptionInConstructorTest" (no quotes) '
127 'appears on the same line as words "called unexpectedly"')
129 if (
'CxxExceptionInDestructorTest.ThrowsExceptionInDestructor' in
133 self.assert_(
'C++ exception with description '
134 '"Standard C++ exception" thrown '
135 'in the test fixture\'s destructor'
137 self.assert_(
'CxxExceptionInDestructorTest::TearDownTestSuite() '
138 'called as expected.'
142 self.assert_(
'C++ exception with description "Standard C++ exception"'
143 ' thrown in SetUpTestSuite()' in EX_BINARY_OUTPUT)
144 self.assert_(
'CxxExceptionInConstructorTest::TearDownTestSuite() '
145 'called as expected.'
147 self.assert_(
'CxxExceptionInSetUpTestSuiteTest constructor '
148 'called as expected.'
150 self.assert_(
'CxxExceptionInSetUpTestSuiteTest destructor '
151 'called as expected.'
153 self.assert_(
'CxxExceptionInSetUpTestSuiteTest::SetUp() '
154 'called as expected.'
156 self.assert_(
'CxxExceptionInSetUpTestSuiteTest::TearDown() '
157 'called as expected.'
159 self.assert_(
'CxxExceptionInSetUpTestSuiteTest test body '
160 'called as expected.'
164 self.assert_(
'C++ exception with description "Standard C++ exception"'
165 ' thrown in TearDownTestSuite()' in EX_BINARY_OUTPUT)
168 self.assert_(
'C++ exception with description "Standard C++ exception"'
171 self.assert_(
'CxxExceptionInSetUpTest::TearDownTestSuite() '
172 'called as expected.'
174 self.assert_(
'CxxExceptionInSetUpTest destructor '
175 'called as expected.'
177 self.assert_(
'CxxExceptionInSetUpTest::TearDown() '
178 'called as expected.'
180 self.assert_(
'unexpected' not in EX_BINARY_OUTPUT,
181 'This failure belongs in this test only if '
182 '"CxxExceptionInSetUpTest" (no quotes) '
183 'appears on the same line as words "called unexpectedly"')
186 self.assert_(
'C++ exception with description "Standard C++ exception"'
187 ' thrown in TearDown()'
189 self.assert_(
'CxxExceptionInTearDownTest::TearDownTestSuite() '
190 'called as expected.'
192 self.assert_(
'CxxExceptionInTearDownTest destructor '
193 'called as expected.'
197 self.assert_(
'C++ exception with description "Standard C++ exception"'
198 ' thrown in the test body'
200 self.assert_(
'CxxExceptionInTestBodyTest::TearDownTestSuite() '
201 'called as expected.'
203 self.assert_(
'CxxExceptionInTestBodyTest destructor '
204 'called as expected.'
206 self.assert_(
'CxxExceptionInTestBodyTest::TearDown() '
207 'called as expected.'
211 self.assert_(
'Unknown C++ exception thrown in the test body'
217 FITLER_OUT_SEH_TESTS_FLAG = FILTER_FLAG +
'=-*Seh*'
221 NO_CATCH_EXCEPTIONS_FLAG,
222 FITLER_OUT_SEH_TESTS_FLAG],
225 self.assert_(
'Unhandled C++ exception terminating the program'
226 in uncaught_exceptions_ex_binary_output)
227 self.assert_(
'unexpected' not in uncaught_exceptions_ex_binary_output)
230 if __name__ ==
'__main__':