From 247eba45bf336f067499c2668301c339126bd65d Mon Sep 17 00:00:00 2001 From: zachcran Date: Tue, 3 Sep 2024 11:58:46 -0600 Subject: [PATCH 01/12] Sanitize build directory test paths better and add lots of comments --- cmake/cmake_test/add_dir.cmake | 91 +++++++++++++++++++++++++--------- 1 file changed, 67 insertions(+), 24 deletions(-) diff --git a/cmake/cmake_test/add_dir.cmake b/cmake/cmake_test/add_dir.cmake index f1700d8..56417f2 100644 --- a/cmake/cmake_test/add_dir.cmake +++ b/cmake/cmake_test/add_dir.cmake @@ -14,25 +14,29 @@ include_guard() +include(cmakepp_lang/cmakepp_lang) + #[[[ -# This function will find all :code:`*.cmake` files in the specified directory as well as recursively through all subdirectories. -# It will then configure the boilerplate template to include() each cmake file and register each configured boilerplate -# with CTest. The configured templates will be executed seperately via CTest during the Test phase, and each *.cmake -# file found in the specified directory is assumed to contain CMakeTest tests. +# This function will find all :code:`*.cmake` files in the specified directory +# as well as recursively through all subdirectories. It will then configure the +# boilerplate template to include() each cmake file and register each +# configured boilerplate with CTest. The configured templates will be executed +# seperately via CTest during the Test phase, and each *.cmake file found in +# the specified directory is assumed to contain CMakeTest tests. # -# :param dir: The directory to search for *.cmake files. Subdirectories will be recursively searched. -# :type dir: path +# :param test_dir: The directory to search for *.cmake files containing tests. +# Subdirectories will be recursively searched. +# :type test_dir: path # # **Keyword Arguments** # # :keyword CMAKE_OPTIONS: List of additional CMake options to be # passed to all test invocations. Options -# should follow the syntax: :code:`-D=` +# should follow the syntax: +# :code:`-D=` # :type CMAKE_OPTIONS: list -# -# #]] -function(ct_add_dir _ad_dir) +function(ct_add_dir _ad_test_dir) set(_ad_multi_value_args "CMAKE_OPTIONS") set(_ad_options CT_DEBUG_MODE_ON) cmake_parse_arguments(PARSE_ARGV 1 ADD_DIR "${_ad_options}" "" "${_ad_multi_value_args}") @@ -40,31 +44,70 @@ function(ct_add_dir _ad_dir) # This variable will be picked up by the template set(ct_debug_mode "${ADD_DIR_CT_DEBUG_MODE_ON}") - get_filename_component(_ad_abs_test_dir "${_ad_dir}" REALPATH) - file(GLOB_RECURSE _ad_files LIST_DIRECTORIES FALSE FOLLOW_SYMLINKS "${_ad_abs_test_dir}/*.cmake") #Recurse over target dir to find all cmake files + # We expect to be given relative paths wrt the project, like + # ``ct_add_dir("test")``. This ensures we have an absolute path + # to the test directory when we do get a relative path. If we + # get an absolute path to begin with, this is essentially a no-op. + get_filename_component(_ad_abs_test_dir "${_ad_test_dir}" REALPATH) + + # Recurse over the test directory to find all cmake files + # (assumed to all be test files) + file(GLOB_RECURSE + _ad_test_files + LIST_DIRECTORIES FALSE + FOLLOW_SYMLINKS "${_ad_abs_test_dir}/*.cmake" + ) + + # Each test file will get its own directory and "mini-project" in the + # build directory to facilitate independently running each test case. + # These directories are created from the mangled path to the source test + # file in the project to help ensure that each path is unique + foreach(_ad_test_file ${_ad_test_files}) + # Normalize the absolute path to the project test directory, used in + # the build directory as a prefixing subdirectory to hold all of the + # test mini-projects from this test directory + file(TO_CMAKE_PATH "${_ad_abs_test_dir}" _ad_normalized_abs_test_dir) + + # Find the relative path to the test file from the test directory to + # reduce the path length for the test folders created in the build + # directory. This is used for the test mini-project directory in the + # build directory + file(RELATIVE_PATH + _ad_test_file_rel_path + "${_ad_abs_test_dir}" + "${_ad_test_file}" + ) + + # string(REPLACE "/" "_" _ad_dir_prefix "${_ad_normalized_dir}") + # string(REPLACE ":" "_" _ad_dir_prefix "${_ad_dir_prefix}") + + # Mangle all of the directory names derived from paths, since path + # strings commonly have characters that are illegal in file names + # mangle_path(_ad_dir_prefix_mangled "${_ad_normalized_abs_test_dir}") + # mangle_path(_ad_rel_path_mangled "${_ad_test_file_rel_path}") + cpp_sanitize_string(_ad_test_dest_prefix + "${_ad_normalized_abs_test_dir}" + ) + cpp_sanitize_string(_ad_test_proj_dir "${_ad_test_file_rel_path}") - foreach(_ad_test_file ${_ad_files}) - #Find rel path so we don't end up with insanely long paths under test folders - file(RELATIVE_PATH _ad_rel_path "${_ad_abs_test_dir}" "${_ad_test_file}") - file(TO_CMAKE_PATH "${_ad_abs_test_dir}" _ad_normalized_dir) - string(REPLACE "/" "_" _ad_dir_prefix "${_ad_normalized_dir}") - string(REPLACE ":" "_" _ad_dir_prefix "${_ad_dir_prefix}") + set(_ad_test_dest_full_path + "${CMAKE_CURRENT_BINARY_DIR}/tests/${_ad_test_dest_prefix}/${_ad_test_proj_dir}" + ) - #Fill in boilerplate, copy to build dir + # Fill in boilerplate, copy to build dir configure_file( "${_CT_TEMPLATES_DIR}/lists.txt" - "${CMAKE_CURRENT_BINARY_DIR}/tests/${_ad_dir_prefix}/${_ad_rel_path}/src/CMakeLists.txt" + "${_ad_test_dest_full_path}/src/CMakeLists.txt" @ONLY ) add_test( NAME - "${_ad_dir_prefix}_${_ad_rel_path}" + "${_ad_test_dest_prefix}_${_ad_test_proj_dir}" COMMAND "${CMAKE_COMMAND}" - -S "${CMAKE_CURRENT_BINARY_DIR}/tests/${_ad_dir_prefix}/${_ad_rel_path}/src" - -B "${CMAKE_CURRENT_BINARY_DIR}/tests/${_ad_dir_prefix}/${_ad_rel_path}" + -S "${_ad_test_dest_full_path}/src" + -B "${_ad_test_dest_full_path}" ${ADD_DIR_CMAKE_OPTIONS} ) - endforeach() endfunction() From f1ce8bf911b991b08a8c154fa994746a9cb2db81 Mon Sep 17 00:00:00 2001 From: zachcran Date: Tue, 3 Sep 2024 14:39:40 -0500 Subject: [PATCH 02/12] Decouple CMakeLists template file from add_dir and fix sanitization issue --- cmake/cmake_test/add_dir.cmake | 18 +++++++++++------- ...ists.txt => test_project_CMakeLists.txt.in} | 16 ++++++++++------ 2 files changed, 21 insertions(+), 13 deletions(-) rename cmake/cmake_test/templates/{lists.txt => test_project_CMakeLists.txt.in} (70%) diff --git a/cmake/cmake_test/add_dir.cmake b/cmake/cmake_test/add_dir.cmake index 56417f2..52f64db 100644 --- a/cmake/cmake_test/add_dir.cmake +++ b/cmake/cmake_test/add_dir.cmake @@ -63,6 +63,13 @@ function(ct_add_dir _ad_test_dir) # These directories are created from the mangled path to the source test # file in the project to help ensure that each path is unique foreach(_ad_test_file ${_ad_test_files}) + # Set the test file path for configuring the test mini-project + set(_CT_LISTS_TEMPLATE_TEST_FILE "${_ad_test_file}") + + # Sanitize the full path to the test file to get the mini-project name + # for configuring the test mini-project + cpp_sanitize_string(_CT_LISTS_TEMPLATE_PROJECT_NAME "${_ad_test_file}") + # Normalize the absolute path to the project test directory, used in # the build directory as a prefixing subdirectory to hold all of the # test mini-projects from this test directory @@ -78,28 +85,25 @@ function(ct_add_dir _ad_test_dir) "${_ad_test_file}" ) - # string(REPLACE "/" "_" _ad_dir_prefix "${_ad_normalized_dir}") - # string(REPLACE ":" "_" _ad_dir_prefix "${_ad_dir_prefix}") - # Mangle all of the directory names derived from paths, since path # strings commonly have characters that are illegal in file names - # mangle_path(_ad_dir_prefix_mangled "${_ad_normalized_abs_test_dir}") - # mangle_path(_ad_rel_path_mangled "${_ad_test_file_rel_path}") cpp_sanitize_string(_ad_test_dest_prefix "${_ad_normalized_abs_test_dir}" ) cpp_sanitize_string(_ad_test_proj_dir "${_ad_test_file_rel_path}") + # Create the test destination path in the build directory set(_ad_test_dest_full_path "${CMAKE_CURRENT_BINARY_DIR}/tests/${_ad_test_dest_prefix}/${_ad_test_proj_dir}" ) - # Fill in boilerplate, copy to build dir + # Configure the test mini-project in the build directory configure_file( - "${_CT_TEMPLATES_DIR}/lists.txt" + "${_CT_TEMPLATES_DIR}/test_project_CMakeLists.txt.in" "${_ad_test_dest_full_path}/src/CMakeLists.txt" @ONLY ) + add_test( NAME "${_ad_test_dest_prefix}_${_ad_test_proj_dir}" diff --git a/cmake/cmake_test/templates/lists.txt b/cmake/cmake_test/templates/test_project_CMakeLists.txt.in similarity index 70% rename from cmake/cmake_test/templates/lists.txt rename to cmake/cmake_test/templates/test_project_CMakeLists.txt.in index bd5126e..2733b9f 100644 --- a/cmake/cmake_test/templates/lists.txt +++ b/cmake/cmake_test/templates/test_project_CMakeLists.txt.in @@ -2,11 +2,12 @@ #The configured file will be used as the CTest entrypoint and will #include() the intended test file before executing the tests found. - cmake_minimum_required(VERSION @_ct_min_cmake_version@) #Required for FetchContent_MakeAvailable() set(_ct_min_cmake_version @_ct_min_cmake_version@) #Propagate min version down -project(@_ad_test_file@ LANGUAGES C) #Needed so dummy libraries don't complain about not having a linkage language +# A language is set so the dummy projects don't complain about not having a +# linkage language. +project(@_CT_LISTS_TEMPLATE_PROJECT_NAME@ LANGUAGES C) #Enable colors in Unix environments, ignored on Windows. Will not work with pipes set(CMAKETEST_USE_COLORS "@CMAKETEST_USE_COLORS@") @@ -16,9 +17,12 @@ if(NOT CT_PRINT_LENGTH GREATER 0) set(CT_PRINT_LENGTH "@CT_PRINT_LENGTH@") endif() -set(CMAKE_MODULE_PATH "@CMAKE_MODULE_PATH@" CACHE STRING "" FORCE) - - +# Propagate the module CMake module path for the project so they stick when +# the tests are run separately +set(CMAKE_MODULE_PATH + "@CMAKE_MODULE_PATH@" + CACHE STRING "" FORCE +) if(@ct_debug_mode@) set(CMAKEPP_LANG_DEBUG_MODE "TRUE") @@ -30,5 +34,5 @@ cpp_set_global("CT_DEBUG_MODE" "@ct_debug_mode@") include("cmake_test/cmake_test") set(CMAKEPP_LANG_DEBUG_MODE "@CMAKEPP_LANG_DEBUG_MODE@") -include([[@_ad_test_file@]]) +include([[@_CT_LISTS_TEMPLATE_TEST_FILE@]]) ct_exec_tests() From 0a8e5be28f6d2d399a0173d9c549e900d417efc4 Mon Sep 17 00:00:00 2001 From: zachcran Date: Tue, 3 Sep 2024 14:40:11 -0500 Subject: [PATCH 03/12] Fix indentation issue --- cmake/cmake_test/add_dir.cmake | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cmake/cmake_test/add_dir.cmake b/cmake/cmake_test/add_dir.cmake index 52f64db..4d2e574 100644 --- a/cmake/cmake_test/add_dir.cmake +++ b/cmake/cmake_test/add_dir.cmake @@ -105,13 +105,13 @@ function(ct_add_dir _ad_test_dir) ) add_test( - NAME - "${_ad_test_dest_prefix}_${_ad_test_proj_dir}" - COMMAND - "${CMAKE_COMMAND}" - -S "${_ad_test_dest_full_path}/src" - -B "${_ad_test_dest_full_path}" - ${ADD_DIR_CMAKE_OPTIONS} + NAME + "${_ad_test_dest_prefix}_${_ad_test_proj_dir}" + COMMAND + "${CMAKE_COMMAND}" + -S "${_ad_test_dest_full_path}/src" + -B "${_ad_test_dest_full_path}" + ${ADD_DIR_CMAKE_OPTIONS} ) endforeach() endfunction() From 892d0978f7ad455b3e48367b3e299ae3d476c56a Mon Sep 17 00:00:00 2001 From: zachcran Date: Tue, 3 Sep 2024 14:58:11 -0500 Subject: [PATCH 04/12] Add question about keyword argument --- cmake/cmake_test/add_dir.cmake | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cmake/cmake_test/add_dir.cmake b/cmake/cmake_test/add_dir.cmake index 4d2e574..322c080 100644 --- a/cmake/cmake_test/add_dir.cmake +++ b/cmake/cmake_test/add_dir.cmake @@ -30,6 +30,8 @@ include(cmakepp_lang/cmakepp_lang) # # **Keyword Arguments** # +# :keyword CT_DEBUG_MODE_ON: Enables debug mode when the tests are run. +# :type CT_DEBUG_MODE_ON: bool # :keyword CMAKE_OPTIONS: List of additional CMake options to be # passed to all test invocations. Options # should follow the syntax: @@ -38,6 +40,10 @@ include(cmakepp_lang/cmakepp_lang) #]] function(ct_add_dir _ad_test_dir) set(_ad_multi_value_args "CMAKE_OPTIONS") + # TODO: This name is potentially misleading because it seems to enable + # debug mode for the test projects (see the use of 'ct_debug_mode' + # in cmake/cmake_test/templates/test_project_CMakeLists.txt.in). + # I propose renaming it to something like "ENABLE_DEBUG_MODE_IN_TESTS". set(_ad_options CT_DEBUG_MODE_ON) cmake_parse_arguments(PARSE_ARGV 1 ADD_DIR "${_ad_options}" "" "${_ad_multi_value_args}") From 570af8f987f6703a6e7e4f0fd1a039c77e440762 Mon Sep 17 00:00:00 2001 From: zachcran Date: Tue, 3 Sep 2024 16:05:16 -0500 Subject: [PATCH 05/12] Update CMakeLists template --- cmake/cmake_test/add_dir.cmake | 6 +++--- ...st_project_CMakeLists.txt.in => test_CMakeLists.txt.in} | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) rename cmake/cmake_test/templates/{test_project_CMakeLists.txt.in => test_CMakeLists.txt.in} (81%) diff --git a/cmake/cmake_test/add_dir.cmake b/cmake/cmake_test/add_dir.cmake index 322c080..c26c38b 100644 --- a/cmake/cmake_test/add_dir.cmake +++ b/cmake/cmake_test/add_dir.cmake @@ -70,11 +70,11 @@ function(ct_add_dir _ad_test_dir) # file in the project to help ensure that each path is unique foreach(_ad_test_file ${_ad_test_files}) # Set the test file path for configuring the test mini-project - set(_CT_LISTS_TEMPLATE_TEST_FILE "${_ad_test_file}") + set(_CT_CMAKELISTS_TEMPLATE_TEST_FILE "${_ad_test_file}") # Sanitize the full path to the test file to get the mini-project name # for configuring the test mini-project - cpp_sanitize_string(_CT_LISTS_TEMPLATE_PROJECT_NAME "${_ad_test_file}") + cpp_sanitize_string(_CT_CMAKELISTS_TEMPLATE_PROJECT_NAME "${_ad_test_file}") # Normalize the absolute path to the project test directory, used in # the build directory as a prefixing subdirectory to hold all of the @@ -105,7 +105,7 @@ function(ct_add_dir _ad_test_dir) # Configure the test mini-project in the build directory configure_file( - "${_CT_TEMPLATES_DIR}/test_project_CMakeLists.txt.in" + "${_CT_TEMPLATES_DIR}/test_CMakeLists.txt.in" "${_ad_test_dest_full_path}/src/CMakeLists.txt" @ONLY ) diff --git a/cmake/cmake_test/templates/test_project_CMakeLists.txt.in b/cmake/cmake_test/templates/test_CMakeLists.txt.in similarity index 81% rename from cmake/cmake_test/templates/test_project_CMakeLists.txt.in rename to cmake/cmake_test/templates/test_CMakeLists.txt.in index 2733b9f..73edd81 100644 --- a/cmake/cmake_test/templates/test_project_CMakeLists.txt.in +++ b/cmake/cmake_test/templates/test_CMakeLists.txt.in @@ -7,7 +7,7 @@ set(_ct_min_cmake_version @_ct_min_cmake_version@) #Propagate min version down # A language is set so the dummy projects don't complain about not having a # linkage language. -project(@_CT_LISTS_TEMPLATE_PROJECT_NAME@ LANGUAGES C) +project(@_CT_CMAKELISTS_TEMPLATE_PROJECT_NAME@ LANGUAGES C) #Enable colors in Unix environments, ignored on Windows. Will not work with pipes set(CMAKETEST_USE_COLORS "@CMAKETEST_USE_COLORS@") @@ -24,6 +24,8 @@ set(CMAKE_MODULE_PATH CACHE STRING "" FORCE ) +# Question: Why not just set this to @ct_debug_mode@? I'm pretty sure that +# accomplishes the same thing. if(@ct_debug_mode@) set(CMAKEPP_LANG_DEBUG_MODE "TRUE") endif() @@ -32,7 +34,8 @@ include(cmakepp_lang/cmakepp_lang) cpp_set_global("CT_DEBUG_MODE" "@ct_debug_mode@") include("cmake_test/cmake_test") +# Question: Why is this set separately from above? set(CMAKEPP_LANG_DEBUG_MODE "@CMAKEPP_LANG_DEBUG_MODE@") -include([[@_CT_LISTS_TEMPLATE_TEST_FILE@]]) +include([[@_CT_CMAKELISTS_TEMPLATE_TEST_FILE@]]) ct_exec_tests() From be1b9e540d58325cd8d2f8c73c34eb368d38bd43 Mon Sep 17 00:00:00 2001 From: zachcran Date: Tue, 3 Sep 2024 19:06:52 -0500 Subject: [PATCH 06/12] Add hashing for test directory names, plus some code optimizations --- cmake/cmake_test/add_dir.cmake | 59 ++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/cmake/cmake_test/add_dir.cmake b/cmake/cmake_test/add_dir.cmake index c26c38b..8d9d565 100644 --- a/cmake/cmake_test/add_dir.cmake +++ b/cmake/cmake_test/add_dir.cmake @@ -48,13 +48,15 @@ function(ct_add_dir _ad_test_dir) cmake_parse_arguments(PARSE_ARGV 1 ADD_DIR "${_ad_options}" "" "${_ad_multi_value_args}") # This variable will be picked up by the template + # TODO: This variable should be made Config File-specific and may end up + # mirroring the rename of CT_DEBUG_MODE_ON above, if that happens set(ct_debug_mode "${ADD_DIR_CT_DEBUG_MODE_ON}") # We expect to be given relative paths wrt the project, like # ``ct_add_dir("test")``. This ensures we have an absolute path - # to the test directory when we do get a relative path. If we - # get an absolute path to begin with, this is essentially a no-op. + # to the test directory as well as a CMak-style normalized path. get_filename_component(_ad_abs_test_dir "${_ad_test_dir}" REALPATH) + file(TO_CMAKE_PATH "${_ad_abs_test_dir}" _ad_abs_test_dir) # Recurse over the test directory to find all cmake files # (assumed to all be test files) @@ -66,53 +68,68 @@ function(ct_add_dir _ad_test_dir) # Each test file will get its own directory and "mini-project" in the # build directory to facilitate independently running each test case. - # These directories are created from the mangled path to the source test - # file in the project to help ensure that each path is unique + # These directories are created from hashes of the test directory and + # test file paths to help ensure that each path is unique foreach(_ad_test_file ${_ad_test_files}) # Set the test file path for configuring the test mini-project set(_CT_CMAKELISTS_TEMPLATE_TEST_FILE "${_ad_test_file}") # Sanitize the full path to the test file to get the mini-project name # for configuring the test mini-project - cpp_sanitize_string(_CT_CMAKELISTS_TEMPLATE_PROJECT_NAME "${_ad_test_file}") - - # Normalize the absolute path to the project test directory, used in - # the build directory as a prefixing subdirectory to hold all of the - # test mini-projects from this test directory - file(TO_CMAKE_PATH "${_ad_abs_test_dir}" _ad_normalized_abs_test_dir) + cpp_sanitize_string( + _CT_CMAKELISTS_TEMPLATE_PROJECT_NAME "${_ad_test_file}" + ) # Find the relative path to the test file from the test directory to - # reduce the path length for the test folders created in the build - # directory. This is used for the test mini-project directory in the - # build directory + # reduce the length of the test names file(RELATIVE_PATH _ad_test_file_rel_path "${_ad_abs_test_dir}" "${_ad_test_file}" ) - # Mangle all of the directory names derived from paths, since path - # strings commonly have characters that are illegal in file names - cpp_sanitize_string(_ad_test_dest_prefix - "${_ad_normalized_abs_test_dir}" - ) + # Mangle the test directory and test file paths, since path strings + # commonly have characters that are illegal in file names + cpp_sanitize_string(_ad_test_dest_prefix "${_ad_abs_test_dir}") cpp_sanitize_string(_ad_test_proj_dir "${_ad_test_file_rel_path}") + # Get hashes for the prefix directory and test project directory + string(SHA256 _ad_test_dest_prefix_hash "${_ad_test_dest_prefix}") + string(SHA256 _ad_test_proj_dir_hash "${_ad_test_proj_dir}") + + # Truncate the hashes to 7 characters + set(_ad_hash_length 7) + string(SUBSTRING + "${_ad_test_dest_prefix_hash}" + 0 + "${_ad_hash_length}" + _ad_test_dest_prefix_hash + ) + string(SUBSTRING + "${_ad_test_proj_dir_hash}" + 0 + "${_ad_hash_length}" + _ad_test_proj_dir_hash + ) + # Create the test destination path in the build directory set(_ad_test_dest_full_path - "${CMAKE_CURRENT_BINARY_DIR}/tests/${_ad_test_dest_prefix}/${_ad_test_proj_dir}" + "${CMAKE_CURRENT_BINARY_DIR}/tests/${_ad_test_dest_prefix_hash}/${_ad_test_proj_dir_hash}" ) - # Configure the test mini-project in the build directory + # Configure the CMakeLists.txt for test in the build directory configure_file( "${_CT_TEMPLATES_DIR}/test_CMakeLists.txt.in" "${_ad_test_dest_full_path}/src/CMakeLists.txt" @ONLY ) + # The test name is long right now, but it would likely be much more + # complicated to make it shorter while still unique and readable + set(_ad_test_name "${_CT_CMAKELISTS_TEMPLATE_PROJECT_NAME}") add_test( NAME - "${_ad_test_dest_prefix}_${_ad_test_proj_dir}" + "${_ad_test_name}" COMMAND "${CMAKE_COMMAND}" -S "${_ad_test_dest_full_path}/src" From 2928f9d96ec1546a651aae897e42edbc2948a8fa Mon Sep 17 00:00:00 2001 From: zachcran Date: Tue, 3 Sep 2024 20:17:55 -0500 Subject: [PATCH 07/12] Remove questions [no ci] --- cmake/cmake_test/templates/test_CMakeLists.txt.in | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmake/cmake_test/templates/test_CMakeLists.txt.in b/cmake/cmake_test/templates/test_CMakeLists.txt.in index 73edd81..0c9077e 100644 --- a/cmake/cmake_test/templates/test_CMakeLists.txt.in +++ b/cmake/cmake_test/templates/test_CMakeLists.txt.in @@ -24,8 +24,9 @@ set(CMAKE_MODULE_PATH CACHE STRING "" FORCE ) -# Question: Why not just set this to @ct_debug_mode@? I'm pretty sure that -# accomplishes the same thing. +# Unconfirmed: This assignment is done in a seemily redundant way +# because some CMakePPLang debug statements trigger just by +# CMAKEPP_LANG_DEBUG_MODE being defined at all if(@ct_debug_mode@) set(CMAKEPP_LANG_DEBUG_MODE "TRUE") endif() @@ -34,7 +35,6 @@ include(cmakepp_lang/cmakepp_lang) cpp_set_global("CT_DEBUG_MODE" "@ct_debug_mode@") include("cmake_test/cmake_test") -# Question: Why is this set separately from above? set(CMAKEPP_LANG_DEBUG_MODE "@CMAKEPP_LANG_DEBUG_MODE@") include([[@_CT_CMAKELISTS_TEMPLATE_TEST_FILE@]]) From a9d1fe263965bfef0c408d0dc4a482b5abea38c5 Mon Sep 17 00:00:00 2001 From: zachcran Date: Tue, 3 Sep 2024 20:37:20 -0500 Subject: [PATCH 08/12] Use the unsanitized test file paths for the test names --- cmake/cmake_test/add_dir.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/cmake_test/add_dir.cmake b/cmake/cmake_test/add_dir.cmake index 8d9d565..4412e1a 100644 --- a/cmake/cmake_test/add_dir.cmake +++ b/cmake/cmake_test/add_dir.cmake @@ -126,7 +126,7 @@ function(ct_add_dir _ad_test_dir) # The test name is long right now, but it would likely be much more # complicated to make it shorter while still unique and readable - set(_ad_test_name "${_CT_CMAKELISTS_TEMPLATE_PROJECT_NAME}") + set(_ad_test_name "${_ad_test_file}") add_test( NAME "${_ad_test_name}" From 88092e1775f892d82e42b5ed48751cc4e24e928f Mon Sep 17 00:00:00 2001 From: zachcran Date: Wed, 4 Sep 2024 16:13:12 -0600 Subject: [PATCH 09/12] Ignore template file based on extension --- .github/.licenserc.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/.licenserc.yaml b/.github/.licenserc.yaml index 851d1fe..92fd8a8 100644 --- a/.github/.licenserc.yaml +++ b/.github/.licenserc.yaml @@ -25,5 +25,6 @@ header: - tests/ - LICENSE - requirements.txt + - *.txt.in comment: never \ No newline at end of file From 3a779e7ecfe5272f9a054a1cb3273d62aa5d7903 Mon Sep 17 00:00:00 2001 From: zachcran Date: Wed, 4 Sep 2024 17:02:22 -0600 Subject: [PATCH 10/12] Add relative path option for test names --- cmake/cmake_test/add_dir.cmake | 40 ++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/cmake/cmake_test/add_dir.cmake b/cmake/cmake_test/add_dir.cmake index 4412e1a..58e4e18 100644 --- a/cmake/cmake_test/add_dir.cmake +++ b/cmake/cmake_test/add_dir.cmake @@ -32,6 +32,10 @@ include(cmakepp_lang/cmakepp_lang) # # :keyword CT_DEBUG_MODE_ON: Enables debug mode when the tests are run. # :type CT_DEBUG_MODE_ON: bool +# :keyword USE_REL_PATH_NAMES: Enables using shorter, relative paths for +# test names, but increases the chance of name +# collisions. +# :type USE_REL_PATH_NAMES: bool # :keyword CMAKE_OPTIONS: List of additional CMake options to be # passed to all test invocations. Options # should follow the syntax: @@ -44,7 +48,7 @@ function(ct_add_dir _ad_test_dir) # debug mode for the test projects (see the use of 'ct_debug_mode' # in cmake/cmake_test/templates/test_project_CMakeLists.txt.in). # I propose renaming it to something like "ENABLE_DEBUG_MODE_IN_TESTS". - set(_ad_options CT_DEBUG_MODE_ON) + set(_ad_options CT_DEBUG_MODE_ON USE_REL_PATH_NAMES) cmake_parse_arguments(PARSE_ARGV 1 ADD_DIR "${_ad_options}" "" "${_ad_multi_value_args}") # This variable will be picked up by the template @@ -124,9 +128,37 @@ function(ct_add_dir _ad_test_dir) @ONLY ) - # The test name is long right now, but it would likely be much more - # complicated to make it shorter while still unique and readable - set(_ad_test_name "${_ad_test_file}") + if (ADD_DIR_USE_REL_PATH_NAMES) + # Option 1 - shortest but highest collision likelyhood + # Prepend the test name to the relative path to test file from the + # given test directory + + # set(_ad_test_name "${}/${_ad_test_file_rel_path}") + + + # Option 2 - longest but least collision likelyhood + # Get the path from the root of the project, with the project name + # prepended + + # Generate relative path from project root for the test name + # file(RELATIVE_PATH + # _ad_test_file_rel_path_from_proj_root + # "${PROJECT_SOURCE_DIR}" + # "${_ad_test_file}" + # ) + # # Prepend the project name to the relative path + # set(_ad_test_name "${PROJECT_NAME}/${_ad_test_file_rel_path_from_proj_root}") + + + # Option 3 - in-between length and collision likelyhood + # Prepend the project name and given test directory name to the + # test file relative path + + get_filename_component(_ad_test_dir_name "${_ad_test_dir}" NAME) + set(_ad_test_name "${PROJECT_NAME}::${_ad_test_dir_name}/${_ad_test_file_rel_path}") + else() + set(_ad_test_name "${_ad_test_file}") + endif() add_test( NAME "${_ad_test_name}" From ec2f6c2b40aaa66d97d3bdf03d2b00c17fcc9590 Mon Sep 17 00:00:00 2001 From: zachcran Date: Wed, 4 Sep 2024 18:09:59 -0500 Subject: [PATCH 11/12] Try to fix licenserc paths-ignore to include *.txt.in --- .github/.licenserc.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/.licenserc.yaml b/.github/.licenserc.yaml index 92fd8a8..7aabf72 100644 --- a/.github/.licenserc.yaml +++ b/.github/.licenserc.yaml @@ -25,6 +25,6 @@ header: - tests/ - LICENSE - requirements.txt - - *.txt.in + - "*.txt.in" comment: never \ No newline at end of file From 937f008a87163c24fbebe96fd280b8ef28ba2aa3 Mon Sep 17 00:00:00 2001 From: zachcran Date: Wed, 4 Sep 2024 18:12:31 -0500 Subject: [PATCH 12/12] Try to fix licenserc paths-ignore to include *.txt.in files again --- .github/.licenserc.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/.licenserc.yaml b/.github/.licenserc.yaml index 7aabf72..d1cb1f6 100644 --- a/.github/.licenserc.yaml +++ b/.github/.licenserc.yaml @@ -25,6 +25,6 @@ header: - tests/ - LICENSE - requirements.txt - - "*.txt.in" + - "**/**.txt.in" comment: never \ No newline at end of file