CMake and CTest: Automatically run test dependencies
In my CMakeLists.txt, I have something like this:
set_property(TEST testX APPEND PROPERTY DEPENDS testY) set_property(TEST testX APPEND PROPERTY DEPENDS testZ)
And I want to run somehow testX
and all its dependencies automatically. Something like:
ctest <options> testX
and as a result CTest will work textY
, testZ
and testX
. Is there a way to do this?
Or, if this is not possible now, is there a way to extract dependency information from the CMake build directory to a script?
source to share
There is no built-in way to do this as far as I know.
The best way I can think of to achieve your goal is to use > LABELS
property in tests. You can get the list of dependencies using > t21> or and apply the same label to and each of its dependent tests: get_test_property
testX
get_test_property(testX DEPENDS DependenciesOfTestX) set_tests_properties(testX ${DependenciesOfTestX} PROPERTIES LABELS LabelX)
Then you can tell CTest to only run tests with that label:
ctest -L LabelX
source to share
Test fixture support was added in CMake 3.7 and they do exactly what you want. Your specific scenario will be implemented like this:
set_property(TEST testX PROPERTIES FIXTURES_REQUIRED Foo) set_property(TEST testY PROPERTIES FIXTURES_SETUP Foo) set_property(TEST testZ PROPERTIES FIXTURES_SETUP Foo)
Then you can request ctest
to run only testX
, and it will automatically add testY
and testZ
to the set of tests to be run:
ctest -R testX
It also ensures that testX
will work only after it has been sent testY
and testZ
. If none of testY
or testZ
does not work, testX
will be skipped. New options -FS
, -FC
and have -FA
also been added in ctest
CMake 3.9, which allow the automatic addition of hardware install / wipe tests to be monitored on the command line ctest
. For example, to temporarily skip adding testY
to a test suite, but still automatically adding testZ
, one could do this:
ctest -R testX -FS testY
The properties of the luminaires are described in the CMake docs and the following article goes into more detail about the luminaire function:
https://crascit.com/2016/10/18/test-fixtures-with-cmake-ctest/
source to share