diff options
author | Bernhard Bauer <bauerb@chromium.org> | 2018-03-12 13:51:04 (GMT) |
---|---|---|
committer | Bernhard Bauer <bauerb@chromium.org> | 2018-03-12 18:14:06 (GMT) |
commit | 7b70413e0ca57b3e48d7655f342122f159f52b31 (patch) | |
tree | e9339fcd1ff6deb4e9b5f76b11012a4941984ddd /googletest/test | |
parent | 7a2563a514563145d82f02b5b350cba1af33af67 (diff) | |
download | googletest-7b70413e0ca57b3e48d7655f342122f159f52b31.zip googletest-7b70413e0ca57b3e48d7655f342122f159f52b31.tar.gz googletest-7b70413e0ca57b3e48d7655f342122f159f52b31.tar.bz2 |
Allow macros inside of parametrized test names.
This allows doing things like TEST_P(TestFixture, MAYBE(TestName))
for nicer conditional test disabling.
Upstream of cr/188748737.
Tested:
Added unit tests MacroNamingTest and MacroNamingTestNonParametrized.
Diffstat (limited to 'googletest/test')
-rw-r--r-- | googletest/test/gtest-param-test_test.cc | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/googletest/test/gtest-param-test_test.cc b/googletest/test/gtest-param-test_test.cc index b0aa4f9..16d1e6e 100644 --- a/googletest/test/gtest-param-test_test.cc +++ b/googletest/test/gtest-param-test_test.cc @@ -803,6 +803,34 @@ TEST_P(NamingTest, TestsReportCorrectNamesAndParameters) { INSTANTIATE_TEST_CASE_P(ZeroToFiveSequence, NamingTest, Range(0, 5)); +// Tests that macros in test names are expanded correctly. +class MacroNamingTest : public TestWithParam<int> {}; + +#define PREFIX_WITH_FOO(test_name) Foo##test_name +#define PREFIX_WITH_MACRO(test_name) Macro##test_name + +TEST_P(PREFIX_WITH_MACRO(NamingTest), PREFIX_WITH_FOO(SomeTestName)) { + const ::testing::TestInfo* const test_info = + ::testing::UnitTest::GetInstance()->current_test_info(); + + EXPECT_STREQ("FortyTwo/MacroNamingTest", test_info->test_case_name()); + EXPECT_STREQ("FooSomeTestName", test_info->name()); +} + +INSTANTIATE_TEST_CASE_P(FortyTwo, MacroNamingTest, Values(42)); + +// Tests the same thing for non-parametrized tests. +class MacroNamingTestNonParametrized : public ::testing::Test {}; + +TEST_F(PREFIX_WITH_MACRO(NamingTestNonParametrized), + PREFIX_WITH_FOO(SomeTestName)) { + const ::testing::TestInfo* const test_info = + ::testing::UnitTest::GetInstance()->current_test_info(); + + EXPECT_STREQ("MacroNamingTestNonParametrized", test_info->test_case_name()); + EXPECT_STREQ("FooSomeTestName", test_info->name()); +} + // Tests that user supplied custom parameter names are working correctly. // Runs the test with a builtin helper method which uses PrintToString, // as well as a custom function and custom functor to ensure all possible |