Googletest export
- Fix a bug in dealing with paramaterized tests where the name is it self a macro expansion. - Add a compile time check to ensure that the parameters to TEST_P and INSTANTIATE_TEST_SUITE_P are not empty. The above fix causes some compilers to fail in that case and even where it works, it's likely to result in technically invalid code by virtue of creating reserved identifiers: https://en.cppreference.com/w/cpp/language/identifiers PiperOrigin-RevId: 274047249
This commit is contained in:
parent
ed78e54f38
commit
a4a5a7c768
@ -429,7 +429,7 @@ internal::CartesianProductHolder<Generator...> Combine(const Generator&... g) {
|
|||||||
::testing::UnitTest::GetInstance() \
|
::testing::UnitTest::GetInstance() \
|
||||||
->parameterized_test_registry() \
|
->parameterized_test_registry() \
|
||||||
.GetTestSuitePatternHolder<test_suite_name>( \
|
.GetTestSuitePatternHolder<test_suite_name>( \
|
||||||
#test_suite_name, \
|
GTEST_STRINGIFY_(test_suite_name), \
|
||||||
::testing::internal::CodeLocation(__FILE__, __LINE__)) \
|
::testing::internal::CodeLocation(__FILE__, __LINE__)) \
|
||||||
->AddTestPattern( \
|
->AddTestPattern( \
|
||||||
GTEST_STRINGIFY_(test_suite_name), GTEST_STRINGIFY_(test_name), \
|
GTEST_STRINGIFY_(test_suite_name), GTEST_STRINGIFY_(test_name), \
|
||||||
@ -493,10 +493,11 @@ internal::CartesianProductHolder<Generator...> Combine(const Generator&... g) {
|
|||||||
::testing::UnitTest::GetInstance() \
|
::testing::UnitTest::GetInstance() \
|
||||||
->parameterized_test_registry() \
|
->parameterized_test_registry() \
|
||||||
.GetTestSuitePatternHolder<test_suite_name>( \
|
.GetTestSuitePatternHolder<test_suite_name>( \
|
||||||
#test_suite_name, \
|
GTEST_STRINGIFY_(test_suite_name), \
|
||||||
::testing::internal::CodeLocation(__FILE__, __LINE__)) \
|
::testing::internal::CodeLocation(__FILE__, __LINE__)) \
|
||||||
->AddTestSuiteInstantiation( \
|
->AddTestSuiteInstantiation( \
|
||||||
#prefix, >est_##prefix##test_suite_name##_EvalGenerator_, \
|
GTEST_STRINGIFY_(prefix), \
|
||||||
|
>est_##prefix##test_suite_name##_EvalGenerator_, \
|
||||||
>est_##prefix##test_suite_name##_EvalGenerateName_, \
|
>est_##prefix##test_suite_name##_EvalGenerateName_, \
|
||||||
__FILE__, __LINE__)
|
__FILE__, __LINE__)
|
||||||
|
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
# include <algorithm>
|
# include <algorithm>
|
||||||
# include <iostream>
|
# include <iostream>
|
||||||
# include <list>
|
# include <list>
|
||||||
|
# include <set>
|
||||||
# include <sstream>
|
# include <sstream>
|
||||||
# include <string>
|
# include <string>
|
||||||
# include <vector>
|
# include <vector>
|
||||||
@ -802,7 +803,7 @@ TEST_P(PREFIX_WITH_MACRO(NamingTest), PREFIX_WITH_FOO(SomeTestName)) {
|
|||||||
::testing::UnitTest::GetInstance()->current_test_info();
|
::testing::UnitTest::GetInstance()->current_test_info();
|
||||||
|
|
||||||
EXPECT_STREQ("FortyTwo/MacroNamingTest", test_info->test_suite_name());
|
EXPECT_STREQ("FortyTwo/MacroNamingTest", test_info->test_suite_name());
|
||||||
EXPECT_STREQ("FooSomeTestName", test_info->name());
|
EXPECT_STREQ("FooSomeTestName/0", test_info->name());
|
||||||
}
|
}
|
||||||
|
|
||||||
INSTANTIATE_TEST_SUITE_P(FortyTwo, MacroNamingTest, Values(42));
|
INSTANTIATE_TEST_SUITE_P(FortyTwo, MacroNamingTest, Values(42));
|
||||||
@ -819,6 +820,36 @@ TEST_F(PREFIX_WITH_MACRO(NamingTestNonParametrized),
|
|||||||
EXPECT_STREQ("FooSomeTestName", test_info->name());
|
EXPECT_STREQ("FooSomeTestName", test_info->name());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(MacroNameing, LookupNames) {
|
||||||
|
std::set<std::string> know_suite_names, know_test_names;
|
||||||
|
|
||||||
|
auto ins = testing::UnitTest::GetInstance();
|
||||||
|
int ts = 0;
|
||||||
|
while (const testing::TestSuite* suite = ins->GetTestSuite(ts++)) {
|
||||||
|
know_suite_names.insert(suite->name());
|
||||||
|
|
||||||
|
int ti = 0;
|
||||||
|
while (const testing::TestInfo* info = suite->GetTestInfo(ti++)) {
|
||||||
|
know_test_names.insert(std::string(suite->name()) + "." + info->name());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check that the expected form of the test suit name actualy exists.
|
||||||
|
EXPECT_NE( //
|
||||||
|
know_suite_names.find("FortyTwo/MacroNamingTest"),
|
||||||
|
know_suite_names.end());
|
||||||
|
EXPECT_NE(
|
||||||
|
know_suite_names.find("MacroNamingTestNonParametrized"),
|
||||||
|
know_suite_names.end());
|
||||||
|
// Check that the expected form of the test name actualy exists.
|
||||||
|
EXPECT_NE( //
|
||||||
|
know_test_names.find("FortyTwo/MacroNamingTest.FooSomeTestName/0"),
|
||||||
|
know_test_names.end());
|
||||||
|
EXPECT_NE(
|
||||||
|
know_test_names.find("MacroNamingTestNonParametrized.FooSomeTestName"),
|
||||||
|
know_test_names.end());
|
||||||
|
}
|
||||||
|
|
||||||
// Tests that user supplied custom parameter names are working correctly.
|
// Tests that user supplied custom parameter names are working correctly.
|
||||||
// Runs the test with a builtin helper method which uses PrintToString,
|
// Runs the test with a builtin helper method which uses PrintToString,
|
||||||
// as well as a custom function and custom functor to ensure all possible
|
// as well as a custom function and custom functor to ensure all possible
|
||||||
|
Loading…
Reference in New Issue
Block a user