# Unable to set ctest specific property for parameterized gtest tests

**URL:** https://discourse.cmake.org/t/unable-to-set-ctest-specific-property-for-parameterized-gtest-tests/11251
**Category:** Usage
**Created:** [July 15, 2024, 6:26am UTC](https://discourse.cmake.org/t/unable-to-set-ctest-specific-property-for-parameterized-gtest-tests/11251 "2024-07-15T06:26:31Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![andi\_schacherbauer](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/b5e925/32.png) [@andi\_schacherbauer](https://discourse.cmake.org/u/andi_schacherbauer)
#### Post date: [July 15, 2024, 6:26am UTC](https://discourse.cmake.org/t/unable-to-set-ctest-specific-property-for-parameterized-gtest-tests/11251/1 "2024-07-15T06:26:31Z")

</div>

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:

```auto
#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:

```auto
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:

```auto
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.

```auto
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!

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [July 15, 2024, 10:27pm UTC](https://discourse.cmake.org/t/unable-to-set-ctest-specific-property-for-parameterized-gtest-tests/11251/2 "2024-07-15T22:27:09Z")

</div>

Put quotes around the test names in your call to `set_tests_properties()`.

```cmake
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
)

```

I assume you are calling `set_tests_properties()` inside a custom ctest script that you add to the `TEST_INCLUDE_FILES` directory property?

---

<div class="post-metadata">

### Author: ![andi\_schacherbauer](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/b5e925/32.png) [@andi\_schacherbauer](https://discourse.cmake.org/u/andi_schacherbauer)
#### Post date: [July 18, 2024, 12:15pm UTC](https://discourse.cmake.org/t/unable-to-set-ctest-specific-property-for-parameterized-gtest-tests/11251/3 "2024-07-18T12:15:02Z")

</div>

I feel so dumb for not trying this… Thank you!

A follow up question would be if wildcards are supported as well in any way. It’s nice to be able to set properties for each test method individually, but sometimes it would be handy to be able to write

```auto
set_tests_properties(
    "DifferentStrings/ParameterizedTestFixture.*"
)

```

or for non parameterized tests

```auto
set_tests_properties(
    "FooTest.*"
)

```

So far I haven’t found an answer to this and it does not work.

Thx!

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [July 18, 2024, 10:40pm UTC](https://discourse.cmake.org/t/unable-to-set-ctest-specific-property-for-parameterized-gtest-tests/11251/4 "2024-07-18T22:40:06Z")

</div>

Wildcards are not supported, you need to list all properties by their exact name. But check the `TEST_LIST` keyword of `gtest_discover_tests()`. You can use it to have that command populate a variable you nominate and you can read that variable in the custom ctest script. You can apply whatever filtering you want to that list and then call `set_tests_properties()` on the filtered list, so you can indirectly get the behavior you want that way.

---

<div class="post-metadata">

### Author: ![dabrahams](https://discourse.cmake.org/user_avatar/discourse.cmake.org/dabrahams/32/4265_2.png) [@dabrahams](https://discourse.cmake.org/u/dabrahams)
#### Post date: [August 14, 2024, 8:22pm UTC](https://discourse.cmake.org/t/unable-to-set-ctest-specific-property-for-parameterized-gtest-tests/11251/5 "2024-08-14T20:22:14Z")

</div>

Ah, just found this topic; @craig.scott you are pointing in the direction of the answer I’m searching for. Obviously the TEST\_LIST variable is unavailable before the test executable has been built, so it’s still empty immediately after the call to `gtest_discovered_tests()`, and I need to do something else, but I don’t know about custom ctest scripts. `GoogleTest` itself is clearly generating some scripts. Do I need to follow the same pattern? I guess it’s the directory’s `TEST_INCLUDE_FILES` property that causes these scripts to get used. Just confirming I’ve got all that right.

Whew, that all [should really be documented](https://gitlab.kitware.com/cmake/cmake/-/issues/26217).

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [August 15, 2024, 7:36am UTC](https://discourse.cmake.org/t/unable-to-set-ctest-specific-property-for-parameterized-gtest-tests/11251/6 "2024-08-15T07:36:42Z")

</div>

You can’t access the list of tests from your CMake project during the configure run. `TEST_LIST` is naming a variable you can access _during `ctest` execution_. The querying of the tests only happens at test time (or maybe at build time, depending on how you define things). You would access the variable named by `TEST_LIST` from a custom script that you write and tell `ctest` about via the `TEST_INCLUDE_FILES` directory property.

I’d welcome a merge request that improves the documentation around this.
