Use case for TEST_INCLUDE_FILES directory property?

What is the intended use case for the TEST_INCLUDE_FILES directory property?

The docs say:

A list of cmake files that will be included when ctest is run. If you specify TEST_INCLUDE_FILES, those files will be included and processed when ctest is run on the directory.

Is this intended to allow you to run some setup tasks before ctest executes tests?

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

Interesting. So in the files included by TEST_INCLUDE_FILES, the variables in that scope of CMake processing are available?

So, is CTest actually re-executing cmake configuration as it builds the test graph? I didn’t realize that.

No it is a completely separate processing environment. It is isolated from the CMake configure run. All you have access to is whatever is defined in the files ctest reads. Imagine it like a separate cmake -P invocation.

1 Like

I see. Thanks for the info!