Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

Add optional argument to catch_discover_tests to set DYLD_FRAMEWORK_PATH (#2880)

* Added optional argument to catch_discover_tests to set the DYLD_FRAMEWORK_PATH environment variable on Apple platforms.
Commit
85b7f3d6abbf11cfde34e274180a5539d2ac8bfe
Author
Andy Phillips ·
Committer
GitHub
Parents
7af96bbb2269

Files · Download .tar.gz

Changes

 extras/Catch.cmake         | 20 +++++++++++++++-----
 extras/CatchAddTests.cmake | 16 +++++++++++++++-
 2 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/extras/Catch.cmake b/extras/Catch.cmake
index 8f30688c..e080665b 100644
--- a/extras/Catch.cmake
+++ b/extras/Catch.cmake
@@ -124,6 +124,13 @@ same as the Catch name; see also ``TEST_PREFIX`` and ``TEST_SUFFIX``.
     test executable and when the tests are executed themselves. This requires
     cmake/ctest >= 3.22.
 
+  ``DL_FRAMEWORK_PATHS path...``
+    Specifies paths that need to be set for the dynamic linker to find libraries
+    packaged as frameworks on Apple platforms when running the test executable
+    (DYLD_FRAMEWORK_PATH). These paths will both be set when retrieving the list
+    of test cases from the test executable and when the tests are executed themselves.
+    This requires cmake/ctest >= 3.22.
+
   `DISCOVERY_MODE mode``
     Provides control over when ``catch_discover_tests`` performs test discovery.
     By default, ``POST_BUILD`` sets up a post-build command to perform test discovery
@@ -146,7 +153,7 @@ function(catch_discover_tests TARGET)
     ""
     ""
     "TEST_PREFIX;TEST_SUFFIX;WORKING_DIRECTORY;TEST_LIST;REPORTER;OUTPUT_DIR;OUTPUT_PREFIX;OUTPUT_SUFFIX;DISCOVERY_MODE"
-    "TEST_SPEC;EXTRA_ARGS;PROPERTIES;DL_PATHS"
+    "TEST_SPEC;EXTRA_ARGS;PROPERTIES;DL_PATHS;DL_FRAMEWORK_PATHS"
     ${ARGN}
   )
 
@@ -156,10 +163,11 @@ function(catch_discover_tests TARGET)
   if(NOT _TEST_LIST)
     set(_TEST_LIST ${TARGET}_TESTS)
   endif()
-  if (_DL_PATHS)
-    if(${CMAKE_VERSION} VERSION_LESS "3.22.0")
-        message(FATAL_ERROR "The DL_PATHS option requires at least cmake 3.22")
-    endif()
+  if(_DL_PATHS AND ${CMAKE_VERSION} VERSION_LESS "3.22.0")
+    message(FATAL_ERROR "The DL_PATHS option requires at least cmake 3.22")
+  endif()
+  if(_DL_FRAMEWORK_PATHS AND ${CMAKE_VERSION} VERSION_LESS "3.22.0")
+    message(FATAL_ERROR "The DL_FRAMEWORK_PATHS option requires at least cmake 3.22")
   endif()
   if(NOT _DISCOVERY_MODE)
     if(NOT CMAKE_CATCH_DISCOVER_TESTS_DISCOVERY_MODE)
@@ -205,6 +213,7 @@ function(catch_discover_tests TARGET)
               -D "TEST_OUTPUT_PREFIX=${_OUTPUT_PREFIX}"
               -D "TEST_OUTPUT_SUFFIX=${_OUTPUT_SUFFIX}"
               -D "TEST_DL_PATHS=${_DL_PATHS}"
+              -D "TEST_DL_FRAMEWORK_PATHS=${_DL_FRAMEWORK_PATHS}"
               -D "CTEST_FILE=${ctest_tests_file}"
               -P "${_CATCH_DISCOVER_TESTS_SCRIPT}"
       VERBATIM
@@ -250,6 +259,7 @@ function(catch_discover_tests TARGET)
       "      TEST_OUTPUT_SUFFIX"     " [==[" "${_OUTPUT_SUFFIX}"          "]==]"   "\n"
       "      CTEST_FILE"             " [==[" "${ctest_tests_file}"        "]==]"   "\n"
       "      TEST_DL_PATHS"          " [==[" "${_DL_PATHS}"               "]==]"   "\n"
+      "      TEST_DL_FRAMEWORK_PATHS" " [==[" "${_DL_FRAMEWORK_PATHS}"     "]==]"   "\n"
       "      CTEST_FILE"             " [==[" "${CTEST_FILE}"              "]==]"   "\n"
       "    )"                                                                      "\n"
       "  endif()"                                                                  "\n"
diff --git a/extras/CatchAddTests.cmake b/extras/CatchAddTests.cmake
index a0731941..604e097a 100644
--- a/extras/CatchAddTests.cmake
+++ b/extras/CatchAddTests.cmake
@@ -22,7 +22,7 @@ function(catch_discover_tests_impl)
     ""
     ""
     "TEST_EXECUTABLE;TEST_WORKING_DIR;TEST_OUTPUT_DIR;TEST_OUTPUT_PREFIX;TEST_OUTPUT_SUFFIX;TEST_PREFIX;TEST_REPORTER;TEST_SPEC;TEST_SUFFIX;TEST_LIST;CTEST_FILE"
-    "TEST_EXTRA_ARGS;TEST_PROPERTIES;TEST_EXECUTOR;TEST_DL_PATHS"
+    "TEST_EXTRA_ARGS;TEST_PROPERTIES;TEST_EXECUTOR;TEST_DL_PATHS;TEST_DL_FRAMEWORK_PATHS"
     ${ARGN}
   )
 
@@ -36,6 +36,7 @@ function(catch_discover_tests_impl)
   set(output_prefix ${_TEST_OUTPUT_PREFIX})
   set(output_suffix ${_TEST_OUTPUT_SUFFIX})
   set(dl_paths ${_TEST_DL_PATHS})
+  set(dl_framework_paths ${_TEST_DL_FRAMEWORK_PATHS})
   set(script)
   set(suite)
   set(tests)
@@ -60,6 +61,11 @@ function(catch_discover_tests_impl)
     set(ENV{${dl_paths_variable_name}} "${paths}")
   endif()
 
+  if(APPLE AND dl_framework_paths)
+    cmake_path(CONVERT "${dl_framework_paths}" TO_NATIVE_PATH_LIST paths)
+    set(ENV{DYLD_FRAMEWORK_PATH} "${paths}")
+  endif()
+
   execute_process(
     COMMAND ${_TEST_EXECUTOR} "${_TEST_EXECUTABLE}" ${spec} --list-tests --verbosity quiet
     OUTPUT_VARIABLE output
@@ -121,6 +127,13 @@ function(catch_discover_tests_impl)
     endforeach()
   endif()
 
+  if(APPLE AND dl_framework_paths)
+    foreach(path ${dl_framework_paths})
+      cmake_path(NATIVE_PATH path native_path)
+      list(APPEND environment_modifications "DYLD_FRAMEWORK_PATH=path_list_prepend:${native_path}")
+    endforeach()
+  endif()
+
   # Parse output
   foreach(line ${output})
     set(test "${line}")
@@ -187,6 +200,7 @@ if(CMAKE_SCRIPT_MODE_FILE)
     TEST_OUTPUT_PREFIX ${TEST_OUTPUT_PREFIX}
     TEST_OUTPUT_SUFFIX ${TEST_OUTPUT_SUFFIX}
     TEST_DL_PATHS ${TEST_DL_PATHS}
+    TEST_DL_FRAMEWORK_PATHS ${TEST_DL_FRAMEWORK_PATHS}
     CTEST_FILE ${CTEST_FILE}
   )
 endif()