Enhancement: Set property of a test in a subdirectory
I asked a question on discourse about setting test properties where the test is defined in a different directory. The feedback I got said that set_property(TEST
only sees tests in the current directory and that is defined behaviour.
Thus this enhancement request to see if the restriction can be removed.
I've pasted a copy of the original question below to make this ticket self-contained.
Cannot set a property of a test in a subdirectory
I’m having trouble setting properties on all tests in a directory tree.
Here is a dummy project that illustrates the issue
project(Hello_world VERSION 1.0)
enable_testing()
# get_all_tests will walk from CMAKE_CURRENT_SOURCE_DIR & find all tests
function(get_all_tests _out_var)
set(${_out_var} "")
get_all_tests_walker(${_out_var} ${CMAKE_CURRENT_SOURCE_DIR})
set(${_out_var} "${${_out_var}}" PARENT_SCOPE)
endfunction()
function(get_all_tests_walker _out_var _directory)
get_property(_subdirs DIRECTORY "${_directory}" PROPERTY SUBDIRECTORIES)
foreach(_subdir IN LISTS _subdirs)
get_all_tests_walker(${_out_var} "${_subdir}")
endforeach()
get_directory_property(_tests DIRECTORY "${_directory}" TESTS)
set(${_out_var} ${${_out_var}} ${_tests} PARENT_SCOPE)
endfunction()
# add a subdir with a test
add_subdirectory(another_dir)
# add a test local to the current directory
add_test(
NAME localtest
COMMAND localtest
)
# read all test names into "alltests"
get_all_tests(alltests)
message(WARNING "${alltests}")
set_property(TEST ${alltests}
APPEND
PROPERTY
LABELS PROTOBUF mylabel
)
The directory another-dir has this
add_test(
NAME subdirtest
COMMAND mycommand
)
When I run cmake against the above I get this output
$ cmake ..
CMake Warning at CMakeLists.txt:126 (message):
subdirtest;localtest
CMake Error at CMakeLists.txt:141 (set_property):
set_property given TEST names that do not exist:
subdirtest
-- Configuring incomplete, errors occurred!
Observations
-
the call to
get_all_tests
has correctly found all the tests in the directory tree -
the call to
set_property
cannot find thesubdirtest
test. It appears thatset_property(TEST
only sees tests in the current directory