summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorjgm@google.com <jgm@google.com@861a406c-534a-0410-8894-cb66d6ee9925>2012-03-09 17:12:39 +0000
committerjgm@google.com <jgm@google.com@861a406c-534a-0410-8894-cb66d6ee9925>2012-03-09 17:12:39 +0000
commit7a574c99ea1d474f8ec5f040deba54169120f063 (patch)
treedea331f222e639cfc37f481766bbc88ce20dc7cb /test
parent62576d5b3fb1173e4ad1b7fbc98f9d58323dfc64 (diff)
downloadgoogletest-7a574c99ea1d474f8ec5f040deba54169120f063.tar.gz
Misc small updates to some debug death code, and to messages streaming to macros
git-svn-id: http://googletest.googlecode.com/svn/trunk@612 861a406c-534a-0410-8894-cb66d6ee9925
Diffstat (limited to 'test')
-rw-r--r--test/gtest-death-test_test.cc32
-rwxr-xr-xtest/gtest_env_var_test.py3
-rwxr-xr-xtest/gtest_output_test.py2
-rw-r--r--test/gtest_output_test_.cc8
-rwxr-xr-xtest/gtest_shuffle_test.py3
-rw-r--r--test/gtest_unittest.cc121
6 files changed, 140 insertions, 29 deletions
diff --git a/test/gtest-death-test_test.cc b/test/gtest-death-test_test.cc
index 5a4a989..b389e73 100644
--- a/test/gtest-death-test_test.cc
+++ b/test/gtest-death-test_test.cc
@@ -618,8 +618,8 @@ TEST_F(TestForDeathTest, ReturnIsFailure) {
"illegal return in test statement.");
}
-// Tests that EXPECT_DEBUG_DEATH works as expected,
-// that is, in debug mode, it:
+// Tests that EXPECT_DEBUG_DEATH works as expected, that is, you can stream a
+// message to it, and in debug mode it:
// 1. Asserts on death.
// 2. Has no side effect.
//
@@ -628,8 +628,8 @@ TEST_F(TestForDeathTest, ReturnIsFailure) {
TEST_F(TestForDeathTest, TestExpectDebugDeath) {
int sideeffect = 0;
- EXPECT_DEBUG_DEATH(DieInDebugElse12(&sideeffect),
- "death.*DieInDebugElse12");
+ EXPECT_DEBUG_DEATH(DieInDebugElse12(&sideeffect), "death.*DieInDebugElse12")
+ << "Must accept a streamed message";
# ifdef NDEBUG
@@ -644,22 +644,18 @@ TEST_F(TestForDeathTest, TestExpectDebugDeath) {
# endif
}
-// Tests that ASSERT_DEBUG_DEATH works as expected
-// In debug mode:
-// 1. Asserts on debug death.
+// Tests that ASSERT_DEBUG_DEATH works as expected, that is, you can stream a
+// message to it, and in debug mode it:
+// 1. Asserts on death.
// 2. Has no side effect.
//
-// In opt mode:
-// 1. Has side effects and returns the expected value (12).
+// And in opt mode, it:
+// 1. Has side effects but does not assert.
TEST_F(TestForDeathTest, TestAssertDebugDeath) {
int sideeffect = 0;
- ASSERT_DEBUG_DEATH({ // NOLINT
- // Tests that the return value is 12 in opt mode.
- EXPECT_EQ(12, DieInDebugElse12(&sideeffect));
- // Tests that the side effect occurred in opt mode.
- EXPECT_EQ(12, sideeffect);
- }, "death.*DieInDebugElse12");
+ ASSERT_DEBUG_DEATH(DieInDebugElse12(&sideeffect), "death.*DieInDebugElse12")
+ << "Must accept a streamed message";
# ifdef NDEBUG
@@ -730,7 +726,7 @@ static void TestExitMacros() {
// Of all signals effects on the process exit code, only those of SIGABRT
// are documented on Windows.
// See http://msdn.microsoft.com/en-us/library/dwwzkt4c(VS.71).aspx.
- EXPECT_EXIT(raise(SIGABRT), testing::ExitedWithCode(3), "");
+ EXPECT_EXIT(raise(SIGABRT), testing::ExitedWithCode(3), "") << "b_ar";
# else
@@ -739,14 +735,14 @@ static void TestExitMacros() {
EXPECT_FATAL_FAILURE({ // NOLINT
ASSERT_EXIT(_exit(0), testing::KilledBySignal(SIGSEGV), "")
- << "This failure is expected, too.";
+ << "This failure is expected, too.";
}, "This failure is expected, too.");
# endif // GTEST_OS_WINDOWS
EXPECT_NONFATAL_FAILURE({ // NOLINT
EXPECT_EXIT(raise(SIGSEGV), testing::ExitedWithCode(0), "")
- << "This failure is expected.";
+ << "This failure is expected.";
}, "This failure is expected.");
}
diff --git a/test/gtest_env_var_test.py b/test/gtest_env_var_test.py
index ac24337..4728bbc 100755
--- a/test/gtest_env_var_test.py
+++ b/test/gtest_env_var_test.py
@@ -67,7 +67,8 @@ def GetFlag(flag):
args = [COMMAND]
if flag is not None:
args += [flag]
- return gtest_test_utils.Subprocess(args, env=environ).output
+ return gtest_test_utils.Subprocess(args, env=environ,
+ capture_stderr=False).output
def TestFlag(flag, test_val, default_val):
diff --git a/test/gtest_output_test.py b/test/gtest_output_test.py
index f409e2a..72b3ae0 100755
--- a/test/gtest_output_test.py
+++ b/test/gtest_output_test.py
@@ -213,7 +213,7 @@ def GetShellCommandOutput(env_cmd):
# Set and save the environment properly.
environ = os.environ.copy()
environ.update(env_cmd[0])
- p = gtest_test_utils.Subprocess(env_cmd[1], env=environ)
+ p = gtest_test_utils.Subprocess(env_cmd[1], env=environ, capture_stderr=False)
return p.output
diff --git a/test/gtest_output_test_.cc b/test/gtest_output_test_.cc
index 031ae83..1b08b65 100644
--- a/test/gtest_output_test_.cc
+++ b/test/gtest_output_test_.cc
@@ -221,13 +221,13 @@ TEST(SCOPED_TRACETest, CanBeRepeated) {
{
SCOPED_TRACE("C");
- ADD_FAILURE() << "This failure is expected, and should contain "
- << "trace point A, B, and C.";
+ ADD_FAILURE() << "This failure is expected, and should "
+ << "contain trace point A, B, and C.";
}
SCOPED_TRACE("D");
- ADD_FAILURE() << "This failure is expected, and should contain "
- << "trace point A, B, and D.";
+ ADD_FAILURE() << "This failure is expected, and should "
+ << "contain trace point A, B, and D.";
}
#if GTEST_IS_THREADSAFE
diff --git a/test/gtest_shuffle_test.py b/test/gtest_shuffle_test.py
index 30d0303..d3e5780 100755
--- a/test/gtest_shuffle_test.py
+++ b/test/gtest_shuffle_test.py
@@ -81,7 +81,8 @@ def RunAndReturnOutput(extra_env, args):
environ_copy = os.environ.copy()
environ_copy.update(extra_env)
- return gtest_test_utils.Subprocess([COMMAND] + args, env=environ_copy).output
+ return gtest_test_utils.Subprocess([COMMAND] + args, env=environ_copy,
+ capture_stderr=False).output
def GetTestsForAllIterations(extra_env, args):
diff --git a/test/gtest_unittest.cc b/test/gtest_unittest.cc
index 8cd58be..e61f791 100644
--- a/test/gtest_unittest.cc
+++ b/test/gtest_unittest.cc
@@ -2642,6 +2642,11 @@ TEST(StringAssertionTest, STREQ_Wide) {
// Strings containing wide characters.
EXPECT_NONFATAL_FAILURE(EXPECT_STREQ(L"abc\x8119", L"abc\x8120"),
"abc");
+
+ // The streaming variation.
+ EXPECT_NONFATAL_FAILURE({ // NOLINT
+ EXPECT_STREQ(L"abc\x8119", L"abc\x8121") << "Expected failure";
+ }, "Expected failure");
}
// Tests *_STRNE on wide strings.
@@ -2668,6 +2673,9 @@ TEST(StringAssertionTest, STRNE_Wide) {
// Strings containing wide characters.
EXPECT_NONFATAL_FAILURE(EXPECT_STRNE(L"abc\x8119", L"abc\x8119"),
"abc");
+
+ // The streaming variation.
+ ASSERT_STRNE(L"abc\x8119", L"abc\x8120") << "This shouldn't happen";
}
// Tests for ::testing::IsSubstring().
@@ -4263,8 +4271,109 @@ TEST(SuccessfulAssertionTest, ASSERT_STR) {
namespace {
+// Tests the message streaming variation of assertions.
+
+TEST(AssertionWithMessageTest, EXPECT) {
+ EXPECT_EQ(1, 1) << "This should succeed.";
+ EXPECT_NONFATAL_FAILURE(EXPECT_NE(1, 1) << "Expected failure #1.",
+ "Expected failure #1");
+ EXPECT_LE(1, 2) << "This should succeed.";
+ EXPECT_NONFATAL_FAILURE(EXPECT_LT(1, 0) << "Expected failure #2.",
+ "Expected failure #2.");
+ EXPECT_GE(1, 0) << "This should succeed.";
+ EXPECT_NONFATAL_FAILURE(EXPECT_GT(1, 2) << "Expected failure #3.",
+ "Expected failure #3.");
+
+ EXPECT_STREQ("1", "1") << "This should succeed.";
+ EXPECT_NONFATAL_FAILURE(EXPECT_STRNE("1", "1") << "Expected failure #4.",
+ "Expected failure #4.");
+ EXPECT_STRCASEEQ("a", "A") << "This should succeed.";
+ EXPECT_NONFATAL_FAILURE(EXPECT_STRCASENE("a", "A") << "Expected failure #5.",
+ "Expected failure #5.");
+
+ EXPECT_FLOAT_EQ(1, 1) << "This should succeed.";
+ EXPECT_NONFATAL_FAILURE(EXPECT_DOUBLE_EQ(1, 1.2) << "Expected failure #6.",
+ "Expected failure #6.");
+ EXPECT_NEAR(1, 1.1, 0.2) << "This should succeed.";
+}
+
+TEST(AssertionWithMessageTest, ASSERT) {
+ ASSERT_EQ(1, 1) << "This should succeed.";
+ ASSERT_NE(1, 2) << "This should succeed.";
+ ASSERT_LE(1, 2) << "This should succeed.";
+ ASSERT_LT(1, 2) << "This should succeed.";
+ ASSERT_GE(1, 0) << "This should succeed.";
+ EXPECT_FATAL_FAILURE(ASSERT_GT(1, 2) << "Expected failure.",
+ "Expected failure.");
+}
+
+TEST(AssertionWithMessageTest, ASSERT_STR) {
+ ASSERT_STREQ("1", "1") << "This should succeed.";
+ ASSERT_STRNE("1", "2") << "This should succeed.";
+ ASSERT_STRCASEEQ("a", "A") << "This should succeed.";
+ EXPECT_FATAL_FAILURE(ASSERT_STRCASENE("a", "A") << "Expected failure.",
+ "Expected failure.");
+}
+
+TEST(AssertionWithMessageTest, ASSERT_FLOATING) {
+ ASSERT_FLOAT_EQ(1, 1) << "This should succeed.";
+ ASSERT_DOUBLE_EQ(1, 1) << "This should succeed.";
+ EXPECT_FATAL_FAILURE(ASSERT_NEAR(1,1.2, 0.1) << "Expect failure.", // NOLINT
+ "Expect failure.");
+ // To work around a bug in gcc 2.95.0, there is intentionally no
+ // space after the first comma in the previous statement.
+}
+
+// Tests using ASSERT_FALSE with a streamed message.
+TEST(AssertionWithMessageTest, ASSERT_FALSE) {
+ ASSERT_FALSE(false) << "This shouldn't fail.";
+ EXPECT_FATAL_FAILURE({ // NOLINT
+ ASSERT_FALSE(true) << "Expected failure: " << 2 << " > " << 1
+ << " evaluates to " << true;
+ }, "Expected failure");
+}
+
+// Tests using FAIL with a streamed message.
+TEST(AssertionWithMessageTest, FAIL) {
+ EXPECT_FATAL_FAILURE(FAIL() << 0,
+ "0");
+}
+
+// Tests using SUCCEED with a streamed message.
+TEST(AssertionWithMessageTest, SUCCEED) {
+ SUCCEED() << "Success == " << 1;
+}
+
+// Tests using ASSERT_TRUE with a streamed message.
+TEST(AssertionWithMessageTest, ASSERT_TRUE) {
+ ASSERT_TRUE(true) << "This should succeed.";
+ ASSERT_TRUE(true) << true;
+ EXPECT_FATAL_FAILURE({ // NOLINT
+ ASSERT_TRUE(false) << static_cast<const char *>(NULL)
+ << static_cast<char *>(NULL);
+ }, "(null)(null)");
+}
+
+#if GTEST_OS_WINDOWS
+// Tests using wide strings in assertion messages.
+TEST(AssertionWithMessageTest, WideStringMessage) {
+ EXPECT_NONFATAL_FAILURE({ // NOLINT
+ EXPECT_TRUE(false) << L"This failure is expected.\x8119";
+ }, "This failure is expected.");
+ EXPECT_FATAL_FAILURE({ // NOLINT
+ ASSERT_EQ(1, 2) << "This failure is "
+ << L"expected too.\x8120";
+ }, "This failure is expected too.");
+}
+#endif // GTEST_OS_WINDOWS
+
// Tests EXPECT_TRUE.
TEST(ExpectTest, EXPECT_TRUE) {
+ EXPECT_TRUE(true) << "Intentional success";
+ EXPECT_NONFATAL_FAILURE(EXPECT_TRUE(false) << "Intentional failure #1.",
+ "Intentional failure #1.");
+ EXPECT_NONFATAL_FAILURE(EXPECT_TRUE(false) << "Intentional failure #2.",
+ "Intentional failure #2.");
EXPECT_TRUE(2 > 1); // NOLINT
EXPECT_NONFATAL_FAILURE(EXPECT_TRUE(2 < 1),
"Value of: 2 < 1\n"
@@ -4288,9 +4397,14 @@ TEST(ExpectTest, ExpectTrueWithAssertionResult) {
"Expected: true");
}
-// Tests EXPECT_FALSE.
+// Tests EXPECT_FALSE with a streamed message.
TEST(ExpectTest, EXPECT_FALSE) {
EXPECT_FALSE(2 < 1); // NOLINT
+ EXPECT_FALSE(false) << "Intentional success";
+ EXPECT_NONFATAL_FAILURE(EXPECT_FALSE(true) << "Intentional failure #1.",
+ "Intentional failure #1.");
+ EXPECT_NONFATAL_FAILURE(EXPECT_FALSE(true) << "Intentional failure #2.",
+ "Intentional failure #2.");
EXPECT_NONFATAL_FAILURE(EXPECT_FALSE(2 > 1),
"Value of: 2 > 1\n"
" Actual: true\n"
@@ -4564,7 +4678,7 @@ TEST(StreamableTest, BasicIoManip) {
void AddFailureHelper(bool* aborted) {
*aborted = true;
- ADD_FAILURE() << "Failure";
+ ADD_FAILURE() << "Intentional failure.";
*aborted = false;
}
@@ -4572,7 +4686,7 @@ void AddFailureHelper(bool* aborted) {
TEST(MacroTest, ADD_FAILURE) {
bool aborted = true;
EXPECT_NONFATAL_FAILURE(AddFailureHelper(&aborted),
- "Failure");
+ "Intentional failure.");
EXPECT_FALSE(aborted);
}
@@ -4605,7 +4719,6 @@ TEST(MacroTest, SUCCEED) {
SUCCEED() << "Explicit success.";
}
-
// Tests for EXPECT_EQ() and ASSERT_EQ().
//
// These tests fail *intentionally*, s.t. the failure messages can be