googletest
googletest copied to clipboard
[FR]: Add more GTEST_DONT_DEFINE_XXX macros
Does the feature exist in the most recent commit?
No
Why do we need this feature?
Our codebase defines ASSERT_THROW, as does gtest, which obviously clashes
Describe the proposal.
- Add macros to omit defining
ASSERT|EXPECT_XXX - Add macros to define
GTEST_ASSERT|GTEST_EXPECT_XXXwhich is far more unlikely to clash
gtest already has several define checks to selectively skip defining helper macros
eg: GTEST_DONT_DEFINE_EXPECT_TRUE, as shown below:
// Define these macros to 1 to omit the definition of the corresponding
// EXPECT or ASSERT, which clashes with some users' own code.
#if !(defined(GTEST_DONT_DEFINE_EXPECT_TRUE) && GTEST_DONT_DEFINE_EXPECT_TRUE)
#define EXPECT_TRUE(condition) GTEST_EXPECT_TRUE(condition)
#endif
There are, however, some other macros which do not have this switch available, eg:
// Macros for testing exceptions.
//
// * {ASSERT|EXPECT}_THROW(statement, expected_exception):
// Tests that the statement throws the expected exception.
// * {ASSERT|EXPECT}_NO_THROW(statement):
// Tests that the statement doesn't throw any exception.
// * {ASSERT|EXPECT}_ANY_THROW(statement):
// Tests that the statement throws an exception.
#define EXPECT_THROW(statement, expected_exception) \
GTEST_TEST_THROW_(statement, expected_exception, GTEST_NONFATAL_FAILURE_)
#define EXPECT_NO_THROW(statement) \
GTEST_TEST_NO_THROW_(statement, GTEST_NONFATAL_FAILURE_)
#define EXPECT_ANY_THROW(statement) \
GTEST_TEST_ANY_THROW_(statement, GTEST_NONFATAL_FAILURE_)
#define ASSERT_THROW(statement, expected_exception) \
GTEST_TEST_THROW_(statement, expected_exception, GTEST_FATAL_FAILURE_)
#define ASSERT_NO_THROW(statement) \
GTEST_TEST_NO_THROW_(statement, GTEST_FATAL_FAILURE_)
#define ASSERT_ANY_THROW(statement) \
GTEST_TEST_ANY_THROW_(statement, GTEST_FATAL_FAILURE_)
For codebases which already have a definition listed above defined elsewhere, this is problematic.
It would be helpful to omit defining the above macros in selective situations
It would also be helpful to define the above macros with a GTEST_ prefix which will be far less likely to clash
Is the feature specific to an operating system, compiler, or build system version?
No