summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/file
diff options
context:
space:
mode:
authorRuslan Baratov <ruslan_baratov@yahoo.com>2014-11-25 22:49:25 (GMT)
committerBrad King <brad.king@kitware.com>2014-12-03 14:47:44 (GMT)
commite6db4c5a4ede8039ed525e3facebd7e0eb7ec1b7 (patch)
treef5e6a3dce7b89725f9fa4e5fcafd040114a85466 /Tests/RunCMake/file
parent05d6531c7a8ecfad513a0e76b44b273b70fa919b (diff)
downloadCMake-e6db4c5a4ede8039ed525e3facebd7e0eb7ec1b7.zip
CMake-e6db4c5a4ede8039ed525e3facebd7e0eb7ec1b7.tar.gz
CMake-e6db4c5a4ede8039ed525e3facebd7e0eb7ec1b7.tar.bz2
file: Add LOCK subcommand to do file and directory locking
Provide options to fail without blocking or to block up to a timeout. Provide options to specify the scope containing the lock so it can be released automatically at the end of a function, file, or process. Extend the RunCMake.file test with cases covering the file(LOCK) command usage and error cases.
Diffstat (limited to 'Tests/RunCMake/file')
-rw-r--r--Tests/RunCMake/file/LOCK-error-file-create-fail-result.txt1
-rw-r--r--Tests/RunCMake/file/LOCK-error-file-create-fail-stderr.txt8
-rw-r--r--Tests/RunCMake/file/LOCK-error-file-create-fail.cmake3
-rw-r--r--Tests/RunCMake/file/LOCK-error-guard-incorrect-result.txt1
-rw-r--r--Tests/RunCMake/file/LOCK-error-guard-incorrect-stderr.txt6
-rw-r--r--Tests/RunCMake/file/LOCK-error-guard-incorrect.cmake1
-rw-r--r--Tests/RunCMake/file/LOCK-error-incorrect-timeout-result.txt1
-rw-r--r--Tests/RunCMake/file/LOCK-error-incorrect-timeout-stderr.txt4
-rw-r--r--Tests/RunCMake/file/LOCK-error-incorrect-timeout-trail-result.txt1
-rw-r--r--Tests/RunCMake/file/LOCK-error-incorrect-timeout-trail-stderr.txt4
-rw-r--r--Tests/RunCMake/file/LOCK-error-incorrect-timeout-trail.cmake1
-rw-r--r--Tests/RunCMake/file/LOCK-error-incorrect-timeout.cmake1
-rw-r--r--Tests/RunCMake/file/LOCK-error-lock-fail-result.txt1
-rw-r--r--Tests/RunCMake/file/LOCK-error-lock-fail-stderr.txt6
-rw-r--r--Tests/RunCMake/file/LOCK-error-lock-fail.cmake6
-rw-r--r--Tests/RunCMake/file/LOCK-error-negative-timeout-result.txt1
-rw-r--r--Tests/RunCMake/file/LOCK-error-negative-timeout-stderr.txt4
-rw-r--r--Tests/RunCMake/file/LOCK-error-negative-timeout.cmake1
-rw-r--r--Tests/RunCMake/file/LOCK-error-no-function-result.txt1
-rw-r--r--Tests/RunCMake/file/LOCK-error-no-function-stderr.txt8
-rw-r--r--Tests/RunCMake/file/LOCK-error-no-function.cmake1
-rw-r--r--Tests/RunCMake/file/LOCK-error-no-guard-result.txt1
-rw-r--r--Tests/RunCMake/file/LOCK-error-no-guard-stderr.txt4
-rw-r--r--Tests/RunCMake/file/LOCK-error-no-guard.cmake1
-rw-r--r--Tests/RunCMake/file/LOCK-error-no-path-result.txt1
-rw-r--r--Tests/RunCMake/file/LOCK-error-no-path-stderr.txt4
-rw-r--r--Tests/RunCMake/file/LOCK-error-no-path.cmake1
-rw-r--r--Tests/RunCMake/file/LOCK-error-no-result-variable-result.txt1
-rw-r--r--Tests/RunCMake/file/LOCK-error-no-result-variable-stderr.txt4
-rw-r--r--Tests/RunCMake/file/LOCK-error-no-result-variable.cmake1
-rw-r--r--Tests/RunCMake/file/LOCK-error-no-timeout-result.txt1
-rw-r--r--Tests/RunCMake/file/LOCK-error-no-timeout-stderr.txt4
-rw-r--r--Tests/RunCMake/file/LOCK-error-no-timeout.cmake1
-rw-r--r--Tests/RunCMake/file/LOCK-error-timeout-result.txt1
-rw-r--r--Tests/RunCMake/file/LOCK-error-timeout-stderr.txt12
-rw-r--r--Tests/RunCMake/file/LOCK-error-timeout-stdout.txt1
-rw-r--r--Tests/RunCMake/file/LOCK-error-timeout.cmake17
-rw-r--r--Tests/RunCMake/file/LOCK-error-unknown-option-result.txt1
-rw-r--r--Tests/RunCMake/file/LOCK-error-unknown-option-stderr.txt6
-rw-r--r--Tests/RunCMake/file/LOCK-error-unknown-option.cmake1
-rw-r--r--Tests/RunCMake/file/LOCK-stdout.txt11
-rw-r--r--Tests/RunCMake/file/LOCK.cmake40
-rw-r--r--Tests/RunCMake/file/RunCMakeTest.cmake14
-rw-r--r--Tests/RunCMake/file/subdir_test_unlock/CMakeLists.txt2
-rw-r--r--Tests/RunCMake/file/timeout-script.cmake5
45 files changed, 196 insertions, 0 deletions
diff --git a/Tests/RunCMake/file/LOCK-error-file-create-fail-result.txt b/Tests/RunCMake/file/LOCK-error-file-create-fail-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-error-file-create-fail-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/file/LOCK-error-file-create-fail-stderr.txt b/Tests/RunCMake/file/LOCK-error-file-create-fail-stderr.txt
new file mode 100644
index 0000000..72b7fe0
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-error-file-create-fail-stderr.txt
@@ -0,0 +1,8 @@
+CMake Error at LOCK-error-file-create-fail\.cmake:[0-9]+ \(file\):
+ file
+
+ ".*"
+
+ creation failed \(check permissions\)\.
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/file/LOCK-error-file-create-fail.cmake b/Tests/RunCMake/file/LOCK-error-file-create-fail.cmake
new file mode 100644
index 0000000..4868cfe
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-error-file-create-fail.cmake
@@ -0,0 +1,3 @@
+set(tmp "${CMAKE_CURRENT_BINARY_DIR}/temp-directory")
+file(MAKE_DIRECTORY "${tmp}")
+file(LOCK "${tmp}")
diff --git a/Tests/RunCMake/file/LOCK-error-guard-incorrect-result.txt b/Tests/RunCMake/file/LOCK-error-guard-incorrect-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-error-guard-incorrect-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/file/LOCK-error-guard-incorrect-stderr.txt b/Tests/RunCMake/file/LOCK-error-guard-incorrect-stderr.txt
new file mode 100644
index 0000000..85136b4
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-error-guard-incorrect-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at LOCK-error-guard-incorrect\.cmake:[0-9]+ \(file\):
+ expected FUNCTION, FILE or PROCESS after GUARD, but got:
+
+ "FUNCTIO"\.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/file/LOCK-error-guard-incorrect.cmake b/Tests/RunCMake/file/LOCK-error-guard-incorrect.cmake
new file mode 100644
index 0000000..51daa7c
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-error-guard-incorrect.cmake
@@ -0,0 +1 @@
+file(LOCK "${CMAKE_CURRENT_BINARY_DIR}/file-to-lock" GUARD FUNCTIO)
diff --git a/Tests/RunCMake/file/LOCK-error-incorrect-timeout-result.txt b/Tests/RunCMake/file/LOCK-error-incorrect-timeout-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-error-incorrect-timeout-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/file/LOCK-error-incorrect-timeout-stderr.txt b/Tests/RunCMake/file/LOCK-error-incorrect-timeout-stderr.txt
new file mode 100644
index 0000000..c6ae1e0
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-error-incorrect-timeout-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at LOCK-error-incorrect-timeout\.cmake:[0-9]+ \(file\):
+ TIMEOUT value "qwerty" is not an unsigned integer\.
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/file/LOCK-error-incorrect-timeout-trail-result.txt b/Tests/RunCMake/file/LOCK-error-incorrect-timeout-trail-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-error-incorrect-timeout-trail-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/file/LOCK-error-incorrect-timeout-trail-stderr.txt b/Tests/RunCMake/file/LOCK-error-incorrect-timeout-trail-stderr.txt
new file mode 100644
index 0000000..6ea2507
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-error-incorrect-timeout-trail-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at LOCK-error-incorrect-timeout-trail\.cmake:[0-9]+ \(file\):
+ TIMEOUT value "123xyz" is not an unsigned integer\.
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/file/LOCK-error-incorrect-timeout-trail.cmake b/Tests/RunCMake/file/LOCK-error-incorrect-timeout-trail.cmake
new file mode 100644
index 0000000..c4f1b75
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-error-incorrect-timeout-trail.cmake
@@ -0,0 +1 @@
+file(LOCK "${CMAKE_CURRENT_BINARY_DIR}/file-to-lock" TIMEOUT 123xyz)
diff --git a/Tests/RunCMake/file/LOCK-error-incorrect-timeout.cmake b/Tests/RunCMake/file/LOCK-error-incorrect-timeout.cmake
new file mode 100644
index 0000000..d882467
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-error-incorrect-timeout.cmake
@@ -0,0 +1 @@
+file(LOCK "${CMAKE_CURRENT_BINARY_DIR}/file-to-lock" TIMEOUT qwerty)
diff --git a/Tests/RunCMake/file/LOCK-error-lock-fail-result.txt b/Tests/RunCMake/file/LOCK-error-lock-fail-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-error-lock-fail-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/file/LOCK-error-lock-fail-stderr.txt b/Tests/RunCMake/file/LOCK-error-lock-fail-stderr.txt
new file mode 100644
index 0000000..a7b0447
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-error-lock-fail-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at LOCK-error-lock-fail.cmake:[0-9]+ \(file\):
+ directory
+
+ ".*"
+
+ creation failed \(check permissions\)\.
diff --git a/Tests/RunCMake/file/LOCK-error-lock-fail.cmake b/Tests/RunCMake/file/LOCK-error-lock-fail.cmake
new file mode 100644
index 0000000..aa7f663
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-error-lock-fail.cmake
@@ -0,0 +1,6 @@
+set(lfile "${CMAKE_CURRENT_BINARY_DIR}/file-to-lock")
+FILE(WRITE "${lfile}" "")
+
+# Try to lock file '${lfile}/cmake.lock'. Since `lfile` is not a directory
+# expected that operation will fail.
+file(LOCK "${lfile}" DIRECTORY)
diff --git a/Tests/RunCMake/file/LOCK-error-negative-timeout-result.txt b/Tests/RunCMake/file/LOCK-error-negative-timeout-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-error-negative-timeout-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/file/LOCK-error-negative-timeout-stderr.txt b/Tests/RunCMake/file/LOCK-error-negative-timeout-stderr.txt
new file mode 100644
index 0000000..0d159c1
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-error-negative-timeout-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at LOCK-error-negative-timeout\.cmake:[0-9]+ \(file\):
+ TIMEOUT value "-2" is not an unsigned integer\.
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/file/LOCK-error-negative-timeout.cmake b/Tests/RunCMake/file/LOCK-error-negative-timeout.cmake
new file mode 100644
index 0000000..6a0f190
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-error-negative-timeout.cmake
@@ -0,0 +1 @@
+file(LOCK "${CMAKE_CURRENT_BINARY_DIR}/file-to-lock" TIMEOUT -2)
diff --git a/Tests/RunCMake/file/LOCK-error-no-function-result.txt b/Tests/RunCMake/file/LOCK-error-no-function-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-error-no-function-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/file/LOCK-error-no-function-stderr.txt b/Tests/RunCMake/file/LOCK-error-no-function-stderr.txt
new file mode 100644
index 0000000..51ed12d
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-error-no-function-stderr.txt
@@ -0,0 +1,8 @@
+CMake Error at LOCK-error-no-function\.cmake:[0-9]+ \(file\):
+ error locking file
+
+ ".*"
+
+ 'GUARD FUNCTION' not used in function definition\.
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/file/LOCK-error-no-function.cmake b/Tests/RunCMake/file/LOCK-error-no-function.cmake
new file mode 100644
index 0000000..1b8b06a
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-error-no-function.cmake
@@ -0,0 +1 @@
+file(LOCK "${CMAKE_CURRENT_BINARY_DIR}/file-to-lock" GUARD FUNCTION)
diff --git a/Tests/RunCMake/file/LOCK-error-no-guard-result.txt b/Tests/RunCMake/file/LOCK-error-no-guard-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-error-no-guard-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/file/LOCK-error-no-guard-stderr.txt b/Tests/RunCMake/file/LOCK-error-no-guard-stderr.txt
new file mode 100644
index 0000000..41177ce
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-error-no-guard-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at LOCK-error-no-guard\.cmake:[0-9]+ \(file\):
+ expected FUNCTION, FILE or PROCESS after GUARD
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/file/LOCK-error-no-guard.cmake b/Tests/RunCMake/file/LOCK-error-no-guard.cmake
new file mode 100644
index 0000000..48ffc5e
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-error-no-guard.cmake
@@ -0,0 +1 @@
+file(LOCK "${CMAKE_CURRENT_BINARY_DIR}/file-to-lock" GUARD)
diff --git a/Tests/RunCMake/file/LOCK-error-no-path-result.txt b/Tests/RunCMake/file/LOCK-error-no-path-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-error-no-path-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/file/LOCK-error-no-path-stderr.txt b/Tests/RunCMake/file/LOCK-error-no-path-stderr.txt
new file mode 100644
index 0000000..2247aa6
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-error-no-path-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at LOCK-error-no-path.cmake:[0-9]+ \(file\):
+ file must be called with at least two arguments.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/file/LOCK-error-no-path.cmake b/Tests/RunCMake/file/LOCK-error-no-path.cmake
new file mode 100644
index 0000000..12d79b7
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-error-no-path.cmake
@@ -0,0 +1 @@
+file(LOCK)
diff --git a/Tests/RunCMake/file/LOCK-error-no-result-variable-result.txt b/Tests/RunCMake/file/LOCK-error-no-result-variable-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-error-no-result-variable-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/file/LOCK-error-no-result-variable-stderr.txt b/Tests/RunCMake/file/LOCK-error-no-result-variable-stderr.txt
new file mode 100644
index 0000000..b38e23c
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-error-no-result-variable-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at LOCK-error-no-result-variable\.cmake:[0-9]+ \(file\):
+ expected variable name after RESULT_VARIABLE
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/file/LOCK-error-no-result-variable.cmake b/Tests/RunCMake/file/LOCK-error-no-result-variable.cmake
new file mode 100644
index 0000000..e6ac18d
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-error-no-result-variable.cmake
@@ -0,0 +1 @@
+file(LOCK "${CMAKE_CURRENT_BINARY_DIR}/file-to-lock" RESULT_VARIABLE)
diff --git a/Tests/RunCMake/file/LOCK-error-no-timeout-result.txt b/Tests/RunCMake/file/LOCK-error-no-timeout-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-error-no-timeout-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/file/LOCK-error-no-timeout-stderr.txt b/Tests/RunCMake/file/LOCK-error-no-timeout-stderr.txt
new file mode 100644
index 0000000..f34d46f
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-error-no-timeout-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at LOCK-error-no-timeout\.cmake:[0-9]+ \(file\):
+ expected timeout value after TIMEOUT
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/file/LOCK-error-no-timeout.cmake b/Tests/RunCMake/file/LOCK-error-no-timeout.cmake
new file mode 100644
index 0000000..1618192
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-error-no-timeout.cmake
@@ -0,0 +1 @@
+file(LOCK "${CMAKE_CURRENT_BINARY_DIR}/file-to-lock" TIMEOUT)
diff --git a/Tests/RunCMake/file/LOCK-error-timeout-result.txt b/Tests/RunCMake/file/LOCK-error-timeout-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-error-timeout-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/file/LOCK-error-timeout-stderr.txt b/Tests/RunCMake/file/LOCK-error-timeout-stderr.txt
new file mode 100644
index 0000000..4ad1f04
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-error-timeout-stderr.txt
@@ -0,0 +1,12 @@
+Output:[ ]*
+Error: CMake Error at .*.timeout-script\.cmake:[0-9]+ \(file\):
+ error locking file
+
+ ".*"
+
+ Timeout reached\.
++
+CMake Error at LOCK-error-timeout\.cmake:[0-9]+ \(message\):
+ Result: 1
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/file/LOCK-error-timeout-stdout.txt b/Tests/RunCMake/file/LOCK-error-timeout-stdout.txt
new file mode 100644
index 0000000..8d98f9d
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-error-timeout-stdout.txt
@@ -0,0 +1 @@
+.*
diff --git a/Tests/RunCMake/file/LOCK-error-timeout.cmake b/Tests/RunCMake/file/LOCK-error-timeout.cmake
new file mode 100644
index 0000000..b6b9476
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-error-timeout.cmake
@@ -0,0 +1,17 @@
+set(script "${CMAKE_CURRENT_LIST_DIR}/timeout-script.cmake")
+set(file_to_lock "${CMAKE_CURRENT_BINARY_DIR}/file-to-lock")
+
+file(LOCK "${file_to_lock}")
+execute_process(
+ COMMAND "${CMAKE_COMMAND}" "-Dfile_to_lock=${file_to_lock}" -P "${script}"
+ RESULT_VARIABLE result
+ OUTPUT_VARIABLE output
+ ERROR_VARIABLE error
+)
+
+message("Output: ${output}")
+message("Error: ${error}")
+
+if(NOT result EQUAL 0)
+ message(FATAL_ERROR "Result: ${result}")
+endif()
diff --git a/Tests/RunCMake/file/LOCK-error-unknown-option-result.txt b/Tests/RunCMake/file/LOCK-error-unknown-option-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-error-unknown-option-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/file/LOCK-error-unknown-option-stderr.txt b/Tests/RunCMake/file/LOCK-error-unknown-option-stderr.txt
new file mode 100644
index 0000000..ad596af
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-error-unknown-option-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at LOCK-error-unknown-option\.cmake:[0-9]+ \(file\):
+ expected DIRECTORY, RELEASE, GUARD, RESULT_VARIABLE or TIMEOUT
+
+ but got: "UNKNOWN"\.
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]* \(include\)
diff --git a/Tests/RunCMake/file/LOCK-error-unknown-option.cmake b/Tests/RunCMake/file/LOCK-error-unknown-option.cmake
new file mode 100644
index 0000000..88ef002
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-error-unknown-option.cmake
@@ -0,0 +1 @@
+file(LOCK "${CMAKE_CURRENT_BINARY_DIR}/temp-file" UNKNOWN)
diff --git a/Tests/RunCMake/file/LOCK-stdout.txt b/Tests/RunCMake/file/LOCK-stdout.txt
new file mode 100644
index 0000000..416126a
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK-stdout.txt
@@ -0,0 +1,11 @@
+-- Simple lock
+-- Directory lock
+-- Release
+-- Lock function scope
+-- Lock file scope
+-- Lock in subdirectory
+-- Lock process scope
+-- Error double lock
+-- Ok
+-- Timeout 0
+-- Timeout not 0
diff --git a/Tests/RunCMake/file/LOCK.cmake b/Tests/RunCMake/file/LOCK.cmake
new file mode 100644
index 0000000..8eff084
--- /dev/null
+++ b/Tests/RunCMake/file/LOCK.cmake
@@ -0,0 +1,40 @@
+set(lfile "${CMAKE_CURRENT_BINARY_DIR}/file-to-lock")
+set(ldir "${CMAKE_CURRENT_BINARY_DIR}/dir-to-lock")
+
+message(STATUS "Simple lock")
+file(LOCK ${lfile})
+
+message(STATUS "Directory lock")
+file(LOCK ${ldir} DIRECTORY)
+
+message(STATUS "Release")
+file(LOCK ${lfile} RELEASE)
+
+function(foo)
+ file(LOCK "${lfile}" GUARD FUNCTION)
+endfunction()
+
+message(STATUS "Lock function scope")
+foo()
+
+message(STATUS "Lock file scope")
+add_subdirectory(subdir_test_unlock)
+
+message(STATUS "Lock process scope")
+file(LOCK "${lfile}" GUARD PROCESS)
+
+message(STATUS "Error double lock")
+file(LOCK "${lfile}" RESULT_VARIABLE lock_result)
+if(lock_result STREQUAL "File already locked")
+ message(STATUS "Ok")
+else()
+ message(STATUS FATAL_ERROR "Expected error message")
+endif()
+
+message(STATUS "Timeout 0")
+file(LOCK "${lfile}" RELEASE)
+file(LOCK "${lfile}" TIMEOUT 0)
+
+message(STATUS "Timeout not 0")
+file(LOCK "${lfile}" RELEASE)
+file(LOCK "${lfile}" TIMEOUT 3)
diff --git a/Tests/RunCMake/file/RunCMakeTest.cmake b/Tests/RunCMake/file/RunCMakeTest.cmake
index bf14263..14819e7 100644
--- a/Tests/RunCMake/file/RunCMakeTest.cmake
+++ b/Tests/RunCMake/file/RunCMakeTest.cmake
@@ -3,3 +3,17 @@ include(RunCMake)
run_cmake(INSTALL-DIRECTORY)
run_cmake(INSTALL-MESSAGE-bad)
run_cmake(FileOpenFailRead)
+run_cmake(LOCK)
+run_cmake(LOCK-error-file-create-fail)
+run_cmake(LOCK-error-guard-incorrect)
+run_cmake(LOCK-error-incorrect-timeout)
+run_cmake(LOCK-error-incorrect-timeout-trail)
+run_cmake(LOCK-error-lock-fail)
+run_cmake(LOCK-error-negative-timeout)
+run_cmake(LOCK-error-no-function)
+run_cmake(LOCK-error-no-guard)
+run_cmake(LOCK-error-no-path)
+run_cmake(LOCK-error-no-result-variable)
+run_cmake(LOCK-error-no-timeout)
+run_cmake(LOCK-error-timeout)
+run_cmake(LOCK-error-unknown-option)
diff --git a/Tests/RunCMake/file/subdir_test_unlock/CMakeLists.txt b/Tests/RunCMake/file/subdir_test_unlock/CMakeLists.txt
new file mode 100644
index 0000000..c167cd7
--- /dev/null
+++ b/Tests/RunCMake/file/subdir_test_unlock/CMakeLists.txt
@@ -0,0 +1,2 @@
+message(STATUS "Lock in subdirectory")
+file(LOCK "${lfile}" GUARD FILE)
diff --git a/Tests/RunCMake/file/timeout-script.cmake b/Tests/RunCMake/file/timeout-script.cmake
new file mode 100644
index 0000000..e07dbf0
--- /dev/null
+++ b/Tests/RunCMake/file/timeout-script.cmake
@@ -0,0 +1,5 @@
+if(NOT file_to_lock)
+ message(FATAL_ERROR "file_to_lock is empty")
+endif()
+
+file(LOCK "${file_to_lock}" TIMEOUT 1)