Merge 1c9e9a635f
into a6ce08abf7
This commit is contained in:
commit
5eb0193c6c
@ -189,6 +189,17 @@ GTEST_API_ bool InDeathTestChild();
|
|||||||
#define EXPECT_DEATH(statement, matcher) \
|
#define EXPECT_DEATH(statement, matcher) \
|
||||||
EXPECT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, 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*:
|
// 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.
|
// Tests that an exit code describes a normal exit with a given exit code.
|
||||||
|
@ -49,6 +49,8 @@
|
|||||||
#ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_H_
|
#ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_H_
|
||||||
#define GOOGLETEST_INCLUDE_GTEST_GTEST_H_
|
#define GOOGLETEST_INCLUDE_GTEST_GTEST_H_
|
||||||
|
|
||||||
|
#include <sys/resource.h>
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
@ -360,6 +362,45 @@ class GTEST_API_ Test {
|
|||||||
Test& operator=(const Test&) = delete;
|
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;
|
typedef internal::TimeInMillis TimeInMillis;
|
||||||
|
|
||||||
// A copyable object representing a user specified test property which can be
|
// A copyable object representing a user specified test property which can be
|
||||||
|
@ -59,7 +59,7 @@ GTEST_API_ int main() {
|
|||||||
// Normal platforms: program entry point is main, argc/argv are initialized.
|
// Normal platforms: program entry point is main, argc/argv are initialized.
|
||||||
|
|
||||||
GTEST_API_ int main(int argc, char **argv) {
|
GTEST_API_ int main(int argc, char **argv) {
|
||||||
printf("Running main() from %s\n", __FILE__);
|
// printf("Running main() from %s\n", __FILE__);
|
||||||
testing::InitGoogleTest(&argc, argv);
|
testing::InitGoogleTest(&argc, argv);
|
||||||
return RUN_ALL_TESTS();
|
return RUN_ALL_TESTS();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user