Hi!
I have parameterized GTest tests and struggle to set CTest properties on them. The problems seems to be the parameter type. If I have tests with string parameters, everything is fine. As soon as the parameter type is a custom type, things start to break. The problem is: CTest seems to be unable to identify the tests.
As soon as the test is based on a custom type parameter, the name has such a cryptic name at the end 4-byte object <02-00 00-00>
. If the parameter type is just string, then it is "foo"
.
Here are a few concrete examples:
#include <gmock/gmock.h>
#include <gtest/gtest.h>
using namespace testing;
class TestFixture : public TestWithParam<std::string>
{
};
TEST_P(TestFixture, test_enabled)
{
std::cout << "param: " << GetParam() << "\n";
SUCCEED();
}
TEST_P(TestFixture, test_disabled)
{
std::cout << "param: " << GetParam() << "\n";
FAIL();
}
INSTANTIATE_TEST_SUITE_P(DifferentStrings, TestFixture, testing::Values("foo", "bar"));
I’m able to to disable specific tests in CMake with the following snippet:
set_tests_properties(
DifferentStrings/TestFixture.test_b/"foo"
DifferentStrings/TestFixture.test_b/"bar"
PROPERTIES
DISABLED ON
)
Here is a snippet of a test that CTest fails to identify:
struct Foo
{
int x;
};
class ParameterizedTestFixture : public TestWithParam<Foo>
{
};
TEST_P(ParameterizedTestFixture, test_a)
{
std::cout << "param: " << GetParam().x << "\n";
SUCCEED();
}
TEST_P(ParameterizedTestFixture, test_b)
{
std::cout << "param: " << GetParam().x << "\n";
FAIL();
}
INSTANTIATE_TEST_SUITE_P(DifferentObjects, ParameterizedTestFixture, testing::Values(Foo{1}, Foo{2}));
GTest is logging the test names as DifferentStrings/TestFixture.test_b/4-byte object <02-00 00-00>
. Using this as a test identifier in CTest does unfortunately not work.
set_tests_properties(
DifferentStrings/ParameterizedTestFixture.test_b/4-byte object <01-00 00-00>
DifferentStrings/ParameterizedTestFixture.test_b/4-byte object <02-00 00-00>
PROPERTIES
DISABLED ON
)
Because of reasons I need to use the gtest_discover_tests
way, provided from GTest, to register tests with CTest.
Any ideas what could be the problem? Thx!