Merge pull request #1846 from google/9A681768AABE08D1EFA5CA77528236A4
Googletest export
This commit is contained in:
commit
4f55245183
|
@ -100,6 +100,7 @@
|
||||||
#ifndef GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
|
#ifndef GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
|
||||||
#define GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
|
#define GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
#include <ostream> // NOLINT
|
#include <ostream> // NOLINT
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -639,7 +640,15 @@ inline void PrintTo(absl::string_view sp, ::std::ostream* os) {
|
||||||
#endif // GTEST_HAS_ABSL
|
#endif // GTEST_HAS_ABSL
|
||||||
|
|
||||||
#if GTEST_LANG_CXX11
|
#if GTEST_LANG_CXX11
|
||||||
|
|
||||||
inline void PrintTo(std::nullptr_t, ::std::ostream* os) { *os << "(nullptr)"; }
|
inline void PrintTo(std::nullptr_t, ::std::ostream* os) { *os << "(nullptr)"; }
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void PrintTo(std::reference_wrapper<T> ref, ::std::ostream* os) {
|
||||||
|
// Delegate to wrapped value.
|
||||||
|
PrintTo(ref.get(), os);
|
||||||
|
}
|
||||||
|
|
||||||
#endif // GTEST_LANG_CXX11
|
#endif // GTEST_LANG_CXX11
|
||||||
|
|
||||||
#if GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_
|
#if GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_
|
||||||
|
|
|
@ -1189,19 +1189,6 @@ class NativeArray {
|
||||||
GTEST_DISALLOW_ASSIGN_(NativeArray);
|
GTEST_DISALLOW_ASSIGN_(NativeArray);
|
||||||
};
|
};
|
||||||
|
|
||||||
class AdditionalMessage
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
AdditionalMessage(const char* message) : value(message) {}
|
|
||||||
void set(const std::string& message) { value = message; }
|
|
||||||
operator bool() const { return true; }
|
|
||||||
|
|
||||||
const std::string& get() const { return value; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::string value;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
} // namespace testing
|
} // namespace testing
|
||||||
|
|
||||||
|
@ -1229,56 +1216,43 @@ private:
|
||||||
|
|
||||||
#define GTEST_TEST_THROW_(statement, expected_exception, fail) \
|
#define GTEST_TEST_THROW_(statement, expected_exception, fail) \
|
||||||
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
|
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
|
||||||
if (::testing::internal::AdditionalMessage message = "") { \
|
if (::testing::internal::ConstCharPtr gtest_msg = "") { \
|
||||||
bool gtest_caught_expected = false; \
|
bool gtest_caught_expected = false; \
|
||||||
try { \
|
try { \
|
||||||
try { \
|
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
|
||||||
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
|
|
||||||
} \
|
|
||||||
catch (expected_exception const&) { \
|
|
||||||
gtest_caught_expected = true; \
|
|
||||||
throw; \
|
|
||||||
} \
|
|
||||||
} \
|
} \
|
||||||
catch (const std::exception& e) { \
|
catch (expected_exception const&) { \
|
||||||
if (!gtest_caught_expected) { \
|
gtest_caught_expected = true; \
|
||||||
message.set("it throws a different type " \
|
|
||||||
"with message: " + std::string(e.what())); \
|
|
||||||
goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
|
|
||||||
} \
|
|
||||||
} \
|
} \
|
||||||
catch (...) { \
|
catch (...) { \
|
||||||
if (!gtest_caught_expected) { \
|
gtest_msg.value = \
|
||||||
message.set("it throws a different type."); \
|
"Expected: " #statement " throws an exception of type " \
|
||||||
goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
|
#expected_exception ".\n Actual: it throws a different type."; \
|
||||||
} \
|
goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
|
||||||
} \
|
} \
|
||||||
if (!gtest_caught_expected) { \
|
if (!gtest_caught_expected) { \
|
||||||
message.set("it throws nothing."); \
|
gtest_msg.value = \
|
||||||
|
"Expected: " #statement " throws an exception of type " \
|
||||||
|
#expected_exception ".\n Actual: it throws nothing."; \
|
||||||
goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
|
goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
|
||||||
} \
|
} \
|
||||||
} else \
|
} else \
|
||||||
GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \
|
GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \
|
||||||
fail(("Expected: " #statement " throws an exception of type " \
|
fail(gtest_msg.value)
|
||||||
#expected_exception ".\n Actual: " + message.get()).c_str())
|
|
||||||
|
|
||||||
#define GTEST_TEST_NO_THROW_(statement, fail) \
|
#define GTEST_TEST_NO_THROW_(statement, fail) \
|
||||||
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
|
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
|
||||||
if (::testing::internal::AdditionalMessage message = ".") { \
|
if (::testing::internal::AlwaysTrue()) { \
|
||||||
try { \
|
try { \
|
||||||
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
|
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
|
||||||
} \
|
} \
|
||||||
catch (const std::exception& e) { \
|
|
||||||
message.set(std::string(": ") + e.what()); \
|
|
||||||
goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \
|
|
||||||
} \
|
|
||||||
catch (...) { \
|
catch (...) { \
|
||||||
goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \
|
goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \
|
||||||
} \
|
} \
|
||||||
} else \
|
} else \
|
||||||
GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__): \
|
GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__): \
|
||||||
fail(("Expected: " #statement " doesn't throw an exception.\n" \
|
fail("Expected: " #statement " doesn't throw an exception.\n" \
|
||||||
" Actual: it throws" + message.get()).c_str())
|
" Actual: it throws.")
|
||||||
|
|
||||||
#define GTEST_TEST_ANY_THROW_(statement, fail) \
|
#define GTEST_TEST_ANY_THROW_(statement, fail) \
|
||||||
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
|
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
|
||||||
|
|
|
@ -1112,9 +1112,25 @@ TEST(PrintStdTupleTest, NestedTuple) {
|
||||||
#endif // GTEST_LANG_CXX11
|
#endif // GTEST_LANG_CXX11
|
||||||
|
|
||||||
#if GTEST_LANG_CXX11
|
#if GTEST_LANG_CXX11
|
||||||
|
|
||||||
TEST(PrintNullptrT, Basic) {
|
TEST(PrintNullptrT, Basic) {
|
||||||
EXPECT_EQ("(nullptr)", Print(nullptr));
|
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
|
#endif // GTEST_LANG_CXX11
|
||||||
|
|
||||||
// Tests printing user-defined unprintable types.
|
// Tests printing user-defined unprintable types.
|
||||||
|
|
|
@ -3328,9 +3328,6 @@ TEST_F(SingleEvaluationTest, OtherCases) {
|
||||||
void ThrowAnInteger() {
|
void ThrowAnInteger() {
|
||||||
throw 1;
|
throw 1;
|
||||||
}
|
}
|
||||||
void ThrowAnException(const char* what) {
|
|
||||||
throw std::runtime_error(what);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tests that assertion arguments are evaluated exactly once.
|
// Tests that assertion arguments are evaluated exactly once.
|
||||||
TEST_F(SingleEvaluationTest, ExceptionTests) {
|
TEST_F(SingleEvaluationTest, ExceptionTests) {
|
||||||
|
@ -3373,20 +3370,6 @@ TEST_F(SingleEvaluationTest, ExceptionTests) {
|
||||||
// failed EXPECT_ANY_THROW
|
// failed EXPECT_ANY_THROW
|
||||||
EXPECT_NONFATAL_FAILURE(EXPECT_ANY_THROW(a_++), "it doesn't");
|
EXPECT_NONFATAL_FAILURE(EXPECT_ANY_THROW(a_++), "it doesn't");
|
||||||
EXPECT_EQ(7, a_);
|
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
|
#endif // GTEST_HAS_EXCEPTIONS
|
||||||
|
@ -3819,11 +3802,6 @@ TEST(AssertionTest, ASSERT_THROW) {
|
||||||
ASSERT_THROW(ThrowNothing(), bool),
|
ASSERT_THROW(ThrowNothing(), bool),
|
||||||
"Expected: ThrowNothing() throws an exception of type bool.\n"
|
"Expected: ThrowNothing() throws an exception of type bool.\n"
|
||||||
" Actual: it throws nothing.");
|
" 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.
|
// Tests ASSERT_NO_THROW.
|
||||||
|
@ -3832,9 +3810,6 @@ TEST(AssertionTest, ASSERT_NO_THROW) {
|
||||||
EXPECT_FATAL_FAILURE(ASSERT_NO_THROW(ThrowAnInteger()),
|
EXPECT_FATAL_FAILURE(ASSERT_NO_THROW(ThrowAnInteger()),
|
||||||
"Expected: ThrowAnInteger() doesn't throw an exception."
|
"Expected: ThrowAnInteger() doesn't throw an exception."
|
||||||
"\n Actual: it throws.");
|
"\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.
|
// Tests ASSERT_ANY_THROW.
|
||||||
|
@ -4561,16 +4536,13 @@ TEST(ExpectTest, EXPECT_GT) {
|
||||||
// Tests EXPECT_THROW.
|
// Tests EXPECT_THROW.
|
||||||
TEST(ExpectTest, EXPECT_THROW) {
|
TEST(ExpectTest, EXPECT_THROW) {
|
||||||
EXPECT_THROW(ThrowAnInteger(), int);
|
EXPECT_THROW(ThrowAnInteger(), int);
|
||||||
EXPECT_THROW(ThrowAnException(""), std::exception);
|
|
||||||
EXPECT_NONFATAL_FAILURE(EXPECT_THROW(ThrowAnInteger(), bool),
|
EXPECT_NONFATAL_FAILURE(EXPECT_THROW(ThrowAnInteger(), bool),
|
||||||
"Expected: ThrowAnInteger() throws an exception of type bool.\n"
|
"Expected: ThrowAnInteger() throws an exception of "
|
||||||
" Actual: it throws a different type.");
|
"type bool.\n Actual: it throws a different type.");
|
||||||
EXPECT_NONFATAL_FAILURE(EXPECT_THROW(ThrowNothing(), bool),
|
EXPECT_NONFATAL_FAILURE(
|
||||||
"Expected: ThrowNothing() throws an exception of type bool.\n"
|
EXPECT_THROW(ThrowNothing(), bool),
|
||||||
" Actual: it throws nothing.");
|
"Expected: ThrowNothing() throws an exception of type bool.\n"
|
||||||
EXPECT_NONFATAL_FAILURE(EXPECT_THROW(ThrowAnException("buuh"), bool),
|
" Actual: it throws nothing.");
|
||||||
"Expected: ThrowAnException(\"buuh\") throws an exception of type bool.\n"
|
|
||||||
" Actual: it throws a different type with message: buuh");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests EXPECT_NO_THROW.
|
// Tests EXPECT_NO_THROW.
|
||||||
|
@ -4579,9 +4551,6 @@ TEST(ExpectTest, EXPECT_NO_THROW) {
|
||||||
EXPECT_NONFATAL_FAILURE(EXPECT_NO_THROW(ThrowAnInteger()),
|
EXPECT_NONFATAL_FAILURE(EXPECT_NO_THROW(ThrowAnInteger()),
|
||||||
"Expected: ThrowAnInteger() doesn't throw an "
|
"Expected: ThrowAnInteger() doesn't throw an "
|
||||||
"exception.\n Actual: it throws.");
|
"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.
|
// Tests EXPECT_ANY_THROW.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user