Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable prepending to path-like environment variables #14

Merged
merged 6 commits into from
Nov 10, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 65 additions & 1 deletion Modules/CetTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ CetTest
#
# CLEAR
# Clear the global test environment (ie anything previously set with
# cet_test_env()) before setting <env>.
# cet_test_env()) before setting <env>.
#
####################################
# Notes:
Expand All @@ -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(<env> [<options] [<dir>+])
#
####################################
# 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:
#
# * <dir> is a directory string or generator expression whose
# * evaluation will be prepended to the specified environment
# * variable. If no <dir> 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.
#
########################################################################

knoepfel marked this conversation as resolved.
Show resolved Hide resolved
########################################################################
# cet_test_assertion: require assertion failure on given condition
#
Expand Down Expand Up @@ -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(<var> [REMOVE_DUPLICATES] <dir> ...)

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)
knoepfel marked this conversation as resolved.
Show resolved Hide resolved
endfunction()

function(_cet_add_ref_test)
if (${NTESTS} EQUAL 1)
_cet_add_ref_test_detail(${TEST_TARGET_NAME} ${CET_TEST_WORKDIR} ${ARGN})
Expand Down