Tests management: add TESTS directory property

Implements: #17680
This commit is contained in:
Marc Chevrier 2018-02-01 15:49:22 +01:00
parent 1da3f3e916
commit b513a879ec
7 changed files with 48 additions and 1 deletions

View File

@ -84,6 +84,7 @@ Properties on Directories
/prop_dir/RULE_LAUNCH_LINK
/prop_dir/SOURCE_DIR
/prop_dir/SUBDIRECTORIES
/prop_dir/TESTS
/prop_dir/TEST_INCLUDE_FILES
/prop_dir/VARIABLES
/prop_dir/VS_GLOBAL_SECTION_POST_section

7
Help/prop_dir/TESTS.rst Normal file
View File

@ -0,0 +1,7 @@
TESTS
-----
List of tests.
This read-only property holds a :ref:`;-list <CMake Language Lists>` of tests
defined so far by the :command:`add_test` command.

View File

@ -0,0 +1,5 @@
directory-property-TESTS
------------------------
* The :prop_dir:`TESTS` directory property was added to hold the list of tests defined by
command :command:`add_test`.

View File

@ -3641,6 +3641,20 @@ void cmMakefile::AppendProperty(const std::string& prop, const char* value,
const char* cmMakefile::GetProperty(const std::string& prop) const
{
// Check for computed properties.
static std::string output;
if (prop == "TESTS") {
std::vector<std::string> keys;
// get list of keys
std::transform(this->Tests.begin(), this->Tests.end(),
std::back_inserter(keys),
[](decltype(this->Tests)::value_type const& pair) {
return pair.first;
});
output = cmJoin(keys, ";");
return output.c_str();
}
return this->StateSnapshot.GetDirectory().GetProperty(prop);
}

View File

@ -19,4 +19,12 @@ get_property: -->[^<;]*/Tests/RunCMake/get_property<--
get_directory_property: -->[^<;]*/Tests/RunCMake/get_property/directory_properties-build/directory_properties<--
get_property: -->[^<;]*/Tests/RunCMake/get_property/directory_properties-build/directory_properties<--
get_directory_property: -->[^<;]*/Tests/RunCMake/get_property/directory_properties<--
get_property: -->[^<;]*/Tests/RunCMake/get_property/directory_properties<--$
get_property: -->[^<;]*/Tests/RunCMake/get_property/directory_properties<--
get_directory_property: --><--
get_property: --><--
get_directory_property: -->test1;test2<--
get_property: -->test1;test2<--
get_directory_property: -->test1;test2;test3<--
get_property: -->test1;test2;test3<--
get_directory_property: -->Sub/test1;Sub/test2<--
get_property: -->Sub/test1;Sub/test2<--$

View File

@ -28,3 +28,12 @@ check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}" BINARY_DIR)
check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}" SOURCE_DIR)
check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}/directory_properties" BINARY_DIR)
check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}/directory_properties" SOURCE_DIR)
check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}" TESTS)
add_test(NAME test1 COMMAND "${CMAKE_COMMAND}" -E echo "test1")
add_test(NAME test2 COMMAND "${CMAKE_COMMAND}" -E echo "test2")
check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}" TESTS)
add_test(NAME test3 COMMAND "${CMAKE_COMMAND}" -E echo "test3")
check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}" TESTS)
check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}/directory_properties" TESTS)

View File

@ -4,3 +4,6 @@ subdirs(sub2)
add_custom_target(CustomSub)
add_library(InterfaceSub INTERFACE)
add_library(my::InterfaceSub ALIAS InterfaceSub)
add_test(Sub/test1 COMMAND "${CMAKE_COMMAND}" -E echo "Sub/test1")
add_test(Sub/test2 COMMAND "${CMAKE_COMMAND}" -E echo "Sub/test2")