Chromium Code Reviews| Index: base/test/gtest_util.h |
| diff --git a/base/test/gtest_util.h b/base/test/gtest_util.h |
| index f353d8364307dfc39269d71e6d84a448f6cb93b7..9ce23ec0daa7e13ddf8ff15ea553d741654a3029 100644 |
| --- a/base/test/gtest_util.h |
| +++ b/base/test/gtest_util.h |
| @@ -10,6 +10,52 @@ |
| #include <vector> |
| #include "base/compiler_specific.h" |
| +#include "base/logging.h" |
| +#include "build/build_config.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +// EXPECT/ASSERT_DCHECK_DEATH is intended to replace EXPECT/ASSERT_DEBUG_DEATH |
| +// when the death is expected to be caused by a DCHECK. Contrary to |
| +// EXPECT/ASSERT_DEBUG_DEATH however, it doesn't execute the statement in non- |
| +// dcheck builds as DCHECKs are intended to catch things that should never |
| +// happen and as such executing the statement results in undefined behavior |
| +// (|statement| is compiled in unsupported configurations nonetheless). |
| +// Death tests misbehave on Android. |
| +#if DCHECK_IS_ON() && defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID) |
| + |
| +#define EXPECT_DCHECK_DEATH(statement, regex) EXPECT_DEATH(statement, regex) |
| +#define ASSERT_DCHECK_DEATH(statement, regex) ASSERT_DEATH(statement, regex) |
| + |
| +#else |
| +// DCHECK_IS_ON() && defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID) |
| + |
| +// Macro copied from gtest-death-test-internal.h as it's (1) internal for now |
| +// and (2) only defined if !GTEST_HAS_DEATH_TEST which is only a subset of the |
| +// conditions in which it's needed here. |
| +// TODO(gab): Expose macro in upstream gtest repo for consumers like us that |
| +// want more specific death tests and remove this hack. |
| +# define GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, terminator) \ |
| + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ |
|
danakj
2016/07/22 21:15:46
While I understand you copy/pasted this out of gte
gab
2016/07/25 15:46:21
I haven't looked into this macro closely so the an
danakj
2016/07/25 18:45:59
In the event that it all goes to ashes, I just pre
gab
2016/07/27 17:00:50
https://cl/128201478 is approved and we have conse
|
| + if (::testing::internal::AlwaysTrue()) { \ |
| + GTEST_LOG_(WARNING) \ |
| + << "Death tests are not supported on this platform.\n" \ |
| + << "Statement '" #statement "' cannot be verified."; \ |
| + } else if (::testing::internal::AlwaysFalse()) { \ |
| + ::testing::internal::RE::PartialMatch(".*", (regex)); \ |
| + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ |
| + terminator; \ |
| + } else \ |
|
danakj
2016/07/22 21:15:46
nit: {}
gab
2016/07/25 15:46:21
This appears to be intentional. It doesn't compile
|
| + ::testing::Message() |
| + |
| +#define EXPECT_DCHECK_DEATH(statement, regex) \ |
| + GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, ) |
| +#define ASSERT_DCHECK_DEATH(statement, regex) \ |
| + GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, return) |
| + |
| +#undef GTEST_UNSUPPORTED_DEATH_TEST |
| + |
| +#endif |
| +// DCHECK_IS_ON() && defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID) |
| namespace base { |