summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorzhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925>2011-02-02 01:25:37 +0000
committerzhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925>2011-02-02 01:25:37 +0000
commit34b3f298ed6c093e36511e235fff9d7501ec4395 (patch)
tree856fa37e8b637bae48943f0e9fe6df3d73ad125c /test
parentc5e8d7a2ecb1ff1f8d295f801b89b12deb8c63fb (diff)
downloadgtest-34b3f298ed6c093e36511e235fff9d7501ec4395.tar.gz
gtest-34b3f298ed6c093e36511e235fff9d7501ec4395.tar.bz2
gtest-34b3f298ed6c093e36511e235fff9d7501ec4395.tar.xz
Add markers to death test messages to make them more recogizable (by Jeff Shute).
git-svn-id: http://googletest.googlecode.com/svn/trunk@539 861a406c-534a-0410-8894-cb66d6ee9925
Diffstat (limited to 'test')
-rw-r--r--test/gtest-death-test_test.cc62
1 files changed, 59 insertions, 3 deletions
diff --git a/test/gtest-death-test_test.cc b/test/gtest-death-test_test.cc
index b83b0db..6cc017b 100644
--- a/test/gtest-death-test_test.cc
+++ b/test/gtest-death-test_test.cc
@@ -103,9 +103,10 @@ class ReplaceDeathTestFactory {
} // namespace internal
} // namespace testing
-void DieInside(const char* function) {
- fprintf(stderr, "death inside %s().", function);
- fflush(stderr);
+void DieWithMessage(const ::std::string& message) {
+ fprintf(stderr, "%s", message.c_str());
+ fflush(stderr); // Make sure the text is printed before the process exits.
+
// We call _exit() instead of exit(), as the former is a direct
// system call and thus safer in the presence of threads. exit()
// will invoke user-defined exit-hooks, which may do dangerous
@@ -118,6 +119,10 @@ void DieInside(const char* function) {
_exit(1);
}
+void DieInside(const ::std::string& function) {
+ DieWithMessage("death inside " + function + "().");
+}
+
// Tests that death tests work.
class TestForDeathTest : public testing::Test {
@@ -686,6 +691,57 @@ TEST_F(TestForDeathTest, InvalidStyle) {
}, "This failure is expected.");
}
+TEST_F(TestForDeathTest, DeathTestFailedOutput) {
+ testing::GTEST_FLAG(death_test_style) = "fast";
+ EXPECT_NONFATAL_FAILURE(
+ EXPECT_DEATH(DieWithMessage("death\n"),
+ "expected message"),
+ "Actual msg:\n"
+ "[ DEATH ] death\n");
+}
+
+TEST_F(TestForDeathTest, DeathTestUnexpectedReturnOutput) {
+ testing::GTEST_FLAG(death_test_style) = "fast";
+ EXPECT_NONFATAL_FAILURE(
+ EXPECT_DEATH({
+ fprintf(stderr, "returning\n");
+ fflush(stderr);
+ return;
+ }, ""),
+ " Result: illegal return in test statement.\n"
+ " Error msg:\n"
+ "[ DEATH ] returning\n");
+}
+
+TEST_F(TestForDeathTest, DeathTestBadExitCodeOutput) {
+ testing::GTEST_FLAG(death_test_style) = "fast";
+ EXPECT_NONFATAL_FAILURE(
+ EXPECT_EXIT(DieWithMessage("exiting with rc 1\n"),
+ testing::ExitedWithCode(3),
+ "expected message"),
+ " Result: died but not with expected exit code:\n"
+ " Exited with exit status 1\n"
+ "Actual msg:\n"
+ "[ DEATH ] exiting with rc 1\n");
+}
+
+TEST_F(TestForDeathTest, DeathTestMultiLineMatchFail) {
+ testing::GTEST_FLAG(death_test_style) = "fast";
+ EXPECT_NONFATAL_FAILURE(
+ EXPECT_DEATH(DieWithMessage("line 1\nline 2\nline 3\n"),
+ "line 1\nxyz\nline 3\n"),
+ "Actual msg:\n"
+ "[ DEATH ] line 1\n"
+ "[ DEATH ] line 2\n"
+ "[ DEATH ] line 3\n");
+}
+
+TEST_F(TestForDeathTest, DeathTestMultiLineMatchPass) {
+ testing::GTEST_FLAG(death_test_style) = "fast";
+ EXPECT_DEATH(DieWithMessage("line 1\nline 2\nline 3\n"),
+ "line 1\nline 2\nline 3\n");
+}
+
// A DeathTestFactory that returns MockDeathTests.
class MockDeathTestFactory : public DeathTestFactory {
public: