From 3d52874f07c2ae473acea540953b0a3585d72006 Mon Sep 17 00:00:00 2001 From: Kyle Knoepfel Date: Thu, 9 Nov 2023 08:55:39 -0600 Subject: [PATCH 1/6] Enable prepending to path-like environment variables. --- Modules/CetTest.cmake | 66 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/Modules/CetTest.cmake b/Modules/CetTest.cmake index 516bcaa9..20d3c66d 100644 --- a/Modules/CetTest.cmake +++ b/Modules/CetTest.cmake @@ -249,7 +249,7 @@ CetTest # # CLEAR # Clear the global test environment (ie anything previously set with -# cet_test_env()) before setting . +# cet_test_env()) before setting . # #################################### # Notes: @@ -264,6 +264,35 @@ CetTest # ######################################################################## +######################################################################## +# cet_test_prepend_env: prepend directories to the specified environment +# variable all tests here specified. +# +# Usage: cet_test_prepend_env( [+]) +# +#################################### +# Options: +# +# REMOVE_DUPLICATES +# Remove any duplicate directory entries that may appear in the +# directories specified by the user. For a given duplicate, only +# the first entry will be kept. +# +#################################### +# Notes: +# +# * is a directory string or generator expression whose +# * evaluation will be prepended to the specified environment +# * variable. If no argument is given, then +# * cet_test_prepend_env() is a NOP. +# +# * If cet_test_prepend_env() is called in a directory to set the +# environment for tests then that will be propagated to tests +# defined in subdirectories unless cet_test_env(CLEAR ...) is +# invoked in that directory. +# +######################################################################## + ######################################################################## # cet_test_assertion: require assertion failure on given condition # @@ -1009,6 +1038,41 @@ function(cet_test_env) set(CET_TEST_ENV "${CET_TEST_ENV}" PARENT_SCOPE) endfunction() +#[================================================================[.rst: +.. command:: cet_test_prepend_env + + Prepend to path-like environment variables to the test environment + for tests defined in and below the current directory. + + .. code-block:: cmake + + cet_test_prepend_env( [REMOVE_DUPLICATES] ...) + + Options + ^^^^^^^ + + ``REMOVE_DUPLICATES`` + Remove any duplicate directory entries that may appear in the + specified directories. For a given duplicate, only the first + entry will be kept. + +#]================================================================] + +function(cet_test_prepend_env CET_ENV_VAR) + cmake_parse_arguments(PARSE_ARGV 1 CET_TEST "REMOVE_DUPLICATES" "" "") + if (CET_TEST_REMOVE_DUPLICATES) + list(REMOVE_DUPLICATES CET_TEST_UNPARSED_ARGUMENTS) + endif() + string(REPLACE ";" ":" PREFIX "${CET_TEST_UNPARSED_ARGUMENTS}") + if (DEFINED ENV{${CET_ENV_VAR}}) + set(PATHS "${CET_ENV_VAR}=${PREFIX}:$ENV{${CET_ENV_VAR}}") + else() + set(PATHS "${CET_ENV_VAR}=${PREFIX}") + endif() + list(APPEND CET_TEST_ENV "${PATHS}") + set(CET_TEST_ENV "${CET_TEST_ENV}" PARENT_SCOPE) +endfunction() + function(_cet_add_ref_test) if (${NTESTS} EQUAL 1) _cet_add_ref_test_detail(${TEST_TARGET_NAME} ${CET_TEST_WORKDIR} ${ARGN}) From d9ea6cceb66336d859564abe35cc3d65e677b8de Mon Sep 17 00:00:00 2001 From: Chris Green Date: Thu, 9 Nov 2023 12:50:57 -0600 Subject: [PATCH 2/6] Suggested changes for `cet_test_prepend_env()` and related --- CMakeLists.txt | 2 +- Modules/CetTest.cmake | 374 +++++------------------------------------- 2 files changed, 46 insertions(+), 330 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fc7ec6b7..5f7da033 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,7 +26,7 @@ # * Awareness of multi-project builds. # ######################################################################## -set(CETMODULES_MIN_CMAKE_VERSION 3.21) # Used in config/cetmodules-cmake-version-check.cmake +set(CETMODULES_MIN_CMAKE_VERSION 3.22) # Used in config/cetmodules-cmake-version-check.cmake # Required to keep CMake happy. cmake_minimum_required(VERSION ${CETMODULES_MIN_CMAKE_VERSION}...3.27 diff --git a/Modules/CetTest.cmake b/Modules/CetTest.cmake index 20d3c66d..5d67ea5e 100644 --- a/Modules/CetTest.cmake +++ b/Modules/CetTest.cmake @@ -8,309 +8,6 @@ CetTest #]================================================================] -######################################################################## -# cet_test: specify tests in a concise and transparent way (see also -# cet_test_env() and cet_test_assertion(), below). -# -# Usage: cet_test(target [] []) -# -#################################### -# Target category options (specify at most one): -# -# COMPILE_ONLY -# -# The test is the act of attempting to build the given sources, not -# the execution of the result of the build. Use in conjunction with -# TEST_PROPERTIES WILL_FAIL and/or PASS/FAIL_REGULAR_EXPRESSION. -# -# HANDBUILT -# -# Do not build the target -- it will be provided. -# -# PREBUILT -# -# Do not build the target -- copy in from the source dir (ideal for -# e.g. scripts). -# -# USE_CATCH_MAIN -# USE_CATCH2_MAIN -# -# This test will use the Catch test framework -# (https://github.com/philsquared/Catch). The specified target will be -# built from a precompiled main program to run tests described in the -# files specified by SOURCES. -# -# N.B.: if you wish to use the ParseAndAddCatchTests() facility -# contributed to the Catch system, you should specify NO_AUTO to avoid -# generating a, "standard" test. Note also that you may have your own -# test executables using Catch without using USE_CATCH2_MAIN. However, -# be aware that the compilation of a Catch main is quite expensive, -# and any tests that *do* use this option will all share the same -# compiled main. -# -# Note also that client packages are responsible for making sure Catch -# is available, such as with: -# -# catch -nq- only_for_build -# -# in product_deps. -# -#################################### -# Other options: -# -# CONFIGURATIONS + -# -# Configurations (Debug, etc, etc) under which the test shall be -# executed. -# -# DATAFILES + -# -# Input and/or references files to be copied to the test area in the -# build tree for use by the test. If there is no path, or a relative -# path, the file is assumed to be in or under -# ${CMAKE_CURRENT_SOURCE_DIR}. -# -# DEPENDENCIES + -# -# List of top-level dependencies to consider for a PREBUILT -# target. Top-level implies a target (not file) created with -# ADD_EXECUTABLE, ADD_LIBRARY or ADD_CUSTOM_TARGET. -# -# DIRTY_WORKDIR -# -# If set, the working directory will not be cleared prior to execution -# of the test. -# -# INSTALL_BIN -# -# Install this test's script / exec in the product's binary directory -# (ignored for HANDBUILT). -# -# INSTALL_EXAMPLE -# -# Install this test and all its data files into the examples area of -# the product. -# -# INSTALL_SOURCE -# -# Install this test's source in the source area of the product. -# -# LIBRARIES + -# -# Extra libraries with which to link this target. -# -# NO_AUTO -# -# Do not add the target to the auto test list. N.B. all options -# related to the declaration of tests and setting of properties -# thereof will be ignored. -# -# OPTIONAL_GROUPS + -# -# Assign this test to one or more named optional groups (a.k.a CMake -# test labels). If ctest is executed specifying labels, then matching -# tests will be executed. -# -# PARG_