diff --git a/googletest/include/gtest/gtest-death-test.h b/googletest/include/gtest/gtest-death-test.h index 3c61909726..ae698bf78c 100644 --- a/googletest/include/gtest/gtest-death-test.h +++ b/googletest/include/gtest/gtest-death-test.h @@ -189,6 +189,17 @@ GTEST_API_ bool InDeathTestChild(); #define EXPECT_DEATH(statement, matcher) \ EXPECT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, matcher) +// check if it is a child of ExceptionTest +#define EXPECT_NO_COREFILE_DEATH(statement, matcher) \ + do { \ + if (dynamic_cast<::testing::ExceptionTest *>(this)) { \ + EXPECT_DEATH(statement, matcher); \ + } else { \ + EXPECT_TRUE(false) << "EXPECT_NO_COREFILE_DEATH can only be used in " \ + "::testing::ExceptionTest and its subclass"; \ + } \ + } while (0) + // Two predicate classes that can be used in {ASSERT,EXPECT}_EXIT*: // Tests that an exit code describes a normal exit with a given exit code. diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index c899669520..461bac1f26 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -49,6 +49,8 @@ #ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_H_ #define GOOGLETEST_INCLUDE_GTEST_GTEST_H_ +#include + #include #include #include @@ -360,6 +362,45 @@ class GTEST_API_ Test { Test& operator=(const Test&) = delete; }; +// The class is a helpler to implements a test suite without core file +// generated. +class ExceptionTest : public ::testing::Test { +protected: + static void SetUpTestSuite() { + struct rlimit rl; + rl.rlim_cur = 0; + rl.rlim_max = 0; + // store old value of core dump file size + if (getrlimit(RLIMIT_CORE, &rl_old_) == -1) { + exit(EXIT_FAILURE); + } + + // do not generate core dump file, we know it will fail + if (setrlimit(RLIMIT_CORE, &rl) == -1) { + exit(EXIT_FAILURE); + } else { + GTEST_LOG_(INFO) << "set RLIMIT_CORE success"; + GTEST_LOG_(INFO) << "rl_old_ rlim_cur: " << rl_old_.rlim_cur; + GTEST_LOG_(INFO) << "rl_old_ rlim_max: " << rl_old_.rlim_max; + } + } + static void TearDownTestSuite() { + // do not generate core dump file, we know it will fail + if (setrlimit(RLIMIT_CORE, &rl_old_) == -1) { + exit(EXIT_FAILURE); + } else { + GTEST_LOG_(INFO) << "restore RLIMIT_CORE success"; + } + } + void SetUp() override {} + + void TearDown() override {} + +private: + static struct rlimit rl_old_; +}; +struct rlimit ExceptionTest::rl_old_ = {0, 0}; + typedef internal::TimeInMillis TimeInMillis; // A copyable object representing a user specified test property which can be