summaryrefslogtreecommitdiffstats
path: root/googletest/test
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2018-09-17 14:42:55 (GMT)
committergennadiycivil <misterg@google.com>2018-09-20 15:01:16 (GMT)
commit1b20bd176fb3bc6feef4ab17488a2ac8850f42dd (patch)
treed3758fb385322e4e31d1f3526dfaeecc7643f391 /googletest/test
parent9ea01728503a445179353113d2854492f41bee84 (diff)
downloadgoogletest-1b20bd176fb3bc6feef4ab17488a2ac8850f42dd.zip
googletest-1b20bd176fb3bc6feef4ab17488a2ac8850f42dd.tar.gz
googletest-1b20bd176fb3bc6feef4ab17488a2ac8850f42dd.tar.bz2
Googletest export
support printing std::reference_wrapper<T> in gUnit PiperOrigin-RevId: 213270392
Diffstat (limited to 'googletest/test')
-rw-r--r--googletest/test/googletest-printers-test.cc16
-rw-r--r--googletest/test/gtest_unittest.cc43
2 files changed, 22 insertions, 37 deletions
diff --git a/googletest/test/googletest-printers-test.cc b/googletest/test/googletest-printers-test.cc
index ea8369d..6e26274 100644
--- a/googletest/test/googletest-printers-test.cc
+++ b/googletest/test/googletest-printers-test.cc
@@ -1112,9 +1112,25 @@ TEST(PrintStdTupleTest, NestedTuple) {
#endif // GTEST_LANG_CXX11
#if GTEST_LANG_CXX11
+
TEST(PrintNullptrT, Basic) {
EXPECT_EQ("(nullptr)", Print(nullptr));
}
+
+TEST(PrintReferenceWrapper, Printable) {
+ int x = 5;
+ EXPECT_EQ("5", Print(std::ref(x)));
+ EXPECT_EQ("5", Print(std::cref(x)));
+}
+
+TEST(PrintReferenceWrapper, Unprintable) {
+ ::foo::UnprintableInFoo up;
+ EXPECT_EQ("16-byte object <EF-12 00-00 34-AB 00-00 00-00 00-00 00-00 00-00>",
+ Print(std::ref(up)));
+ EXPECT_EQ("16-byte object <EF-12 00-00 34-AB 00-00 00-00 00-00 00-00 00-00>",
+ Print(std::cref(up)));
+}
+
#endif // GTEST_LANG_CXX11
// Tests printing user-defined unprintable types.
diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc
index 6b75ab4..701ba20 100644
--- a/googletest/test/gtest_unittest.cc
+++ b/googletest/test/gtest_unittest.cc
@@ -3328,9 +3328,6 @@ TEST_F(SingleEvaluationTest, OtherCases) {
void ThrowAnInteger() {
throw 1;
}
-void ThrowAnException(const char* what) {
- throw std::runtime_error(what);
-}
// Tests that assertion arguments are evaluated exactly once.
TEST_F(SingleEvaluationTest, ExceptionTests) {
@@ -3373,20 +3370,6 @@ TEST_F(SingleEvaluationTest, ExceptionTests) {
// failed EXPECT_ANY_THROW
EXPECT_NONFATAL_FAILURE(EXPECT_ANY_THROW(a_++), "it doesn't");
EXPECT_EQ(7, a_);
-
- // failed EXPECT_THROW std::exception, throws different
- EXPECT_NONFATAL_FAILURE(EXPECT_THROW({ // NOLINT
- a_++;
- ThrowAnInteger();
- }, std::exception), "throws a different type");
- EXPECT_EQ(8, a_);
-
- // failed EXPECT_THROW, throws std::exception
- EXPECT_NONFATAL_FAILURE(EXPECT_THROW({ // NOLINT
- a_++;
- ThrowAnException("blablubb");
- }, bool), "throws a different type with message: blablubb");
- EXPECT_EQ(9, a_);
}
#endif // GTEST_HAS_EXCEPTIONS
@@ -3819,11 +3802,6 @@ TEST(AssertionTest, ASSERT_THROW) {
ASSERT_THROW(ThrowNothing(), bool),
"Expected: ThrowNothing() throws an exception of type bool.\n"
" Actual: it throws nothing.");
-
- EXPECT_FATAL_FAILURE(
- ASSERT_THROW(ThrowAnException("buuh"), bool),
- "Expected: ThrowAnException(\"buuh\") throws an exception of type bool.\n"
- " Actual: it throws a different type with message: buuh");
}
// Tests ASSERT_NO_THROW.
@@ -3832,9 +3810,6 @@ TEST(AssertionTest, ASSERT_NO_THROW) {
EXPECT_FATAL_FAILURE(ASSERT_NO_THROW(ThrowAnInteger()),
"Expected: ThrowAnInteger() doesn't throw an exception."
"\n Actual: it throws.");
- EXPECT_FATAL_FAILURE(ASSERT_NO_THROW(ThrowAnException("blablubb")),
- "Expected: ThrowAnException(\"blablubb\") doesn't throw an exception."
- "\n Actual: it throws: blablubb");
}
// Tests ASSERT_ANY_THROW.
@@ -4561,16 +4536,13 @@ TEST(ExpectTest, EXPECT_GT) {
// Tests EXPECT_THROW.
TEST(ExpectTest, EXPECT_THROW) {
EXPECT_THROW(ThrowAnInteger(), int);
- EXPECT_THROW(ThrowAnException(""), std::exception);
EXPECT_NONFATAL_FAILURE(EXPECT_THROW(ThrowAnInteger(), bool),
- "Expected: ThrowAnInteger() throws an exception of type bool.\n"
- " Actual: it throws a different type.");
- EXPECT_NONFATAL_FAILURE(EXPECT_THROW(ThrowNothing(), bool),
- "Expected: ThrowNothing() throws an exception of type bool.\n"
- " Actual: it throws nothing.");
- EXPECT_NONFATAL_FAILURE(EXPECT_THROW(ThrowAnException("buuh"), bool),
- "Expected: ThrowAnException(\"buuh\") throws an exception of type bool.\n"
- " Actual: it throws a different type with message: buuh");
+ "Expected: ThrowAnInteger() throws an exception of "
+ "type bool.\n Actual: it throws a different type.");
+ EXPECT_NONFATAL_FAILURE(
+ EXPECT_THROW(ThrowNothing(), bool),
+ "Expected: ThrowNothing() throws an exception of type bool.\n"
+ " Actual: it throws nothing.");
}
// Tests EXPECT_NO_THROW.
@@ -4579,9 +4551,6 @@ TEST(ExpectTest, EXPECT_NO_THROW) {
EXPECT_NONFATAL_FAILURE(EXPECT_NO_THROW(ThrowAnInteger()),
"Expected: ThrowAnInteger() doesn't throw an "
"exception.\n Actual: it throws.");
- EXPECT_NONFATAL_FAILURE(EXPECT_NO_THROW(ThrowAnException("blablubb")),
- "Expected: ThrowAnException(\"blablubb\") doesn't throw an "
- "exception.\n Actual: it throws: blablubb");
}
// Tests EXPECT_ANY_THROW.