| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_TEST_GTEST_UTIL_H_ | 5 #ifndef BASE_TEST_GTEST_UTIL_H_ |
| 6 #define BASE_TEST_GTEST_UTIL_H_ | 6 #define BASE_TEST_GTEST_UTIL_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 // EXPECT/ASSERT_DCHECK_DEATH is intended to replace EXPECT/ASSERT_DEBUG_DEATH | 17 // EXPECT/ASSERT_DCHECK_DEATH is intended to replace EXPECT/ASSERT_DEBUG_DEATH |
| 18 // when the death is expected to be caused by a DCHECK. Contrary to | 18 // when the death is expected to be caused by a DCHECK. Contrary to |
| 19 // EXPECT/ASSERT_DEBUG_DEATH however, it doesn't execute the statement in non- | 19 // EXPECT/ASSERT_DEBUG_DEATH however, it doesn't execute the statement in non- |
| 20 // dcheck builds as DCHECKs are intended to catch things that should never | 20 // dcheck builds as DCHECKs are intended to catch things that should never |
| 21 // happen and as such executing the statement results in undefined behavior | 21 // happen and as such executing the statement results in undefined behavior |
| 22 // (|statement| is compiled in unsupported configurations nonetheless). | 22 // (|statement| is compiled in unsupported configurations nonetheless). |
| 23 // Death tests misbehave on Android. | 23 // Death tests misbehave on Android. |
| 24 #if DCHECK_IS_ON() && defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID) | 24 #if DCHECK_IS_ON() && defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID) |
| 25 | 25 |
| 26 #define EXPECT_DCHECK_DEATH(statement, regex) EXPECT_DEATH(statement, regex) | 26 // EXPECT/ASSERT_DCHECK_DEATH tests verify that a DCHECK is hit ("Check failed" |
| 27 #define ASSERT_DCHECK_DEATH(statement, regex) ASSERT_DEATH(statement, regex) | 27 // is part of the error message), but intentionally do not expose the gtest |
| 28 // death test's full |regex| parameter to avoid users having to verify the exact |
| 29 // syntax of the error message produced by the DCHECK. |
| 30 #define EXPECT_DCHECK_DEATH(statement) EXPECT_DEATH(statement, "Check failed") |
| 31 #define ASSERT_DCHECK_DEATH(statement) ASSERT_DEATH(statement, "Check failed") |
| 28 | 32 |
| 29 #else | 33 #else |
| 30 // DCHECK_IS_ON() && defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID) | 34 // DCHECK_IS_ON() && defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID) |
| 31 | 35 |
| 32 // Macro copied from gtest-death-test-internal.h as it's (1) internal for now | 36 // Macro copied from gtest-death-test-internal.h as it's (1) internal for now |
| 33 // and (2) only defined if !GTEST_HAS_DEATH_TEST which is only a subset of the | 37 // and (2) only defined if !GTEST_HAS_DEATH_TEST which is only a subset of the |
| 34 // conditions in which it's needed here. | 38 // conditions in which it's needed here. |
| 35 // TODO(gab): Expose macro in upstream gtest repo for consumers like us that | 39 // TODO(gab): Expose macro in upstream gtest repo for consumers like us that |
| 36 // want more specific death tests and remove this hack. | 40 // want more specific death tests and remove this hack. |
| 37 # define GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, terminator) \ | 41 # define GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, terminator) \ |
| 38 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ | 42 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ |
| 39 if (::testing::internal::AlwaysTrue()) { \ | 43 if (::testing::internal::AlwaysTrue()) { \ |
| 40 GTEST_LOG_(WARNING) \ | 44 GTEST_LOG_(WARNING) \ |
| 41 << "Death tests are not supported on this platform.\n" \ | 45 << "Death tests are not supported on this platform.\n" \ |
| 42 << "Statement '" #statement "' cannot be verified."; \ | 46 << "Statement '" #statement "' cannot be verified."; \ |
| 43 } else if (::testing::internal::AlwaysFalse()) { \ | 47 } else if (::testing::internal::AlwaysFalse()) { \ |
| 44 ::testing::internal::RE::PartialMatch(".*", (regex)); \ | 48 ::testing::internal::RE::PartialMatch(".*", (regex)); \ |
| 45 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ | 49 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ |
| 46 terminator; \ | 50 terminator; \ |
| 47 } else \ | 51 } else \ |
| 48 ::testing::Message() | 52 ::testing::Message() |
| 49 | 53 |
| 50 #define EXPECT_DCHECK_DEATH(statement, regex) \ | 54 #define EXPECT_DCHECK_DEATH(statement) \ |
| 51 GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, ) | 55 GTEST_UNSUPPORTED_DEATH_TEST(statement, "Check failed", ) |
| 52 #define ASSERT_DCHECK_DEATH(statement, regex) \ | 56 #define ASSERT_DCHECK_DEATH(statement) \ |
| 53 GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, return) | 57 GTEST_UNSUPPORTED_DEATH_TEST(statement, "Check failed", return) |
| 54 | 58 |
| 55 #endif | 59 #endif |
| 56 // DCHECK_IS_ON() && defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID) | 60 // DCHECK_IS_ON() && defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID) |
| 57 | 61 |
| 58 namespace base { | 62 namespace base { |
| 59 | 63 |
| 60 class FilePath; | 64 class FilePath; |
| 61 | 65 |
| 62 struct TestIdentifier { | 66 struct TestIdentifier { |
| 63 TestIdentifier(); | 67 TestIdentifier(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 84 | 88 |
| 85 // Reads the list of gtest-based tests from |path| into |output|. | 89 // Reads the list of gtest-based tests from |path| into |output|. |
| 86 // Returns true on success. | 90 // Returns true on success. |
| 87 bool ReadTestNamesFromFile( | 91 bool ReadTestNamesFromFile( |
| 88 const FilePath& path, | 92 const FilePath& path, |
| 89 std::vector<TestIdentifier>* output) WARN_UNUSED_RESULT; | 93 std::vector<TestIdentifier>* output) WARN_UNUSED_RESULT; |
| 90 | 94 |
| 91 } // namespace base | 95 } // namespace base |
| 92 | 96 |
| 93 #endif // BASE_TEST_GTEST_UTIL_H_ | 97 #endif // BASE_TEST_GTEST_UTIL_H_ |
| OLD | NEW |