Use case for TEST_INCLUDE_FILES directory property?

It allows you to execute arbitrary code at test time. But by test time, I don’t mean during a test case, I mean when ctest runs, specifically while it is reading the files to build up its picture of the set of defined tests.

One example use case is with gtest_discover_tests(). That command allows you to specify properties to set on test cases, but it can’t set a value that is a list, only single values. If you need to assign a list to some test property, you need to do that in a separate file, which you then add to ctest processing by listing that file in the TEST_INCLUDE_FILES property. The TEST_LIST keyword allows you to specify what variable to store the list of discovered tests in so that you can set properties on those tests.

CMakeLists.txt

gtest_discover_tests(SomeTarget TEST_LIST discovered_tests)
set_property(DIRECTORY APPEND PROPERTY
    TEST_INCLUDE_FILES ${CMAKE_CURRENT_LIST_DIR}/add_labels.cmake
)

add_labels.cmake

set_tests_properties(${discovered_tests} PROPERTIES LABELS "One;Two;Three")
1 Like