summaryrefslogtreecommitdiffstats
path: root/Tests
diff options
context:
space:
mode:
authorFeRD (Frank Dana) <ferdnyc@gmail.com>2024-08-21 18:33:52 (GMT)
committerBrad King <brad.king@kitware.com>2024-08-26 13:55:57 (GMT)
commitb0be1bd9ca720296261fec4733435d69f54e5130 (patch)
treee6c097b67bfdc5de923e5f9c6ce5d7c5acc78d6b /Tests
parent8dcb35911ca3570cc7fcb6820def8d86b5cd76cb (diff)
downloadCMake-b0be1bd9ca720296261fec4733435d69f54e5130.zip
CMake-b0be1bd9ca720296261fec4733435d69f54e5130.tar.gz
CMake-b0be1bd9ca720296261fec4733435d69f54e5130.tar.bz2
cmake_path: Fix 'GET "foo/.." STEM' result
`cmake_path(GET "foo/.." STEM out)` is supposed to set `out` to `".."`, the entire `cmake_path(GET "foo/.." FILENAME)` result. However, the `GetNarrowStem()` logic in `cmCMakePath` was lacking the `.` and `..` special-casing logic present in other methods. As a result, it would erroneously trim the second `.` off of a stem of `..` and return only `.`. This caused the result of `cmake_path(GET "foo/.." STEM)` to be `"."`. Making the standard empty-or-.-or-.. checks and bailing out early fixes the result of `cmCMakePaths{".."}.GetNarrowStem()`. Fixes: #26235
Diffstat (limited to 'Tests')
-rw-r--r--Tests/RunCMake/cmake_path/GET.cmake67
1 files changed, 67 insertions, 0 deletions
diff --git a/Tests/RunCMake/cmake_path/GET.cmake b/Tests/RunCMake/cmake_path/GET.cmake
index 463bc47..b0bda98 100644
--- a/Tests/RunCMake/cmake_path/GET.cmake
+++ b/Tests/RunCMake/cmake_path/GET.cmake
@@ -245,4 +245,71 @@ if (NOT output STREQUAL ".file")
list (APPEND errors "STEM returns bad data: ${output}")
endif()
+##################################################
+## tests for subcommands' handling of "." and ".."
+##################################################
+if (WIN32)
+ set (dot "C:/aa/bb/.")
+ set (dotdot "C:/ee/ff/..")
+else()
+ set (dot "/aa/bb/.")
+ set (dotdot "/ee/ff/..")
+endif()
+
+cmake_path(GET dot FILENAME dot_out)
+cmake_path(GET dotdot FILENAME dotdot_out)
+
+if (NOT dot_out STREQUAL ".")
+ list(APPEND errors "FILENAME returns bad data for '<path>/.': ${dot_out}")
+endif()
+if (NOT dotdot_out STREQUAL "..")
+ list(APPEND errors "FILENAME returns bad data for '<path>/..': ${dotdot_out}")
+endif()
+
+cmake_path(GET dot STEM dot_out)
+cmake_path(GET dotdot STEM dotdot_out)
+
+if (NOT dot_out STREQUAL ".")
+ list(APPEND errors "STEM returns bad data for '<path>/.': ${dot_out}")
+endif()
+if (NOT dotdot_out STREQUAL "..")
+ list(APPEND errors "STEM returns bad data for '<path>/..': ${dotdot_out}")
+endif()
+
+cmake_path(GET dot STEM LAST_ONLY dot_out)
+cmake_path(GET dotdot STEM LAST_ONLY dotdot_out)
+
+if (NOT dot_out STREQUAL ".")
+ list(APPEND errors
+ "STEM LAST_ONLY returns bad data for '<path>/.': ${dot_out}")
+endif()
+if (NOT dotdot_out STREQUAL "..")
+ list(APPEND errors
+ "STEM LAST_ONLY returns bad data for '<path>/..': ${dotdot_out}")
+endif()
+
+cmake_path(GET dot EXTENSION dot_out)
+cmake_path(GET dotdot EXTENSION dotdot_out)
+
+if (NOT dot_out STREQUAL "")
+ list(APPEND errors
+ "EXTENSION returns bad data for '<path>/.': ${dot_out}")
+endif()
+if (NOT dotdot_out STREQUAL "")
+ list(APPEND errors
+ "EXTENSION returns bad data for '<path>/..': ${dotdot_out}")
+endif()
+
+cmake_path(GET dot EXTENSION LAST_ONLY dot_out)
+cmake_path(GET dotdot EXTENSION LAST_ONLY dotdot_out)
+
+if (NOT dot_out STREQUAL "")
+ list(APPEND errors
+ "EXTENSION LAST_ONLY returns bad data for '<path>/.': ${dot_out}")
+endif()
+if (NOT dotdot_out STREQUAL "")
+ list(APPEND errors
+ "EXTENSION LAST_ONLY returns bad data for '<path>/..': ${dotdot_out}")
+endif()
+
check_errors (GET ${errors})