summaryrefslogtreecommitdiffstats
path: root/googletest/include/gtest/internal
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2018-09-20 19:00:10 (GMT)
committerGennadiy Civil <misterg@google.com>2018-09-25 17:05:03 (GMT)
commit0fc5466dbb9e623029b1ada539717d10bd45e99e (patch)
treebef699c01b39a7b16319098dfea58ec4adf6a154 /googletest/include/gtest/internal
parent0f7f5cd93a7cc866443eb882643acdd8b335cffd (diff)
downloadgoogletest-0fc5466dbb9e623029b1ada539717d10bd45e99e.zip
googletest-0fc5466dbb9e623029b1ada539717d10bd45e99e.tar.gz
googletest-0fc5466dbb9e623029b1ada539717d10bd45e99e.tar.bz2
Googletest export
Project import generated by Copybara. Including recently accepted and merged PRs PiperOrigin-RevId: 213856848
Diffstat (limited to 'googletest/include/gtest/internal')
-rw-r--r--googletest/include/gtest/internal/gtest-internal.h105
1 files changed, 39 insertions, 66 deletions
diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h
index 4dcc587..b762f61 100644
--- a/googletest/include/gtest/internal/gtest-internal.h
+++ b/googletest/include/gtest/internal/gtest-internal.h
@@ -1189,18 +1189,6 @@ class NativeArray {
GTEST_DISALLOW_ASSIGN_(NativeArray);
};
-class AdditionalMessage {
- public:
- AdditionalMessage(const char* message) : msg(message) {}
- void set(const std::string& message) { msg = message; }
- operator bool() const { return true; }
-
- const std::string& get() const { return msg; }
-
- private:
- std::string msg;
-};
-
} // namespace internal
} // namespace testing
@@ -1226,60 +1214,45 @@ class AdditionalMessage {
#define GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) \
if (::testing::internal::AlwaysTrue()) { statement; }
-#define GTEST_TEST_THROW_(statement, expected_exception, fail) \
- GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
- if (::testing::internal::AdditionalMessage message = "") { \
- bool gtest_caught_expected = false; \
- try { \
- try { \
- GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
- } catch (expected_exception const&) { \
- gtest_caught_expected = true; \
- throw; \
- } \
- } catch (const std::exception& e) { \
- if (!gtest_caught_expected) { \
- message.set( \
- "it throws a different type " \
- "with message: " + \
- std::string(e.what())); \
- goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
- } \
- } catch (...) { \
- if (!gtest_caught_expected) { \
- message.set("it throws a different type."); \
- goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
- } \
- } \
- if (!gtest_caught_expected) { \
- message.set("it throws nothing."); \
- goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
- } \
- } else \
- GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__) \
- : fail(("Expected: " #statement \
- " throws an exception of type " #expected_exception \
- ".\n Actual: " + \
- message.get()) \
- .c_str())
-
-#define GTEST_TEST_NO_THROW_(statement, fail) \
- GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
- if (::testing::internal::AdditionalMessage message = ".") { \
- try { \
- 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 (...) { \
- goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \
- } \
- } else \
- GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__) \
- : fail(("Expected: " #statement " doesn't throw an exception.\n" \
- " Actual: it throws" + \
- message.get()) \
- .c_str())
+#define GTEST_TEST_THROW_(statement, expected_exception, fail) \
+ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
+ if (::testing::internal::ConstCharPtr gtest_msg = "") { \
+ bool gtest_caught_expected = false; \
+ try { \
+ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
+ } \
+ catch (expected_exception const&) { \
+ gtest_caught_expected = true; \
+ } \
+ catch (...) { \
+ gtest_msg.value = \
+ "Expected: " #statement " throws an exception of type " \
+ #expected_exception ".\n Actual: it throws a different type."; \
+ goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
+ } \
+ if (!gtest_caught_expected) { \
+ 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__); \
+ } \
+ } else \
+ GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \
+ fail(gtest_msg.value)
+
+#define GTEST_TEST_NO_THROW_(statement, fail) \
+ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
+ if (::testing::internal::AlwaysTrue()) { \
+ try { \
+ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
+ } \
+ catch (...) { \
+ goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \
+ } \
+ } else \
+ GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__): \
+ fail("Expected: " #statement " doesn't throw an exception.\n" \
+ " Actual: it throws.")
#define GTEST_TEST_ANY_THROW_(statement, fail) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \