This is an automated email from the ASF dual-hosted git repository.

asf-gitbox-commits pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git

commit f114443f9472b1c8087526aa561f998a0d039010
Author: Andrew Stitcher <[email protected]>
AuthorDate: Fri Nov 6 14:41:40 2026 -0500

    PROTON-3007: Set the test environment with CTest properties
    
    pn_add_test() now uses the CTest ENVIRONMENT and ENVIRONMENT_MODIFICATION
    properties instead of wrapping every test in scripts/env.py. That script is
    removed; its remaining build-time uses become cmake -E env.
    
    PATH, PYTHONPATH and RUBYLIB are passed as individual directories and
    prepended by CTest when the test runs. This removes the per-platform
    separator handling, the configure-time $ENV{PATH} snapshots, 
to_native_path()
    and the escaping needed to pass environment settings on a command line.
    
    PREPEND_ENVIRONMENT and APPEND_ENVIRONMENT collapse into a single 
ENVIRONMENT
    keyword with a documented precedence, so -DTEST_ENV=... now overrides the
    build's own settings for the C++ tests as it already did elsewhere.
    
    Requires CMake 3.26.
    
    Assisted-By: Claude Opus 5 <[email protected]>
---
 CMakeLists.txt                |  30 +----------
 INSTALL.md                    |   4 +-
 c/CMakeLists.txt              |   4 +-
 c/examples/CMakeLists.txt     |   2 +-
 c/tests/CMakeLists.txt        |  28 ++++++-----
 c/tests/fuzz/CMakeLists.txt   |   3 +-
 cpp/examples/CMakeLists.txt   |   2 +-
 cpp/tests.cmake               |  23 +++++----
 go/CMakeLists.txt             |   2 +-
 go/examples/CMakeLists.txt    |   4 +-
 python/CMakeLists.txt         |  36 +++++++-------
 ruby/CMakeLists.txt           |  22 ++++----
 scripts/env.py                |  68 -------------------------
 tests/PNAddTest.cmake         | 113 ++++++++++++++++++++++++++++++------------
 tests/cpp/CMakeLists.txt      |  10 ++--
 tests/examples/CMakeLists.txt |  38 +++++++-------
 tests/share/CMakeLists.txt    |   3 +-
 17 files changed, 177 insertions(+), 215 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1932bdeb6..09376deaf 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -17,7 +17,7 @@
 # under the License.
 #
 
-cmake_minimum_required (VERSION 3.16)
+cmake_minimum_required (VERSION 3.26)
 
 project (Proton C)
 
@@ -58,7 +58,6 @@ set (ProtonCpp_DIR 
${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake/config)
 
 ## Variables used across components
 
-set (PN_ENV_SCRIPT "${Python_EXECUTABLE}" 
"${PROJECT_SOURCE_DIR}/scripts/env.py")
 set (PN_C_INCLUDE_DIR "${PROJECT_BINARY_DIR}/c/include")
 set (PN_C_LIBRARY_DIR "${PROJECT_BINARY_DIR}/c")
 set (PN_C_SOURCE_DIR "${PROJECT_BINARY_DIR}/c/src")
@@ -308,33 +307,6 @@ set (PROTON_SHARE ${CMAKE_INSTALL_DATADIR}/proton)
 
 ## LANGUAGE BINDINGS
 
-# Set result to a native search path - used by examples and binding tests.
-# args after result are directories or search paths.
-macro(set_search_path result)
-  set(${result} ${ARGN})
-  if (UNIX)
-    string(REPLACE ";" ":" ${result} "${${result}}") # native search path 
separators.
-  endif()
-  file(TO_NATIVE_PATH "${${result}}" ${result}) # native slash separators
-endmacro()
-
-if (CMAKE_SYSTEM_NAME STREQUAL Windows)
-  # CMake uses semicolon as list separator. Change ';'->'\;'
-  function(to_native_path path result)
-    file (TO_NATIVE_PATH "${path}" path)
-    string (REPLACE ";" "\;" path "${path}")
-    # without this, ...;last\dir\ would later combine with list separator ; 
into \;
-    set (${result} "${path}\;" PARENT_SCOPE)
-  endfunction()
-else (CMAKE_SYSTEM_NAME STREQUAL Windows)
-  # Just change ';'->':'
-  function(to_native_path path result)
-    file (TO_NATIVE_PATH "${path}" path)
-    string (REPLACE ";" ":" path "${path}")
-    set (${result} "${path}" PARENT_SCOPE)
-  endfunction()
-endif (CMAKE_SYSTEM_NAME STREQUAL Windows)
-
 add_custom_target(docs)
 add_custom_target(doc DEPENDS docs)
 
diff --git a/INSTALL.md b/INSTALL.md
index 3d0535e13..5098c5cea 100644
--- a/INSTALL.md
+++ b/INSTALL.md
@@ -30,6 +30,8 @@ Windows dependencies
 CMake (Linux)
 -------------
 
+Building Proton requires CMake 3.26 or newer.
+
 The following prerequisites are required to do a full build on
 RPM-based systems (RHEL, Fedora, etc.).  If you do not wish to build a
 given language binding you can omit the devel package for that
@@ -109,7 +111,7 @@ The following packages must be installed:
 
   - Visual Studio 2019 or newer (Community or Enterprise Editions)
   - Python 3.9 or newer (www.python.org)
-  - CMake (www.cmake.org)
+  - CMake 3.26 or newer (www.cmake.org)
 
 Additional packages are required for language bindings:
 
diff --git a/c/CMakeLists.txt b/c/CMakeLists.txt
index f4f33bf8b..02850d6b8 100644
--- a/c/CMakeLists.txt
+++ b/c/CMakeLists.txt
@@ -67,7 +67,7 @@ add_custom_command (
   OUTPUT
     ${CMAKE_CURRENT_BINARY_DIR}/src/encodings.h
   COMMAND
-    ${PN_ENV_SCRIPT} PYTHONPATH=${PROJECT_SOURCE_DIR}/tools/python 
${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/src/encodings.h.py > 
${CMAKE_CURRENT_BINARY_DIR}/src/encodings.h
+    ${CMAKE_COMMAND} -E env PYTHONPATH=${PROJECT_SOURCE_DIR}/tools/python -- 
${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/src/encodings.h.py > 
${CMAKE_CURRENT_BINARY_DIR}/src/encodings.h
   DEPENDS
     ${CMAKE_CURRENT_SOURCE_DIR}/src/encodings.h.py
   )
@@ -76,7 +76,7 @@ add_custom_command (
   OUTPUT
     ${CMAKE_CURRENT_BINARY_DIR}/src/protocol.h
   COMMAND
-    ${PN_ENV_SCRIPT} PYTHONPATH=${PROJECT_SOURCE_DIR}/tools/python 
${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/src/protocol.h.py > 
${CMAKE_CURRENT_BINARY_DIR}/src/protocol.h
+    ${CMAKE_COMMAND} -E env PYTHONPATH=${PROJECT_SOURCE_DIR}/tools/python -- 
${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/src/protocol.h.py > 
${CMAKE_CURRENT_BINARY_DIR}/src/protocol.h
   DEPENDS
     ${CMAKE_CURRENT_SOURCE_DIR}/src/protocol.h.py
   )
diff --git a/c/examples/CMakeLists.txt b/c/examples/CMakeLists.txt
index a1418fd1f..3e25e3d42 100644
--- a/c/examples/CMakeLists.txt
+++ b/c/examples/CMakeLists.txt
@@ -16,7 +16,7 @@
 # specific language governing permissions and limitations
 # under the License.
 #
-cmake_minimum_required (VERSION 3.16)
+cmake_minimum_required (VERSION 3.26)
 
 project(ProtonCExamples C)
 
diff --git a/c/tests/CMakeLists.txt b/c/tests/CMakeLists.txt
index 117bc604b..823b1786e 100644
--- a/c/tests/CMakeLists.txt
+++ b/c/tests/CMakeLists.txt
@@ -18,10 +18,11 @@
 #
 
 include_directories(${PROJECT_SOURCE_DIR}/tests/include)
+set(test_env "TEST_CERT_DIR=${TEST_CERT_DIR}")
 if (WIN32)
-  set(test_env 
"PATH=$<TARGET_FILE_DIR:qpid-proton-core>;TEST_CERT_DIR=${TEST_CERT_DIR}")
+  # Windows looks for DLLs on PATH
+  set(test_path $<TARGET_FILE_DIR:qpid-proton-core>)
 else()
-  set(test_env "TEST_CERT_DIR=${TEST_CERT_DIR}")
   set(platform_test_src ssl_test.cpp)
 endif()
 
@@ -57,7 +58,8 @@ if (CMAKE_CXX_COMPILER)
     pn_add_test(
       EXECUTABLE
       NAME ${exe}
-      PREPEND_ENVIRONMENT ${test_env}
+      ENVIRONMENT ${test_env}
+      PATH_PREPEND ${test_path}
       WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
       COMMAND $<TARGET_FILE:${exe}>)
   endmacro()
@@ -110,29 +112,29 @@ if (CMAKE_CXX_COMPILER)
       pn_add_test(
         EXECUTABLE
         NAME c-threaderciser
-        PREPEND_ENVIRONMENT ${test_env}
+        ENVIRONMENT ${test_env}
+        PATH_PREPEND ${test_path}
         WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
         COMMAND $<TARGET_FILE:c-threaderciser>)
     endif()
 
+    set(fdlimit_path $<TARGET_FILE_DIR:c-broker>)
     if(WIN32)
-      set(path "$<TARGET_FILE_DIR:c-broker>\\;$<TARGET_FILE_DIR:qpid-proton>")
-    else(WIN32)
-      set(path "$<TARGET_FILE_DIR:c-broker>:$ENV{PATH}")
-    endif(WIN32)
-
-    set(pypath "${PROJECT_SOURCE_DIR}/tests/py")
+      list(APPEND fdlimit_path $<TARGET_FILE_DIR:qpid-proton>)
+    endif()
 
     # Disable fdlimit test by default. Flaky throughout its history and 
implementations.
     # Very useful for proactor development, so keep around.
     option(ENABLE_FDLIMIT_TEST "Run the fdlimit recovery test" OFF)
     if (ENABLE_FDLIMIT_TEST)
-      # unset TEST_EXE_PREFIX as valgrind does not run successfully when fds 
are limited
       pn_add_test(
         UNWRAPPED
         NAME c-fdlimit-tests
-        PREPEND_ENVIRONMENT "PATH=${path}" "PYTHONPATH=${pypath}" "${test_env}"
-        APPEND_ENVIRONMENT "TEST_EXE_PREFIX="
+        ENVIRONMENT ${test_env}
+        PATH_PREPEND ${fdlimit_path}
+        PYTHONPATH_PREPEND "${PROJECT_SOURCE_DIR}/tests/py"
+        # valgrind does not run successfully when fds are limited
+        UNSET_ENVIRONMENT TEST_EXE_PREFIX
         WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
         COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/fdlimit.py)
     endif()
diff --git a/c/tests/fuzz/CMakeLists.txt b/c/tests/fuzz/CMakeLists.txt
index ebe22add2..68d082aa8 100644
--- a/c/tests/fuzz/CMakeLists.txt
+++ b/c/tests/fuzz/CMakeLists.txt
@@ -63,7 +63,8 @@ macro (pn_add_fuzz_test test)
     pn_add_test(
       EXECUTABLE
       NAME ${test}
-      PREPEND_ENVIRONMENT ${test_env}
+      ENVIRONMENT ${test_env}
+      PATH_PREPEND ${test_path}
       COMMAND $<TARGET_FILE:${test}> 
"@${CMAKE_CURRENT_BINARY_DIR}/${test}-files")
   else ()
     pn_add_test(
diff --git a/cpp/examples/CMakeLists.txt b/cpp/examples/CMakeLists.txt
index 685a5ed36..2134ab00b 100644
--- a/cpp/examples/CMakeLists.txt
+++ b/cpp/examples/CMakeLists.txt
@@ -16,7 +16,7 @@
 # specific language governing permissions and limitations
 # under the License.
 #
-cmake_minimum_required (VERSION 3.16)
+cmake_minimum_required (VERSION 3.26)
 
 project(ProtonCppExamples C CXX)
 
diff --git a/cpp/tests.cmake b/cpp/tests.cmake
index b29753b3a..7171459f8 100644
--- a/cpp/tests.cmake
+++ b/cpp/tests.cmake
@@ -36,7 +36,8 @@ if(CyrusSASL_Saslpasswd_EXECUTABLE)
 endif()
 
 if (CMAKE_SYSTEM_NAME STREQUAL Windows)
-  set(test_env ${test_env} "PATH=$<TARGET_FILE_DIR:qpid-proton>")
+  # Windows looks for DLLs on PATH
+  set(test_path $<TARGET_FILE_DIR:qpid-proton>)
 endif()
 
 macro(add_cpp_test test)
@@ -45,7 +46,8 @@ macro(add_cpp_test test)
   pn_add_test(
     EXECUTABLE
     NAME cpp-${test}
-    APPEND_ENVIRONMENT ${test_env}
+    ENVIRONMENT ${test_env}
+    PATH_PREPEND ${test_path}
     COMMAND $<TARGET_FILE:${test}>
     ${ARGN})
 endmacro(add_cpp_test)
@@ -72,12 +74,11 @@ if (ENABLE_JSONCPP)
   file(COPY  "${CMAKE_CURRENT_SOURCE_DIR}/testdata" DESTINATION 
"${CMAKE_CURRENT_BINARY_DIR}")
 
   if (NOT CMAKE_SYSTEM_NAME STREQUAL Windows)
-    add_executable (pkcs11_test src/pkcs11_test.cpp)
-    target_link_libraries (pkcs11_test qpid-proton-cpp qpid-proton-core 
${PLATFORM_LIBS})
-    # PKCS#11 URIs contain semicolons, which CMake would interpret as
-    # list sepearator, so we side step add_cpp_test and pass the env
-    # through as is.
-    add_test(NAME cpp-pkcs11_test COMMAND $<TARGET_FILE:pkcs11_test>)
+    # Reads its PKCS#11 URIs from the ambient environment, and skips if they
+    # are not set. pn_add_test only adds to the inherited environment, so
+    # they still reach the test.
+    add_cpp_test(pkcs11_test)
+    target_link_libraries (pkcs11_test qpid-proton-core)
     set_tests_properties(cpp-pkcs11_test PROPERTIES SKIP_RETURN_CODE 127)
   endif()
 endif()
@@ -112,7 +113,8 @@ macro(add_catch_test tag)
   pn_add_test(
     EXECUTABLE
     NAME cpp-${tag}-test
-    APPEND_ENVIRONMENT ${test_env}
+    ENVIRONMENT ${test_env}
+    PATH_PREPEND ${test_path}
     COMMAND $<TARGET_FILE:cpp-test> "[${tag}]")
   set_tests_properties(cpp-${tag}-test PROPERTIES  FAIL_REGULAR_EXPRESSION 
".*No tests ran.*")
 endmacro(add_catch_test)
@@ -121,7 +123,8 @@ macro(add_core_catch_test tag)
   pn_add_test(
           EXECUTABLE
           NAME cpp-${tag}-test
-          APPEND_ENVIRONMENT ${test_env}
+          ENVIRONMENT ${test_env}
+          PATH_PREPEND ${test_path}
           COMMAND $<TARGET_FILE:cpp-core-test> "[${tag}]")
   set_tests_properties(cpp-${tag}-test PROPERTIES  FAIL_REGULAR_EXPRESSION 
".*No tests ran.*")
 endmacro(add_core_catch_test)
diff --git a/go/CMakeLists.txt b/go/CMakeLists.txt
index 5be23564c..21afabf5e 100644
--- a/go/CMakeLists.txt
+++ b/go/CMakeLists.txt
@@ -66,7 +66,7 @@ if (BUILD_GO)
     "SASLPASSWD=${CyrusSASL_Saslpasswd_EXECUTABLE}"
     CACHE INTERNAL "Run a command with Go environment variables")
 
-  set(GO ${PN_ENV_SCRIPT} -- ${GO_ENV} ${GO_EXE} CACHE INTERNAL "Run go with 
environment set")
+  set(GO ${CMAKE_COMMAND} -E env ${GO_ENV} -- ${GO_EXE} CACHE INTERNAL "Run go 
with environment set")
 
   set(GO_BUILD ${GO} build ${GO_BUILD_FLAGS} ${GO_RPATH_FLAGS} CACHE INTERNAL 
"Run go build")
   set(GO_INSTALL ${GO} install ${GO_BUILD_FLAGS} CACHE INTERNAL "Run go 
install" )
diff --git a/go/examples/CMakeLists.txt b/go/examples/CMakeLists.txt
index a4c85ccbe..9908ea0c8 100644
--- a/go/examples/CMakeLists.txt
+++ b/go/examples/CMakeLists.txt
@@ -45,13 +45,13 @@ if(BUILD_GO)
   pn_add_test(
     UNWRAPPED
     NAME go-example-electron
-    PREPEND_ENVIRONMENT ${GO_ENV}
+    ENVIRONMENT ${GO_ENV}
     COMMAND ${test_exe} -dir ${CMAKE_CURRENT_BINARY_DIR}/electron -broker 
broker)
 
   pn_add_test(
     UNWRAPPED
     NAME go-example-proton
-    PREPEND_ENVIRONMENT ${GO_ENV}
+    ENVIRONMENT ${GO_ENV}
     COMMAND ${test_exe} -dir ${CMAKE_CURRENT_BINARY_DIR}/electron -broker 
../proton/broker)
   list(APPEND ADDITIONAL_MAKE_CLEAN_FILES ${examples})
 endif()
diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt
index 2f15682dc..bd700ff18 100644
--- a/python/CMakeLists.txt
+++ b/python/CMakeLists.txt
@@ -72,9 +72,9 @@ if (NOT SPHINX_MODULE_FOUND)
 else ()
     add_custom_target(docs-py
              DEPENDS .timestamp.test_env
-        COMMAND ${PN_ENV_SCRIPT} --
-        PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}:${CMAKE_CURRENT_SOURCE_DIR}
-        LD_LIBRARY_PATH="${CMAKE_CURRENT_BINARY_DIR}/c"
+        COMMAND ${CMAKE_COMMAND} -E env
+        PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}
+        --
         ${Python_EXECUTABLE} -m sphinx "${CMAKE_CURRENT_SOURCE_DIR}/docs" 
"${CMAKE_CURRENT_BINARY_DIR}/docs")
     add_dependencies(docs docs-py)
     install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/docs/"
@@ -234,15 +234,18 @@ endif()
 if (BUILD_TESTING)
   # python test: python/tests/proton-test
   set (py_src "${CMAKE_CURRENT_SOURCE_DIR}")
-  # These are only needed on Windows due to build differences
-  set (py_bld "$<$<PLATFORM_ID:Windows>:$<TARGET_FILE_DIR:qpid-proton-core>>")
   set (py_tests "${py_src}/tests")
   set (tests_py "${py_src}/../tests/py")
 
-  set (py_path $<$<TARGET_EXISTS:msgr-recv>:$<TARGET_FILE_DIR:msgr-recv>> 
${py_bld} $ENV{PATH})
-  set (py_pythonpath ${py_tests} ${py_src} ${py_bin} ${tests_py} 
$ENV{PYTHONPATH})
-  to_native_path ("${py_pythonpath}" py_pythonpath)
-  to_native_path ("${py_path}" py_path)
+  unset (py_path)
+  if (TARGET msgr-recv)
+    list (APPEND py_path $<TARGET_FILE_DIR:msgr-recv>)
+  endif ()
+  if (WIN32)
+    # Only needed on Windows due to build differences: DLLs are found on PATH
+    list (APPEND py_path $<TARGET_FILE_DIR:qpid-proton-core>)
+  endif ()
+  set (py_pythonpath ${py_tests} ${py_src} ${py_bin} ${tests_py})
 
   if (CMAKE_BUILD_TYPE MATCHES "Coverage")
     set (python_coverage_module "coverage")
@@ -280,20 +283,20 @@ if (BUILD_TESTING)
     pn_add_test(
       INTERPRETED
       NAME python-test
-      PREPEND_ENVIRONMENT
-        "PATH=${py_path}"
+      ENVIRONMENT
         "PYTHONPATH=."
         "SASLPASSWD=${CyrusSASL_Saslpasswd_EXECUTABLE}"
+      PATH_PREPEND ${py_path}
       COMMAND ${pytest_executable} ${python_coverage_options} -- 
"${py_tests}/proton-test")
 
     set(PYTHON_TEST_COMMAND "-m" "unittest")
     pn_add_test(
       INTERPRETED
       NAME python-integration-test
-      PREPEND_ENVIRONMENT
-        "PATH=${py_path}"
-        "PYTHONPATH=.:${py_pythonpath}"
+      ENVIRONMENT
         "SASLPASSWD=${CyrusSASL_Saslpasswd_EXECUTABLE}"
+      PATH_PREPEND ${py_path}
+      PYTHONPATH_PREPEND . ${py_pythonpath}
       COMMAND
         ${pytest_executable}
           ${python_coverage_options}
@@ -334,12 +337,11 @@ if (BUILD_TESTING)
     pn_add_test(
       INTERPRETED
       NAME python-tox-test
-      WORKING_DIRECTORY ${py_dist_dir}
-      PREPEND_ENVIRONMENT
-        "PATH=${py_path}"
+      ENVIRONMENT
         "SASLPASSWD=${CyrusSASL_Saslpasswd_EXECUTABLE}"
         "TOXENV=${TOX_ENVLIST}"
         "PY_TEST_DIR=${CMAKE_CURRENT_SOURCE_DIR}/tests"
+      PATH_PREPEND ${py_path}
       COMMAND ${Python_EXECUTABLE} -m tox)
     set_tests_properties(python-tox-test
       PROPERTIES
diff --git a/ruby/CMakeLists.txt b/ruby/CMakeLists.txt
index fb48f4494..6930a36b5 100644
--- a/ruby/CMakeLists.txt
+++ b/ruby/CMakeLists.txt
@@ -94,24 +94,20 @@ install(DIRECTORY examples/
         USE_SOURCE_PERMISSIONS)
 ## Tests
 
-to_native_path("${src}/lib;${src}/tests;${src}/spec;${bin};${c_lib_dir};$ENV{RUBYLIB}"
 RUBYLIB)
-to_native_path("${bin};${c_lib_dir};$ENV{PATH}" PATH)
-
-if (CMAKE_BUILD_TYPE MATCHES "Coverage")
-  set(COVERAGE "COVERAGE=1")
-endif ()
+set(test_rubylib ${src}/lib ${src}/tests ${src}/spec ${bin} ${c_lib_dir})
+set(test_path ${bin} ${c_lib_dir})
 
 execute_process(COMMAND ${RUBY_EXECUTABLE} -r minitest -e ""
   RESULT_VARIABLE result OUTPUT_QUIET ERROR_QUIET)
 if (result EQUAL 0)  # Have minitest
   set(test_env
-    "PATH=${PATH}"
     "SSL_CERT_DIR=${TEST_CERT_DIR}"
-    "RUBYLIB=${RUBYLIB}"
     "PN_SASL_CONFIG_PATH=${PROJECT_BINARY_DIR}/sasl-conf"
-    "${COVERAGE}"
     "COVERAGE_DIR=${PROJECT_BINARY_DIR}/coverage_results/ruby"
     "SASLPASSWD=${CyrusSASL_Saslpasswd_EXECUTABLE}")
+  if (CMAKE_BUILD_TYPE MATCHES "Coverage")
+    list(APPEND test_env "COVERAGE=1")
+  endif ()
 
   macro(add_ruby_test script)
     get_filename_component(name ${script} NAME_WE)
@@ -119,7 +115,9 @@ if (result EQUAL 0)  # Have minitest
     pn_add_test(
       INTERPRETED
       NAME ${name}
-      PREPEND_ENVIRONMENT ${test_env}
+      ENVIRONMENT ${test_env}
+      PATH_PREPEND ${test_path}
+      RUBYLIB_PREPEND ${test_rubylib}
       COMMAND ${RUBY_EXECUTABLE} 
-r${CMAKE_CURRENT_SOURCE_DIR}/tests/collect_coverage.rb ${script} -v
       WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}  # simplecov doesn't report on 
code not under $CWD
       ${ARGN})
@@ -128,7 +126,9 @@ if (result EQUAL 0)  # Have minitest
   pn_add_test(
     INTERPRETED
     NAME ruby-example-test
-    PREPEND_ENVIRONMENT ${test_env}
+    ENVIRONMENT ${test_env}
+    PATH_PREPEND ${test_path}
+    RUBYLIB_PREPEND ${test_rubylib}
     COMMAND ${RUBY_EXECUTABLE} testme -v
     WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/examples)
 
diff --git a/scripts/env.py b/scripts/env.py
deleted file mode 100644
index 1447e9778..000000000
--- a/scripts/env.py
+++ /dev/null
@@ -1,68 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#   http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-
-#
-# A platform-agnostic tool for running a program in a modified environment.
-#
-
-import sys
-import os
-import subprocess
-from optparse import OptionParser
-
-
-def main(argv=None):
-
-    parser = OptionParser(usage="Usage: %prog [options] [--] VAR=VALUE... 
command [options] arg1 arg2...")
-    parser.add_option("-i", "--ignore-environment",
-                      action="store_true", default=False,
-                      help="Start with an empty environment (do not inherit 
current environment)")
-
-    (options, args) = parser.parse_args(args=argv)
-
-    if options.ignore_environment:
-        new_env = {}
-    else:
-        new_env = os.environ.copy()
-
-    # pull out each name value pair
-    while len(args):
-        z = args[0].split("=", 1)
-        if len(z) != 2:
-            break  # done with env args
-        name, value = z[0], z[1]
-        if len(name) == 0:
-            raise Exception("Error: incorrect format for env var: '%s'" % 
str(args[0]))
-        del args[0]
-        if len(value) == 0:
-            # value is not present, so delete it
-            if name in new_env:
-                del new_env[name]
-        else:
-            new_env[name] = value
-
-    if len(args) == 0 or len(args[0]) == 0:
-        raise Exception("Error: syntax error in command arguments")
-
-    p = subprocess.Popen(args, env=new_env)
-    return p.wait()
-
-
-if __name__ == "__main__":
-    sys.exit(main())
diff --git a/tests/PNAddTest.cmake b/tests/PNAddTest.cmake
index a4c2257e6..bc0d2bfa8 100644
--- a/tests/PNAddTest.cmake
+++ b/tests/PNAddTest.cmake
@@ -17,46 +17,97 @@
 # under the License.
 #
 
-# Helper function to define execution environment for ctest test targets
+# Helper function to define execution environment for ctest test targets.
 
-include(CMakeParseArguments)
 include(CTest)
 
+# pn_add_test(
+#   EXECUTABLE | INTERPRETED | UNWRAPPED    # required, see below
+#   NAME <name>
+#   COMMAND <command>
+#   [WORKING_DIRECTORY <dir>]
+#   [ENVIRONMENT <NAME=VALUE>...]           # set for this test
+#   [UNSET_ENVIRONMENT <NAME>...]           # removed for this test
+#   [PATH_PREPEND <dir>...]                 # prepended to PATH
+#   [PYTHONPATH_PREPEND <dir>...]           # prepended to PYTHONPATH
+#   [RUBYLIB_PREPEND <dir>...]              # prepended to RUBYLIB
+#   [ENV_MODIFICATION <NAME=OP:VALUE>...]   # raw ENVIRONMENT_MODIFICATION 
entries
+#   [<extra arguments for COMMAND>...]
+# )
+#
+# One of these is required, to say how the test is wrapped for runtime 
checking:
+#   EXECUTABLE  - a compiled program, run under TEST_EXE_PREFIX
+#   INTERPRETED - an interpreter (python, ruby) loading proton as an extension,
+#                 run under TEST_WRAP_PREFIX
+#   UNWRAPPED   - run as-is, no runtime check wrapper
+#
+# Environment precedence, lowest to highest:
+#   1. the environment ctest itself was run with
+#   2. ENVIRONMENT entries given here
+#   3. TEST_ENV, so an explicit -DTEST_ENV=... on the cmake command line 
always wins
+#   4. the *_PREPEND, UNSET_ENVIRONMENT and ENV_MODIFICATION entries, which 
CTest
+#      applies after everything above
+#
+# The *_PREPEND arguments take individual directories, not a pre-joined list,
+# and keep the order they are given in: PATH_PREPEND a b c puts "a:b:c" in
+# front of PATH. CTest applies them when the test runs, using the native path
+# separator, so there is no need to join them by hand or to special case
+# Windows, and they are prepended to the real PATH rather than to whatever
+# PATH happened to be set when cmake ran.
+
+# Add ENVIRONMENT_MODIFICATION entries to <out> prepending the directories in
+# the list variable <dirs_var> to the search path <name>. CTest applies the
+# entries in order and each one goes to the front, so emit them last to first
+# to end up with the caller's ordering.
+macro(_pn_path_prepend out name dirs_var)
+  set(_pn_dirs ${${dirs_var}})
+  if (_pn_dirs)
+    list(REVERSE _pn_dirs)
+    foreach(_pn_dir IN LISTS _pn_dirs)
+      list(APPEND ${out} "${name}=path_list_prepend:${_pn_dir}")
+    endforeach()
+  endif()
+endmacro()
+
 function(pn_add_test)
-  set(options EXECUTABLE INTERPRETED UNWRAPPED IGNORE_ENVIRONMENT)
+  set(options EXECUTABLE INTERPRETED UNWRAPPED)
   set(oneValueArgs NAME COMMAND WORKING_DIRECTORY)
-  set(multiValueArgs PREPEND_ENVIRONMENT APPEND_ENVIRONMENT)
-
-  # Semicolon is CMake list separator and path separator on Windows; 
cmake_parse_arguments flattens nested lists!
-  # Replace \; to /////, call cmake_parse_arguments, then replace back where 
it matters; ///// is unlikely to appear
-  STRING(REPLACE \\\; ///// escaped_ARGN "${ARGN}")
-  cmake_parse_arguments(pn_add_test "${options}" "${oneValueArgs}" 
"${multiValueArgs}" "${escaped_ARGN}")
-
-  set(escaped_environment ${pn_add_test_PREPEND_ENVIRONMENT} ${TEST_ENV} 
${pn_add_test_APPEND_ENVIRONMENT})
-  STRING(REPLACE ///// \\\; environment "${escaped_environment}")
-
-  if (pn_add_test_IGNORE_ENVIRONMENT)
-    set (ignore_environment "--ignore_environment")
-  else(pn_add_test_IGNORE_ENVIRONMENT)
-    set (ignore_environment "")
-  endif(pn_add_test_IGNORE_ENVIRONMENT)
-
-  if (pn_add_test_UNWRAPPED)
-    set (wrapper "")
-  elseif(pn_add_test_INTERPRETED)
-    set (wrapper "${TEST_WRAP_PREFIX_CMD}")
-  elseif(pn_add_test_EXECUTABLE)
-    set (wrapper "${TEST_EXE_PREFIX_CMD}")
+  set(multiValueArgs
+    ENVIRONMENT UNSET_ENVIRONMENT ENV_MODIFICATION
+    PATH_PREPEND PYTHONPATH_PREPEND RUBYLIB_PREPEND)
+
+  # PARSE_ARGV keeps each argument intact, so a value containing a literal
+  # semicolon (e.g. a PKCS#11 URI) survives without any escaping games.
+  cmake_parse_arguments(PARSE_ARGV 0 arg
+    "${options}" "${oneValueArgs}" "${multiValueArgs}")
+
+  if (arg_UNWRAPPED)
+    set(wrapper "")
+  elseif (arg_INTERPRETED)
+    set(wrapper "${TEST_WRAP_PREFIX_CMD}")
+  elseif (arg_EXECUTABLE)
+    set(wrapper "${TEST_EXE_PREFIX_CMD}")
   else()
     message(FATAL_ERROR "pn_add_test requires one of EXECUTABLE INTERPRETED 
UNWRAPPED")
   endif()
 
-  add_test (
-    NAME "${pn_add_test_NAME}"
-    COMMAND ${PN_ENV_SCRIPT} ${ignore_environment} -- ${environment} 
${wrapper} ${pn_add_test_COMMAND} ${pn_add_test_UNPARSED_ARGUMENTS}
-    WORKING_DIRECTORY "${pn_add_test_WORKING_DIRECTORY}"
+  add_test(
+    NAME "${arg_NAME}"
+    COMMAND ${wrapper} ${arg_COMMAND} ${arg_UNPARSED_ARGUMENTS}
+    WORKING_DIRECTORY "${arg_WORKING_DIRECTORY}"
   )
 
-  # TODO jdanek 2020-01-17: this could be used instead of env.py, it looks 
CMake 2.8.12 compatible
-  #set_tests_properties("${pn_add_test_NAME}" PROPERTIES ENVIRONMENT 
"${environment}")
+  set(environment ${arg_ENVIRONMENT} ${TEST_ENV})
+
+  set(modification ${arg_ENV_MODIFICATION})
+  _pn_path_prepend(modification PATH arg_PATH_PREPEND)
+  _pn_path_prepend(modification PYTHONPATH arg_PYTHONPATH_PREPEND)
+  _pn_path_prepend(modification RUBYLIB arg_RUBYLIB_PREPEND)
+  foreach(name IN LISTS arg_UNSET_ENVIRONMENT)
+    list(APPEND modification "${name}=unset:")
+  endforeach()
+
+  set_tests_properties("${arg_NAME}" PROPERTIES
+    ENVIRONMENT "${environment}"
+    ENVIRONMENT_MODIFICATION "${modification}")
 endfunction(pn_add_test)
diff --git a/tests/cpp/CMakeLists.txt b/tests/cpp/CMakeLists.txt
index 95c8d9aa9..bf4e045a8 100644
--- a/tests/cpp/CMakeLists.txt
+++ b/tests/cpp/CMakeLists.txt
@@ -34,18 +34,16 @@ target_link_libraries(tx_tester qpid-proton-cpp 
qpid-proton-core Threads::Thread
 target_include_directories(tx_tester PRIVATE 
${PROJECT_SOURCE_DIR}/cpp/examples)
 
 if(WIN32)
-  # NOTE: need to escape semicolons as cmake uses them as list separators.
-  set(test_path 
"$<TARGET_FILE_DIR:qpid-proton-cpp>\;$<TARGET_FILE_DIR:qpid-proton-core>")
-else()
-  set(test_path "$ENV{PATH}")
+  # Windows looks for DLLs on PATH
+  set(test_path $<TARGET_FILE_DIR:qpid-proton-cpp> 
$<TARGET_FILE_DIR:qpid-proton-core>)
 endif()
 
 if (PYTHON_TEST_EXECUTABLE)
   pn_add_test(
     INTERPRETED
     NAME cpp-tx-tests
-    PREPEND_ENVIRONMENT
-      "PATH=${test_path}"
+    PATH_PREPEND ${test_path}
+    ENVIRONMENT
       "TX_TESTER=$<TARGET_FILE:tx_tester>"
       "TX_TESTER_PYTHON=${PYTHON_TEST_EXECUTABLE}"
       "TX_TESTER_BROKER=${PROJECT_SOURCE_DIR}/python/examples/broker.py"
diff --git a/tests/examples/CMakeLists.txt b/tests/examples/CMakeLists.txt
index 8bdb6360c..21a602b9d 100644
--- a/tests/examples/CMakeLists.txt
+++ b/tests/examples/CMakeLists.txt
@@ -22,42 +22,38 @@ if (NOT Python_EXECUTABLE)
   return()
 endif()
 
+set(c_test_path $<TARGET_FILE_DIR:c-broker>)
 if(WIN32)
-  # NOTE: need to escape semicolons as cmake uses them as list separators.
-  set(c_test_path 
"$<TARGET_FILE_DIR:c-broker>\;$<TARGET_FILE_DIR:qpid-proton-core>\;$<TARGET_FILE_DIR:qpid-proton-proactor>")
-else()
-  set(c_test_path "$<TARGET_FILE_DIR:c-broker>:$ENV{PATH}")
+  # Windows looks for DLLs on PATH
+  list(APPEND c_test_path
+    $<TARGET_FILE_DIR:qpid-proton-core> 
$<TARGET_FILE_DIR:qpid-proton-proactor>)
 endif()
 
-set(c_test_env
-  "PATH=${c_test_path}"
-  "SSL_CERT_DIR=${TEST_CERT_DIR}"
-  "PYTHONPATH=${Proton_SOURCE_DIR}/tests/py")
-
 pn_add_test(
   UNWRAPPED
   NAME c-example-tests
-  PREPEND_ENVIRONMENT "${c_test_env}"
+  ENVIRONMENT "SSL_CERT_DIR=${TEST_CERT_DIR}"
+  PATH_PREPEND ${c_test_path}
+  PYTHONPATH_PREPEND "${Proton_SOURCE_DIR}/tests/py"
   WORKING_DIRECTORY ${ProtonCExamples_SOURCE_DIR}
   COMMAND ${Python_EXECUTABLE} testme -v)
 
 if (BUILD_CPP)
+  set(cpp_test_path $<TARGET_FILE_DIR:broker>)
   if(WIN32)
-    # NOTE: need to escape semicolons as cmake uses them as list separators.
-    set(cpp_test_path 
"$<TARGET_FILE_DIR:broker>\;$<TARGET_FILE_DIR:qpid-proton-core>\;$<TARGET_FILE_DIR:qpid-proton-cpp>")
-  else()
-    set(cpp_test_path "$<TARGET_FILE_DIR:broker>:$ENV{PATH}")
+    # Windows looks for DLLs on PATH
+    list(APPEND cpp_test_path
+      $<TARGET_FILE_DIR:qpid-proton-core> $<TARGET_FILE_DIR:qpid-proton-cpp>)
   endif()
 
-  set(cpp_test_env
-    "PATH=${cpp_test_path}"
-    "TEST_CERT_DIR=${TEST_CERT_DIR}"
-    "PYTHONPATH=${Proton_SOURCE_DIR}/tests/py")
+  set(cpp_test_env "TEST_CERT_DIR=${TEST_CERT_DIR}")
 
   pn_add_test(
     UNWRAPPED
     NAME cpp-example-container
-    PREPEND_ENVIRONMENT "${cpp_test_env}"
+    ENVIRONMENT ${cpp_test_env}
+    PATH_PREPEND ${cpp_test_path}
+    PYTHONPATH_PREPEND "${Proton_SOURCE_DIR}/tests/py"
     WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
     COMMAND ${Python_EXECUTABLE} ${ProtonCppExamples_SOURCE_DIR}/testme -v 
ContainerExampleTest)
 
@@ -65,7 +61,9 @@ if (BUILD_CPP)
     pn_add_test(
       UNWRAPPED
       NAME cpp-example-container-ssl
-      PREPEND_ENVIRONMENT "${cpp_test_env}"
+      ENVIRONMENT ${cpp_test_env}
+      PATH_PREPEND ${cpp_test_path}
+      PYTHONPATH_PREPEND "${Proton_SOURCE_DIR}/tests/py"
       WORKING_DIRECTORY ${ProtonCppExamples_SOURCE_DIR}
       COMMAND ${Python_EXECUTABLE} testme -v ContainerExampleSSLTest)
   endif()
diff --git a/tests/share/CMakeLists.txt b/tests/share/CMakeLists.txt
index 467581049..1d53053cb 100644
--- a/tests/share/CMakeLists.txt
+++ b/tests/share/CMakeLists.txt
@@ -17,11 +17,12 @@
 # under the License.
 #
 
-cmake_minimum_required(VERSION 3.16)
+cmake_minimum_required (VERSION 3.26)
 
 project(ProtonExamples)
 include(CTest)
 include("tests/RuntimeCheck.cmake")
+include("tests/PNAddTest.cmake")
 
 # find example sub-directories that contain "CMakeLists.txt" or "testme"
 set(ex_dir "${PROJECT_SOURCE_DIR}/examples")


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to