summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Boeckel <ben.boeckel@kitware.com>2023-07-25 18:28:39 (GMT)
committerBen Boeckel <ben.boeckel@kitware.com>2023-07-29 13:35:20 (GMT)
commit721f1b608c7c0fffa1b217ff706080ab75af3adc (patch)
treeb2a3406f393dfaf47760218fd2dbe6ec43c536c6
parent1c0963e9f2cd2b7a5ff5e02fc7c26e47232061f4 (diff)
downloadCMake-721f1b608c7c0fffa1b217ff706080ab75af3adc.zip
CMake-721f1b608c7c0fffa1b217ff706080ab75af3adc.tar.gz
CMake-721f1b608c7c0fffa1b217ff706080ab75af3adc.tar.bz2
Tests/RunCMake/property_init: add a function to test properties
This function consumes a property table and tests against every kind of target: those for which the initialization happens and those that should ignore them. Also add a function that can build the pairs of target type lists required.
-rw-r--r--Tests/RunCMake/property_init/util.cmake57
1 files changed, 57 insertions, 0 deletions
diff --git a/Tests/RunCMake/property_init/util.cmake b/Tests/RunCMake/property_init/util.cmake
index e98c2d5..564a229 100644
--- a/Tests/RunCMake/property_init/util.cmake
+++ b/Tests/RunCMake/property_init/util.cmake
@@ -17,6 +17,12 @@ set(all_target_types
"CUSTOM")
+function (prepare_target_types name)
+ set("${name}" "${ARGN}" PARENT_SCOPE)
+ list(REMOVE_ITEM all_target_types ${ARGN})
+ set("not_${name}" "${all_target_types}" PARENT_SCOPE)
+endfunction ()
+
function (make_target name type)
if (type STREQUAL "EXECUTABLE")
add_executable("${name}")
@@ -97,3 +103,54 @@ function (prepare_properties table output_properties output_expected output_alia
set("${output_expected}" "${_expected}" PARENT_SCOPE)
set("${output_alias}" "${_alias}" PARENT_SCOPE)
endfunction ()
+
+# Contextual variables:
+# iteration: make unique target names
+# with_defaults: if set, do not set variables, but instead test internal
+# default calculations
+function (run_property_tests applied_types property_table)
+ prepare_properties("${property_table}" expected_properties expected_values expected_alias)
+
+ if (NOT with_defaults)
+ foreach (property expected IN ZIP_LISTS expected_properties expected_values)
+ string(REPLACE "<SEMI>" ";" expected "${expected}")
+ set("CMAKE_${property}" "${expected}")
+ endforeach ()
+ endif ()
+
+ foreach (target_type IN LISTS "${applied_types}")
+ set(target_name "${RunCMake_TEST}${iteration}-${target_type}")
+ if (with_defaults)
+ string(APPEND target_name "-defaults")
+ endif ()
+ make_target("${target_name}" "${target_type}")
+ foreach (property expected alias IN ZIP_LISTS expected_properties expected_values expected_alias)
+ string(REPLACE "<SEMI>" ";" expected "${expected}")
+ check_property("${target_name}" "${property}" "${expected}")
+ if (NOT target_type STREQUAL "CUSTOM")
+ if (alias STREQUAL "<SAME>")
+ check_property("alias::${target_name}" "${property}" "${expected}")
+ elseif (alias STREQUAL "<UNSET>")
+ check_property("alias::${target_name}" "${property}" "<UNSET>")
+ else ()
+ message(FATAL_ERROR
+ "Invalid `alias` entry for property '${property}': '${alias}'")
+ endif ()
+ endif ()
+ endforeach ()
+ endforeach ()
+
+ foreach (target_type IN LISTS "not_${applied_types}")
+ set(target_name "${RunCMake_TEST}${iteration}-${target_type}-unset")
+ if (with_defaults)
+ string(APPEND target_name "-defaults")
+ endif ()
+ make_target("${target_name}" "${target_type}")
+ foreach (property IN LISTS expected_properties)
+ check_property("${target_name}" "${property}" "<UNSET>")
+ if (NOT target_type STREQUAL "CUSTOM")
+ check_property("alias::${target_name}" "${property}" "<UNSET>")
+ endif ()
+ endforeach ()
+ endforeach ()
+endfunction ()