summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/file
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-03-04 13:13:16 (GMT)
committerBrad King <brad.king@kitware.com>2021-03-04 13:49:48 (GMT)
commit9bf40d8027ec9fb91ad995919f6db673c15558dc (patch)
tree2bac35f6c7d1be1e0788724ca86d1a3d9e5c43e2 /Tests/RunCMake/file
parent3600c6cd8c09e501faa06be5f98465e994d51569 (diff)
downloadCMake-9bf40d8027ec9fb91ad995919f6db673c15558dc.zip
CMake-9bf40d8027ec9fb91ad995919f6db673c15558dc.tar.gz
CMake-9bf40d8027ec9fb91ad995919f6db673c15558dc.tar.bz2
file(RENAME): Add option to not replace existing path
Add a `NO_REPLACE` option that prevents overwriting `<newname>` if it exists.
Diffstat (limited to 'Tests/RunCMake/file')
-rw-r--r--Tests/RunCMake/file/RENAME-file-NO_REPLACE-capture-stdout.txt1
-rw-r--r--Tests/RunCMake/file/RENAME-file-NO_REPLACE-capture.cmake9
-rw-r--r--Tests/RunCMake/file/RENAME-file-NO_REPLACE-fail-result.txt1
-rw-r--r--Tests/RunCMake/file/RENAME-file-NO_REPLACE-fail-stderr.txt13
-rw-r--r--Tests/RunCMake/file/RENAME-file-NO_REPLACE-fail.cmake5
-rw-r--r--Tests/RunCMake/file/RENAME-file-replace.cmake9
-rw-r--r--Tests/RunCMake/file/RunCMakeTest.cmake3
7 files changed, 41 insertions, 0 deletions
diff --git a/Tests/RunCMake/file/RENAME-file-NO_REPLACE-capture-stdout.txt b/Tests/RunCMake/file/RENAME-file-NO_REPLACE-capture-stdout.txt
new file mode 100644
index 0000000..a116330
--- /dev/null
+++ b/Tests/RunCMake/file/RENAME-file-NO_REPLACE-capture-stdout.txt
@@ -0,0 +1 @@
+^-- file\(RENAME\) failed with result: NO_REPLACE$
diff --git a/Tests/RunCMake/file/RENAME-file-NO_REPLACE-capture.cmake b/Tests/RunCMake/file/RENAME-file-NO_REPLACE-capture.cmake
new file mode 100644
index 0000000..1ff4178
--- /dev/null
+++ b/Tests/RunCMake/file/RENAME-file-NO_REPLACE-capture.cmake
@@ -0,0 +1,9 @@
+set(oldname "${CMAKE_CURRENT_BINARY_DIR}/input")
+set(newname "${CMAKE_CURRENT_BINARY_DIR}/output")
+file(WRITE "${oldname}" "a")
+file(WRITE "${newname}" "b")
+file(RENAME "${oldname}" "${newname}" NO_REPLACE RESULT result)
+message(STATUS "file(RENAME) failed with result: ${result}")
+if(NOT EXISTS "${oldname}")
+ message(FATAL_ERROR "The old name does not still exist:\n ${oldname}")
+endif()
diff --git a/Tests/RunCMake/file/RENAME-file-NO_REPLACE-fail-result.txt b/Tests/RunCMake/file/RENAME-file-NO_REPLACE-fail-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/file/RENAME-file-NO_REPLACE-fail-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/file/RENAME-file-NO_REPLACE-fail-stderr.txt b/Tests/RunCMake/file/RENAME-file-NO_REPLACE-fail-stderr.txt
new file mode 100644
index 0000000..dd7294c
--- /dev/null
+++ b/Tests/RunCMake/file/RENAME-file-NO_REPLACE-fail-stderr.txt
@@ -0,0 +1,13 @@
+^CMake Error at [^
+]*/Tests/RunCMake/file/RENAME-file-NO_REPLACE-fail.cmake:[0-9] \(file\):
+ file RENAME failed to rename
+
+ [^
+]*/Tests/RunCMake/file/RENAME-file-NO_REPLACE-fail-build/input
+
+ to
+
+ [^
+]*/Tests/RunCMake/file/RENAME-file-NO_REPLACE-fail-build/output
+
+ because: path not replaced$
diff --git a/Tests/RunCMake/file/RENAME-file-NO_REPLACE-fail.cmake b/Tests/RunCMake/file/RENAME-file-NO_REPLACE-fail.cmake
new file mode 100644
index 0000000..c05dd63
--- /dev/null
+++ b/Tests/RunCMake/file/RENAME-file-NO_REPLACE-fail.cmake
@@ -0,0 +1,5 @@
+set(oldname "${CMAKE_CURRENT_BINARY_DIR}/input")
+set(newname "${CMAKE_CURRENT_BINARY_DIR}/output")
+file(WRITE "${oldname}" "a")
+file(WRITE "${newname}" "b")
+file(RENAME "${oldname}" "${newname}" NO_REPLACE)
diff --git a/Tests/RunCMake/file/RENAME-file-replace.cmake b/Tests/RunCMake/file/RENAME-file-replace.cmake
new file mode 100644
index 0000000..efbfaed
--- /dev/null
+++ b/Tests/RunCMake/file/RENAME-file-replace.cmake
@@ -0,0 +1,9 @@
+set(oldname "${CMAKE_CURRENT_BINARY_DIR}/input")
+set(newname "${CMAKE_CURRENT_BINARY_DIR}/output")
+file(WRITE "${oldname}" "a")
+file(WRITE "${newname}" "b")
+file(RENAME "${oldname}" "${newname}")
+file(READ "${newname}" new)
+if(NOT "${new}" STREQUAL "a")
+ message(FATAL_ERROR "New name:\n ${newname}\ndoes not contain expected content 'a'.")
+endif()
diff --git a/Tests/RunCMake/file/RunCMakeTest.cmake b/Tests/RunCMake/file/RunCMakeTest.cmake
index d9e4cfe..f74832c 100644
--- a/Tests/RunCMake/file/RunCMakeTest.cmake
+++ b/Tests/RunCMake/file/RunCMakeTest.cmake
@@ -50,9 +50,12 @@ run_cmake(SIZE-error-does-not-exist)
run_cmake(REMOVE-empty)
+run_cmake_script(RENAME-file-replace)
run_cmake_script(RENAME-file-to-file)
run_cmake_script(RENAME-file-to-dir-capture)
run_cmake_script(RENAME-file-to-dir-fail)
+run_cmake_script(RENAME-file-NO_REPLACE-capture)
+run_cmake_script(RENAME-file-NO_REPLACE-fail)
run_cmake_script(RENAME-arg-missing)
run_cmake_script(RENAME-arg-unknown)