diff options
-rw-r--r-- | Source/cmCMakePath.cxx | 12 | ||||
-rw-r--r-- | Tests/RunCMake/cmake_path/GET.cmake | 67 |
2 files changed, 74 insertions, 5 deletions
diff --git a/Source/cmCMakePath.cxx b/Source/cmCMakePath.cxx index 5080f58..be5c74a 100644 --- a/Source/cmCMakePath.cxx +++ b/Source/cmCMakePath.cxx @@ -57,11 +57,13 @@ cmCMakePath cmCMakePath::GetWideExtension() const cmCMakePath cmCMakePath::GetNarrowStem() const { auto stem = this->Path.stem().string(); - if (!stem.empty()) { - auto pos = stem.find('.', stem[0] == '.' ? 1 : 0); - if (pos != std::string::npos) { - return stem.substr(0, pos); - } + if (stem.empty() || stem == "." || stem == "..") { + return stem; + } + + auto pos = stem.find('.', stem[0] == '.' ? 1 : 0); + if (pos != std::string::npos) { + return stem.substr(0, pos); } return stem; } 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}) |