mirror of
https://github.com/google/googletest.git
synced 2024-12-26 09:31:02 +08:00
Make EXPECT_DEATH_IF_SUPPORTED work with matchers
If death tests were not supported the macro would try to force the second parameter as a string. The second parameter can be a matcher or a string. PiperOrigin-RevId: 633199517 Change-Id: If5e71b4be0b569adb273eb4960202197bb264a8f
This commit is contained in:
parent
fa6de7f438
commit
33af80a883
@ -293,8 +293,8 @@ class GTEST_API_ KilledBySignal {
|
|||||||
// statement is compiled but not executed, to ensure that
|
// statement is compiled but not executed, to ensure that
|
||||||
// EXPECT_DEATH_IF_SUPPORTED compiles with a certain
|
// EXPECT_DEATH_IF_SUPPORTED compiles with a certain
|
||||||
// parameter if and only if EXPECT_DEATH compiles with it.
|
// parameter if and only if EXPECT_DEATH compiles with it.
|
||||||
// regex - A regex that a macro such as EXPECT_DEATH would use to test
|
// regex_or_matcher - A regex that a macro such as EXPECT_DEATH would use
|
||||||
// the output of statement. This parameter has to be
|
// to test the output of statement. This parameter has to be
|
||||||
// compiled but not evaluated by this macro, to ensure that
|
// compiled but not evaluated by this macro, to ensure that
|
||||||
// this macro only accepts expressions that a macro such as
|
// this macro only accepts expressions that a macro such as
|
||||||
// EXPECT_DEATH would accept.
|
// EXPECT_DEATH would accept.
|
||||||
@ -311,13 +311,13 @@ class GTEST_API_ KilledBySignal {
|
|||||||
// statement unconditionally returns or throws. The Message constructor at
|
// statement unconditionally returns or throws. The Message constructor at
|
||||||
// the end allows the syntax of streaming additional messages into the
|
// the end allows the syntax of streaming additional messages into the
|
||||||
// macro, for compilational compatibility with EXPECT_DEATH/ASSERT_DEATH.
|
// macro, for compilational compatibility with EXPECT_DEATH/ASSERT_DEATH.
|
||||||
#define GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, terminator) \
|
#define GTEST_UNSUPPORTED_DEATH_TEST(statement, regex_or_matcher, terminator) \
|
||||||
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
|
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
|
||||||
if (::testing::internal::AlwaysTrue()) { \
|
if (::testing::internal::AlwaysTrue()) { \
|
||||||
GTEST_LOG_(WARNING) << "Death tests are not supported on this platform.\n" \
|
GTEST_LOG_(WARNING) << "Death tests are not supported on this platform.\n" \
|
||||||
<< "Statement '" #statement "' cannot be verified."; \
|
<< "Statement '" #statement "' cannot be verified."; \
|
||||||
} else if (::testing::internal::AlwaysFalse()) { \
|
} else if (::testing::internal::AlwaysFalse()) { \
|
||||||
::testing::internal::RE::PartialMatch(".*", (regex)); \
|
::testing::internal::MakeDeathTestMatcher(regex_or_matcher); \
|
||||||
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
|
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
|
||||||
terminator; \
|
terminator; \
|
||||||
} else \
|
} else \
|
||||||
|
@ -46,6 +46,7 @@
|
|||||||
|
|
||||||
#include "gtest/gtest-matchers.h"
|
#include "gtest/gtest-matchers.h"
|
||||||
#include "gtest/internal/gtest-internal.h"
|
#include "gtest/internal/gtest-internal.h"
|
||||||
|
#include "gtest/internal/gtest-port.h"
|
||||||
|
|
||||||
GTEST_DECLARE_string_(internal_run_death_test);
|
GTEST_DECLARE_string_(internal_run_death_test);
|
||||||
|
|
||||||
@ -55,6 +56,28 @@ namespace internal {
|
|||||||
// Name of the flag (needed for parsing Google Test flag).
|
// Name of the flag (needed for parsing Google Test flag).
|
||||||
const char kInternalRunDeathTestFlag[] = "internal_run_death_test";
|
const char kInternalRunDeathTestFlag[] = "internal_run_death_test";
|
||||||
|
|
||||||
|
// A string passed to EXPECT_DEATH (etc.) is caught by one of these overloads
|
||||||
|
// and interpreted as a regex (rather than an Eq matcher) for legacy
|
||||||
|
// compatibility.
|
||||||
|
inline Matcher<const ::std::string&> MakeDeathTestMatcher(
|
||||||
|
::testing::internal::RE regex) {
|
||||||
|
return ContainsRegex(regex.pattern());
|
||||||
|
}
|
||||||
|
inline Matcher<const ::std::string&> MakeDeathTestMatcher(const char* regex) {
|
||||||
|
return ContainsRegex(regex);
|
||||||
|
}
|
||||||
|
inline Matcher<const ::std::string&> MakeDeathTestMatcher(
|
||||||
|
const ::std::string& regex) {
|
||||||
|
return ContainsRegex(regex);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If a Matcher<const ::std::string&> is passed to EXPECT_DEATH (etc.), it's
|
||||||
|
// used directly.
|
||||||
|
inline Matcher<const ::std::string&> MakeDeathTestMatcher(
|
||||||
|
Matcher<const ::std::string&> matcher) {
|
||||||
|
return matcher;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef GTEST_HAS_DEATH_TEST
|
#ifdef GTEST_HAS_DEATH_TEST
|
||||||
|
|
||||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
|
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
|
||||||
@ -168,28 +191,6 @@ class DefaultDeathTestFactory : public DeathTestFactory {
|
|||||||
// by a signal, or exited normally with a nonzero exit code.
|
// by a signal, or exited normally with a nonzero exit code.
|
||||||
GTEST_API_ bool ExitedUnsuccessfully(int exit_status);
|
GTEST_API_ bool ExitedUnsuccessfully(int exit_status);
|
||||||
|
|
||||||
// A string passed to EXPECT_DEATH (etc.) is caught by one of these overloads
|
|
||||||
// and interpreted as a regex (rather than an Eq matcher) for legacy
|
|
||||||
// compatibility.
|
|
||||||
inline Matcher<const ::std::string&> MakeDeathTestMatcher(
|
|
||||||
::testing::internal::RE regex) {
|
|
||||||
return ContainsRegex(regex.pattern());
|
|
||||||
}
|
|
||||||
inline Matcher<const ::std::string&> MakeDeathTestMatcher(const char* regex) {
|
|
||||||
return ContainsRegex(regex);
|
|
||||||
}
|
|
||||||
inline Matcher<const ::std::string&> MakeDeathTestMatcher(
|
|
||||||
const ::std::string& regex) {
|
|
||||||
return ContainsRegex(regex);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If a Matcher<const ::std::string&> is passed to EXPECT_DEATH (etc.), it's
|
|
||||||
// used directly.
|
|
||||||
inline Matcher<const ::std::string&> MakeDeathTestMatcher(
|
|
||||||
Matcher<const ::std::string&> matcher) {
|
|
||||||
return matcher;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Traps C++ exceptions escaping statement and reports them as test
|
// Traps C++ exceptions escaping statement and reports them as test
|
||||||
// failures. Note that trapping SEH exceptions is not implemented here.
|
// failures. Note that trapping SEH exceptions is not implemented here.
|
||||||
#if GTEST_HAS_EXCEPTIONS
|
#if GTEST_HAS_EXCEPTIONS
|
||||||
|
Loading…
x
Reference in New Issue
Block a user