googletest-death-test_ex_test.cc (googletest-release-1.11.0) | : | googletest-death-test_ex_test.cc (googletest-release-1.12.0) | ||
---|---|---|---|---|
skipping to change at line 38 | skipping to change at line 38 | |||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
// | // | |||
// Tests that verify interaction of exceptions and death tests. | // Tests that verify interaction of exceptions and death tests. | |||
#include "gtest/gtest-death-test.h" | #include "gtest/gtest-death-test.h" | |||
#include "gtest/gtest.h" | #include "gtest/gtest.h" | |||
#if GTEST_HAS_DEATH_TEST | #if GTEST_HAS_DEATH_TEST | |||
# if GTEST_HAS_SEH | #if GTEST_HAS_SEH | |||
# include <windows.h> // For RaiseException(). | #include <windows.h> // For RaiseException(). | |||
# endif | #endif | |||
# include "gtest/gtest-spi.h" | #include "gtest/gtest-spi.h" | |||
# if GTEST_HAS_EXCEPTIONS | #if GTEST_HAS_EXCEPTIONS | |||
# include <exception> // For std::exception. | #include <exception> // For std::exception. | |||
// Tests that death tests report thrown exceptions as failures and that the | // Tests that death tests report thrown exceptions as failures and that the | |||
// exceptions do not escape death test macros. | // exceptions do not escape death test macros. | |||
TEST(CxxExceptionDeathTest, ExceptionIsFailure) { | TEST(CxxExceptionDeathTest, ExceptionIsFailure) { | |||
try { | try { | |||
EXPECT_NONFATAL_FAILURE(EXPECT_DEATH(throw 1, ""), "threw an exception"); | EXPECT_NONFATAL_FAILURE(EXPECT_DEATH(throw 1, ""), "threw an exception"); | |||
} catch (...) { // NOLINT | } catch (...) { // NOLINT | |||
FAIL() << "An exception escaped a death test macro invocation " | FAIL() << "An exception escaped a death test macro invocation " | |||
<< "with catch_exceptions " | << "with catch_exceptions " | |||
<< (testing::GTEST_FLAG(catch_exceptions) ? "enabled" : "disabled"); | << (GTEST_FLAG_GET(catch_exceptions) ? "enabled" : "disabled"); | |||
} | } | |||
} | } | |||
class TestException : public std::exception { | class TestException : public std::exception { | |||
public: | public: | |||
const char* what() const noexcept override { return "exceptional message"; } | const char* what() const noexcept override { return "exceptional message"; } | |||
}; | }; | |||
TEST(CxxExceptionDeathTest, PrintsMessageForStdExceptions) { | TEST(CxxExceptionDeathTest, PrintsMessageForStdExceptions) { | |||
// Verifies that the exception message is quoted in the failure text. | // Verifies that the exception message is quoted in the failure text. | |||
EXPECT_NONFATAL_FAILURE(EXPECT_DEATH(throw TestException(), ""), | EXPECT_NONFATAL_FAILURE(EXPECT_DEATH(throw TestException(), ""), | |||
"exceptional message"); | "exceptional message"); | |||
// Verifies that the location is mentioned in the failure text. | // Verifies that the location is mentioned in the failure text. | |||
EXPECT_NONFATAL_FAILURE(EXPECT_DEATH(throw TestException(), ""), | EXPECT_NONFATAL_FAILURE(EXPECT_DEATH(throw TestException(), ""), __FILE__); | |||
__FILE__); | ||||
} | } | |||
# endif // GTEST_HAS_EXCEPTIONS | #endif // GTEST_HAS_EXCEPTIONS | |||
# if GTEST_HAS_SEH | #if GTEST_HAS_SEH | |||
// Tests that enabling interception of SEH exceptions with the | // Tests that enabling interception of SEH exceptions with the | |||
// catch_exceptions flag does not interfere with SEH exceptions being | // catch_exceptions flag does not interfere with SEH exceptions being | |||
// treated as death by death tests. | // treated as death by death tests. | |||
TEST(SehExceptionDeasTest, CatchExceptionsDoesNotInterfere) { | TEST(SehExceptionDeasTest, CatchExceptionsDoesNotInterfere) { | |||
EXPECT_DEATH(RaiseException(42, 0x0, 0, NULL), "") | EXPECT_DEATH(RaiseException(42, 0x0, 0, NULL), "") | |||
<< "with catch_exceptions " | << "with catch_exceptions " | |||
<< (testing::GTEST_FLAG(catch_exceptions) ? "enabled" : "disabled"); | << (GTEST_FLAG_GET(catch_exceptions) ? "enabled" : "disabled"); | |||
} | } | |||
# endif | #endif | |||
#endif // GTEST_HAS_DEATH_TEST | #endif // GTEST_HAS_DEATH_TEST | |||
int main(int argc, char** argv) { | int main(int argc, char** argv) { | |||
testing::InitGoogleTest(&argc, argv); | testing::InitGoogleTest(&argc, argv); | |||
testing::GTEST_FLAG(catch_exceptions) = GTEST_ENABLE_CATCH_EXCEPTIONS_ != 0; | GTEST_FLAG_SET(catch_exceptions, GTEST_ENABLE_CATCH_EXCEPTIONS_ != 0); | |||
return RUN_ALL_TESTS(); | return RUN_ALL_TESTS(); | |||
} | } | |||
End of changes. 11 change blocks. | ||||
14 lines changed or deleted | 13 lines changed or added |