Tests: Fix regex matching to handle paths with special characters

Use `string(REGEX QUOTE)` for `MATCHES` with constructed patterns.

Fixes: #27234
This commit is contained in:
Timo Röhling
2025-09-17 22:54:39 +02:00
committed by Brad King
parent d94d79a909
commit 798cc7010c
5 changed files with 10 additions and 5 deletions

View File

@@ -2,7 +2,8 @@ file(READ "${RunCMake_TEST_BINARY_DIR}/out.txt" content)
unset(RunCMake_TEST_FAILED)
if (NOT content MATCHES "(INCLUDES1:${RunCMake_TEST_SOURCE_DIR}/include)")
string(REGEX QUOTE RunCMake_TEST_SOURCE_DIR_regex "${RunCMake_TEST_SOURCE_DIR}")
if (NOT content MATCHES "(INCLUDES1:${RunCMake_TEST_SOURCE_DIR_regex}/include)")
string(APPEND RunCMake_TEST_FAILED "wrong content for INCLUDES1: \"${CMAKE_MATCH_1}\"\n")
endif()

View File

@@ -1,10 +1,11 @@
include(${RunCMake_SOURCE_DIR}/TARGETS-FILE_RPATH_CHANGE-check-common.cmake)
skip_without_rpath_change_rule()
string(APPEND prefix "${wsnl}" [[FILE "[^"]*/]])
string(REGEX QUOTE RunCMake_BINARY_DIR_regex "${RunCMake_BINARY_DIR}")
set(target "exe1")
string(CONCAT regex "${prefix}${target}\"${wsnl}"
[[OLD_RPATH "]] "${RunCMake_BINARY_DIR}")
[[OLD_RPATH "]] "${RunCMake_BINARY_DIR_regex}")
check()
if("x${CMAKE_SHARED_LIBRARY_RPATH_ORIGIN_TOKEN}" STREQUAL "x\$ORIGIN")

View File

@@ -12,7 +12,8 @@ target_include_directories(main AFTER PRIVATE "${after_include_dir}")
get_target_property(actual_include_dirs main INCLUDE_DIRECTORIES)
set(desired_include_dirs "${include_dir}" "${after_include_dir}")
string(REGEX QUOTE desired_include_dirs_regex "${desired_include_dirs}")
if (NOT "${actual_include_dirs}" MATCHES "${desired_include_dirs}")
if (NOT "${actual_include_dirs}" MATCHES "^${desired_include_dirs_regex}$")
message(SEND_ERROR "include after does not work")
endif()

View File

@@ -12,7 +12,8 @@ target_include_directories(main BEFORE PRIVATE "${before_include_dir}")
get_target_property(actual_include_dirs main INCLUDE_DIRECTORIES)
set(desired_include_dirs "${before_include_dir}" "${include_dir}")
string(REGEX QUOTE desired_include_dirs_regex "${desired_include_dirs}")
if (NOT "${actual_include_dirs}" MATCHES "${desired_include_dirs}")
if (NOT "${actual_include_dirs}" MATCHES "^${desired_include_dirs_regex}$")
message(SEND_ERROR "include before does not work")
endif()

View File

@@ -12,7 +12,8 @@ target_include_directories(main AFTER PRIVATE "${default_include_dir}")
get_target_property(actual_include_dirs main INCLUDE_DIRECTORIES)
set(desired_include_dirs "${include_dir}" "${default_include_dir}")
string(REGEX QUOTE desired_include_dirs_regex "${desired_include_dirs}")
if (NOT "${actual_include_dirs}" MATCHES "${desired_include_dirs}")
if (NOT "${actual_include_dirs}" MATCHES "^${desired_include_dirs_regex}$")
message(SEND_ERROR "include default does not work")
endif()