diff options
author | Kyle Edwards <kyle.edwards@kitware.com> | 2023-08-11 14:44:14 (GMT) |
---|---|---|
committer | Kyle Edwards <kyle.edwards@kitware.com> | 2023-08-11 14:50:52 (GMT) |
commit | 2ccb897d86598daa983f77ce764411c5723b568c (patch) | |
tree | f12a2bab221a7dff8efa4b08bffd6bc7f92772e6 | |
parent | 84e76fedb0255ac4d0524f47268be79598b096fc (diff) | |
download | CMake-2ccb897d86598daa983f77ce764411c5723b568c.zip CMake-2ccb897d86598daa983f77ce764411c5723b568c.tar.gz CMake-2ccb897d86598daa983f77ce764411c5723b568c.tar.bz2 |
get_test_property(): Add DIRECTORY option
-rw-r--r-- | Help/command/get_test_property.rst | 13 | ||||
-rw-r--r-- | Help/release/dev/test-properties-directory.rst | 3 | ||||
-rw-r--r-- | Source/cmGetTestPropertyCommand.cxx | 27 | ||||
-rw-r--r-- | Tests/RunCMake/get_property/test_properties-stderr.txt | 10 | ||||
-rw-r--r-- | Tests/RunCMake/get_property/test_properties.cmake | 19 | ||||
-rw-r--r-- | Tests/RunCMake/get_property/test_properties/CMakeLists.txt | 4 |
6 files changed, 64 insertions, 12 deletions
diff --git a/Help/command/get_test_property.rst b/Help/command/get_test_property.rst index 2b6f354..1fcf24e 100644 --- a/Help/command/get_test_property.rst +++ b/Help/command/get_test_property.rst @@ -5,7 +5,7 @@ Get a property of the test. .. code-block:: cmake - get_test_property(test property VAR) + get_test_property(test property [DIRECTORY <dir>] VAR) Get a property from the test. The value of the property is stored in the variable ``VAR``. If the test property is not found, the behavior @@ -19,6 +19,17 @@ an empty string. For a list of standard properties you can type :option:`cmake --help-property-list`. +.. versionadded:: 3.28 + Directory scope can be overridden with the following sub-option: + + ``DIRECTORY <dir>`` + The test property will be read from the ``<dir>`` directory's + scope. CMake must already know about that source directory, either by + having added it through a call to :command:`add_subdirectory` or ``<dir>`` + being the top level source directory. Relative paths are treated as + relative to the current source directory. ``<dir>`` may reference a binary + directory. + See Also ^^^^^^^^ diff --git a/Help/release/dev/test-properties-directory.rst b/Help/release/dev/test-properties-directory.rst index 2daa533..9df7051 100644 --- a/Help/release/dev/test-properties-directory.rst +++ b/Help/release/dev/test-properties-directory.rst @@ -10,3 +10,6 @@ test-properties-directory * The ``TEST`` mode of the :command:`get_property` command gained a ``DIRECTORY`` sub-option, which allows you to get properties on tests in other directories. +* The :command:`get_test_property` command gained a ``DIRECTORY`` + sub-option, which allows you to get properties on tests in other + directories. diff --git a/Source/cmGetTestPropertyCommand.cxx b/Source/cmGetTestPropertyCommand.cxx index 36446c9..103471b 100644 --- a/Source/cmGetTestPropertyCommand.cxx +++ b/Source/cmGetTestPropertyCommand.cxx @@ -4,21 +4,42 @@ #include "cmExecutionStatus.h" #include "cmMakefile.h" +#include "cmSetPropertyCommand.h" #include "cmTest.h" #include "cmValue.h" bool cmGetTestPropertyCommand(std::vector<std::string> const& args, cmExecutionStatus& status) { - if (args.size() < 3) { + std::vector<std::string>::size_type args_size = args.size(); + if (args_size != 3 && args_size != 5) { status.SetError("called with incorrect number of arguments"); return false; } + std::string test_directory; + bool test_directory_option_enabled = false; + + int var_arg_index = 2; + if (args[2] == "DIRECTORY" && args_size == 5) { + var_arg_index = 4; + test_directory_option_enabled = true; + test_directory = args[3]; + } + + cmMakefile* test_directory_makefile = &status.GetMakefile(); + bool file_scopes_handled = + SetPropertyCommand::HandleAndValidateTestDirectoryScopes( + status, test_directory_option_enabled, test_directory, + test_directory_makefile); + if (!file_scopes_handled) { + return false; + } + std::string const& testName = args[0]; - std::string const& var = args[2]; + std::string const& var = args[var_arg_index]; cmMakefile& mf = status.GetMakefile(); - cmTest* test = mf.GetTest(testName); + cmTest* test = test_directory_makefile->GetTest(testName); if (test) { cmValue prop; if (!args[1].empty()) { diff --git a/Tests/RunCMake/get_property/test_properties-stderr.txt b/Tests/RunCMake/get_property/test_properties-stderr.txt index a447280..9f5a10f 100644 --- a/Tests/RunCMake/get_property/test_properties-stderr.txt +++ b/Tests/RunCMake/get_property/test_properties-stderr.txt @@ -1,6 +1,12 @@ -^get_test_property: --><-- +^get_test_property: -->value<-- +get_property: -->value<-- +get_test_property: --><-- get_property: --><-- get_test_property: -->value<-- get_property: -->value<-- get_test_property: -->NOTFOUND<-- -get_property: --><--$ +get_property: --><-- +get_test_property: -->anotherValue<-- +get_property: -->anotherValue<-- +get_test_property: -->anotherValue<-- +get_property: -->anotherValue<--$ diff --git a/Tests/RunCMake/get_property/test_properties.cmake b/Tests/RunCMake/get_property/test_properties.cmake index 1d0295c..f1cbca4 100644 --- a/Tests/RunCMake/get_property/test_properties.cmake +++ b/Tests/RunCMake/get_property/test_properties.cmake @@ -1,7 +1,11 @@ -function (check_test_property test prop) - get_test_property("${test}" "${prop}" gtp_val) +function (check_test_property test prop dir) + set(dir_args) + if(dir) + set(dir_args DIRECTORY ${dir}) + endif() + get_test_property("${test}" "${prop}" ${dir_args} gtp_val) get_property(gp_val - TEST "${test}" + TEST "${test}" ${dir_args} PROPERTY "${prop}") message("get_test_property: -->${gtp_val}<--") @@ -11,7 +15,10 @@ endfunction () include(CTest) add_test(NAME test COMMAND "${CMAKE_COMMAND}" --help) set_tests_properties(test PROPERTIES empty "" custom value) +add_subdirectory(test_properties) -check_test_property(test empty) -check_test_property(test custom) -check_test_property(test noexist) +check_test_property(test empty "") +check_test_property(test custom "") +check_test_property(test noexist "") +check_test_property(test custom test_properties) +check_test_property(test custom ${CMAKE_BINARY_DIR}/test_properties) diff --git a/Tests/RunCMake/get_property/test_properties/CMakeLists.txt b/Tests/RunCMake/get_property/test_properties/CMakeLists.txt new file mode 100644 index 0000000..ee90344 --- /dev/null +++ b/Tests/RunCMake/get_property/test_properties/CMakeLists.txt @@ -0,0 +1,4 @@ +add_test(NAME test COMMAND "${CMAKE_COMMAND}" --help) +set_tests_properties(test PROPERTIES empty "" custom anotherValue) + +check_test_property(test custom ..) |