summaryrefslogtreecommitdiffstats
path: root/Tests
diff options
context:
space:
mode:
authorscivision <scivision@users.noreply.github.com>2023-01-23 15:47:54 (GMT)
committerBrad King <brad.king@kitware.com>2023-01-24 19:13:52 (GMT)
commita1dc38a5670939a8ce8dfd99282f86d47412a98a (patch)
tree12f0296080cf6c345901839bc6f134fbd01177d3 /Tests
parentadac7f3ca41ae38248f62ce48000390143762e99 (diff)
downloadCMake-a1dc38a5670939a8ce8dfd99282f86d47412a98a.zip
CMake-a1dc38a5670939a8ce8dfd99282f86d47412a98a.tar.gz
CMake-a1dc38a5670939a8ce8dfd99282f86d47412a98a.tar.bz2
Help: Document behavior of if(EXISTS,IS_DIRECTORY) for empty paths
Document and add explicit tests for empty string input: `if(EXISTS "")` and `if(IS_DIRECTORY "")` are always false. This avoids need for users to do extra checks due to CMake non-short-circuit logic as below: if("${p}") if(EXISTS "${p}")
Diffstat (limited to 'Tests')
-rw-r--r--Tests/RunCMake/if/IsDirectoryLong.cmake3
-rw-r--r--Tests/RunCMake/if/RunCMakeTest.cmake1
-rw-r--r--Tests/RunCMake/if/exists.cmake3
3 files changed, 7 insertions, 0 deletions
diff --git a/Tests/RunCMake/if/IsDirectoryLong.cmake b/Tests/RunCMake/if/IsDirectoryLong.cmake
index e6939ac..41f1818 100644
--- a/Tests/RunCMake/if/IsDirectoryLong.cmake
+++ b/Tests/RunCMake/if/IsDirectoryLong.cmake
@@ -8,3 +8,6 @@ if(IS_DIRECTORY "${d}/")
else()
message(STATUS "Directory path with length ${dl} correctly does not exist.")
endif()
+if(IS_DIRECTORY "")
+ message(FATAL_ERROR "IS_DIRECTORY \"\" should not exist")
+endif()
diff --git a/Tests/RunCMake/if/RunCMakeTest.cmake b/Tests/RunCMake/if/RunCMakeTest.cmake
index de9cb57..efee116 100644
--- a/Tests/RunCMake/if/RunCMakeTest.cmake
+++ b/Tests/RunCMake/if/RunCMakeTest.cmake
@@ -1,6 +1,7 @@
include(RunCMake)
run_cmake(InvalidArgument1)
+run_cmake(exists)
run_cmake(IsDirectory)
run_cmake(IsDirectoryLong)
run_cmake(duplicate-deep-else)
diff --git a/Tests/RunCMake/if/exists.cmake b/Tests/RunCMake/if/exists.cmake
new file mode 100644
index 0000000..2e5c0ee
--- /dev/null
+++ b/Tests/RunCMake/if/exists.cmake
@@ -0,0 +1,3 @@
+if(EXISTS "")
+ message(FATAL_ERROR "EXISTS \"\" should not exist")
+endif()