Tests/RunCMake/file: Enable READ_SYMLINK cases on Windows when possible

Probe the filesystem to enable them.

Co-authored-by: scivision@users.noreply.github.com
This commit is contained in:
Brad King
2026-04-17 10:46:51 -04:00
co-authored by
parent 1aa371b706
commit b5b72b0378
9 changed files with 47 additions and 24 deletions
@@ -0,0 +1 @@
^-- target: '[^']*/Tests/RunCMake/file/READ_SYMLINK-target.txt'$
@@ -0,0 +1 @@
include(${CMAKE_CURRENT_LIST_DIR}/READ_SYMLINK-common.cmake)
@@ -0,0 +1,5 @@
file(READ_SYMLINK "${link}" target)
if(CMAKE_HOST_WIN32)
string(REPLACE [[\]] [[/]] target "${target}")
endif()
message(STATUS "target: '${target}'")
@@ -1,6 +1,6 @@
^CMake Error at READ_SYMLINK-noexist\.cmake:[0-9]+ \(file\):
^CMake Error at [^
]*/Tests/RunCMake/file/READ_SYMLINK-noexist\.cmake:[0-9]+ \(file\):
file READ_SYMLINK requested of path that is not a symlink:
.*/Tests/RunCMake/file/READ_SYMLINK-noexist-build/rel\.sym
Call Stack \(most recent call first\):
CMakeLists\.txt:[0-9]+ \(include\)$
[^
]*/Tests/RunCMake/file/READ_SYMLINK-noexist-build/rel\.sym$
@@ -1,6 +1,6 @@
^CMake Error at READ_SYMLINK-notsymlink\.cmake:[0-9]+ \(file\):
^CMake Error at [^
]*Tests/RunCMake/file/READ_SYMLINK-notsymlink\.cmake:[0-9]+ \(file\):
file READ_SYMLINK requested of path that is not a symlink:
.*/Tests/RunCMake/file/READ_SYMLINK-notsymlink-build/rel\.sym
Call Stack \(most recent call first\):
CMakeLists\.txt:[0-9]+ \(include\)$
[^
]*/Tests/RunCMake/file/READ_SYMLINK-notsymlink-build/rel\.sym$
@@ -0,0 +1 @@
^-- target: 'READ_SYMLINK-target.txt'$
@@ -0,0 +1 @@
include(${CMAKE_CURRENT_LIST_DIR}/READ_SYMLINK-common.cmake)
-13
View File
@@ -1,13 +0,0 @@
execute_process(COMMAND
${CMAKE_COMMAND} -E create_symlink "test.txt" "${CMAKE_CURRENT_BINARY_DIR}/rel.sym")
file(READ_SYMLINK "${CMAKE_CURRENT_BINARY_DIR}/rel.sym" result)
if(NOT result STREQUAL "test.txt")
message(SEND_ERROR "Relative symlink is \"${result}\", should be \"test.txt\"")
endif()
execute_process(COMMAND
${CMAKE_COMMAND} -E create_symlink "${CMAKE_CURRENT_BINARY_DIR}/test.txt" "${CMAKE_CURRENT_BINARY_DIR}/abs.sym")
file(READ_SYMLINK "${CMAKE_CURRENT_BINARY_DIR}/abs.sym" result)
if(NOT result MATCHES "^.*/Tests/RunCMake/file/READ_SYMLINK-build/test\\.txt$")
message(SEND_ERROR "Absolute symlink is \"${result}\", should be \"*/Tests/RunCMake/file/READ_SYMLINK-build/test.txt\"")
endif()
+30 -3
View File
@@ -86,9 +86,6 @@ if(NOT WIN32
)
run_cmake(GLOB_RECURSE-cyclic-recursion)
run_cmake(INSTALL-SYMLINK)
run_cmake(READ_SYMLINK)
run_cmake(READ_SYMLINK-noexist)
run_cmake(READ_SYMLINK-notsymlink)
if(NOT CYGWIN)
run_cmake(INSTALL-FOLLOW_SYMLINK_CHAIN)
endif()
@@ -96,6 +93,36 @@ if(NOT WIN32
run_cmake(LOCK-symlink-no-truncate)
endif()
# Try creating symbolic links to read below.
# If this fails on the current filesystem, we'll skip those tests.
block(PROPAGATE READ_SYMLINK-link-rel READ_SYMLINK-link-abs)
set(READ_SYMLINK-dest-rel "READ_SYMLINK-target.txt")
set(READ_SYMLINK-dest-abs "${RunCMake_BINARY_DIR}/${READ_SYMLINK-dest-rel}")
file(WRITE "${READ_SYMLINK-dest-abs}" "")
foreach(link IN ITEMS rel abs)
set(READ_SYMLINK-link-${link} "${RunCMake_BINARY_DIR}/READ_SYMLINK-link-${link}.sym")
file(REMOVE "${READ_SYMLINK-link-${link}}")
execute_process(
COMMAND ${CMAKE_COMMAND} -E create_symlink "${READ_SYMLINK-dest-${link}}" "${READ_SYMLINK-link-${link}}"
OUTPUT_VARIABLE create_symlink_stdout
ERROR_VARIABLE create_symlink_stderr
RESULT_VARIABLE create_symlink_result
)
if(NOT create_symlink_result EQUAL 0 OR NOT EXISTS "${READ_SYMLINK-link-${link}}")
set(READ_SYMLINK-link-${link} "")
endif()
endforeach()
endblock()
if(READ_SYMLINK-link-rel)
run_cmake_script(READ_SYMLINK-rel "-Dlink=${READ_SYMLINK-link-rel}")
endif()
if(READ_SYMLINK-link-abs)
run_cmake_script(READ_SYMLINK-abs "-Dlink=${READ_SYMLINK-link-abs}")
endif()
run_cmake_script(READ_SYMLINK-noexist)
run_cmake_script(READ_SYMLINK-notsymlink)
run_cmake(REAL_PATH-non-existing)
run_cmake(REAL_PATH-existing)
run_cmake(REAL_PATH-unexpected-arg)