summaryrefslogtreecommitdiffstats
path: root/Tests
diff options
context:
space:
mode:
authorMarc Chevrier <marc.chevrier@gmail.com>2022-08-22 14:10:56 (GMT)
committerMarc Chevrier <marc.chevrier@gmail.com>2022-09-03 21:10:01 (GMT)
commit838a5fae23cba0c9acf922164ff89fb6883d0f96 (patch)
tree27cf344771ff7266aa70cbf4ab3ddcba1d653a19 /Tests
parent8f0e1f2111c046aaa240a54c211404747c911698 (diff)
downloadCMake-838a5fae23cba0c9acf922164ff89fb6883d0f96.zip
CMake-838a5fae23cba0c9acf922164ff89fb6883d0f96.tar.gz
CMake-838a5fae23cba0c9acf922164ff89fb6883d0f96.tar.bz2
return(): Propagate variables to result scope
Fixes: #23871
Diffstat (limited to 'Tests')
-rw-r--r--Tests/RunCMake/return/CMP0140-NEW.cmake13
-rw-r--r--Tests/RunCMake/return/CMP0140-OLD.cmake8
-rw-r--r--Tests/RunCMake/return/CMP0140-WARN-result.txt1
-rw-r--r--Tests/RunCMake/return/CMP0140-WARN-stderr.txt12
-rw-r--r--Tests/RunCMake/return/CMP0140-WARN.cmake8
-rw-r--r--Tests/RunCMake/return/CMakeLists.txt2
-rw-r--r--Tests/RunCMake/return/PropagateFromDirectory.cmake10
-rw-r--r--Tests/RunCMake/return/PropagateFromFunction.cmake142
-rw-r--r--Tests/RunCMake/return/PropagateNothing.cmake2
-rw-r--r--Tests/RunCMake/return/RunCMakeTest.cmake9
-rw-r--r--Tests/RunCMake/return/WrongArgument-result.txt1
-rw-r--r--Tests/RunCMake/return/WrongArgument-stderr.txt4
-rw-r--r--Tests/RunCMake/return/WrongArgument.cmake2
-rw-r--r--Tests/RunCMake/return/subdir/CMakeLists.txt5
14 files changed, 218 insertions, 1 deletions
diff --git a/Tests/RunCMake/return/CMP0140-NEW.cmake b/Tests/RunCMake/return/CMP0140-NEW.cmake
new file mode 100644
index 0000000..eb6b85c
--- /dev/null
+++ b/Tests/RunCMake/return/CMP0140-NEW.cmake
@@ -0,0 +1,13 @@
+
+cmake_policy(SET CMP0140 NEW)
+
+function(FUNC)
+ set(VAR "set")
+ return(PROPAGATE VAR)
+endfunction()
+
+set(VAR "initial")
+func()
+if (NOT DEFINED VAR OR NOT VAR STREQUAL "set")
+ message(FATAL_ERROR "return(PROPAGATE) not handled correctly.")
+endif()
diff --git a/Tests/RunCMake/return/CMP0140-OLD.cmake b/Tests/RunCMake/return/CMP0140-OLD.cmake
new file mode 100644
index 0000000..8113a43
--- /dev/null
+++ b/Tests/RunCMake/return/CMP0140-OLD.cmake
@@ -0,0 +1,8 @@
+
+cmake_policy(SET CMP0140 OLD)
+
+function(FUNC)
+ return(PROPAGATE VAR)
+endfunction()
+
+func()
diff --git a/Tests/RunCMake/return/CMP0140-WARN-result.txt b/Tests/RunCMake/return/CMP0140-WARN-result.txt
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/Tests/RunCMake/return/CMP0140-WARN-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/return/CMP0140-WARN-stderr.txt b/Tests/RunCMake/return/CMP0140-WARN-stderr.txt
new file mode 100644
index 0000000..ed4beb6
--- /dev/null
+++ b/Tests/RunCMake/return/CMP0140-WARN-stderr.txt
@@ -0,0 +1,12 @@
+CMake Warning \(dev\) at CMP0140-WARN.cmake:[0-9]+ \(return\):
+ Policy CMP0140 is not set: The return\(\) command checks its arguments. Run
+ "cmake --help-policy CMP0140" for policy details. Use the cmake_policy
+ command to set the policy and suppress this warning.
+
+ return\(\) checks its arguments when the policy is set to NEW. Since the
+ policy is not set the OLD behavior will be used so the arguments will be
+ ignored.
+Call Stack \(most recent call first\):
+ CMP0140-WARN.cmake:[0-9]+ \(func\)
+ CMakeLists.txt:[0-9]+ \(include\)
+This warning is for project developers. Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/return/CMP0140-WARN.cmake b/Tests/RunCMake/return/CMP0140-WARN.cmake
new file mode 100644
index 0000000..df2fc88
--- /dev/null
+++ b/Tests/RunCMake/return/CMP0140-WARN.cmake
@@ -0,0 +1,8 @@
+
+cmake_policy(VERSION 3.1)
+
+function(FUNC)
+ return(PROPAGATE VAR)
+endfunction()
+
+func()
diff --git a/Tests/RunCMake/return/CMakeLists.txt b/Tests/RunCMake/return/CMakeLists.txt
index ef2163c..6cc903f 100644
--- a/Tests/RunCMake/return/CMakeLists.txt
+++ b/Tests/RunCMake/return/CMakeLists.txt
@@ -1,3 +1,3 @@
-cmake_minimum_required(VERSION 3.1)
+cmake_minimum_required(VERSION 3.1...3.25)
project(${RunCMake_TEST} NONE)
include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/return/PropagateFromDirectory.cmake b/Tests/RunCMake/return/PropagateFromDirectory.cmake
new file mode 100644
index 0000000..9c820bb
--- /dev/null
+++ b/Tests/RunCMake/return/PropagateFromDirectory.cmake
@@ -0,0 +1,10 @@
+
+set(VAR1 "initial")
+set(VAR2 "initial")
+
+add_subdirectory(subdir)
+
+if((NOT DEFINED VAR1 OR NOT VAR1 STREQUAL "set")
+ OR DEFINED VAR2)
+ message(SEND_ERROR "erroneous propagation for FUNC1")
+endif()
diff --git a/Tests/RunCMake/return/PropagateFromFunction.cmake b/Tests/RunCMake/return/PropagateFromFunction.cmake
new file mode 100644
index 0000000..1c12bc1
--- /dev/null
+++ b/Tests/RunCMake/return/PropagateFromFunction.cmake
@@ -0,0 +1,142 @@
+
+function(FUNC1)
+ set(VAR1 "set")
+ unset(VAR2)
+ return(PROPAGATE VAR1 VAR2)
+endfunction()
+
+set(VAR1 "initial")
+set(VAR2 "initial")
+func1()
+if((NOT DEFINED VAR1 OR NOT VAR1 STREQUAL "set")
+ OR DEFINED VAR2)
+ message(SEND_ERROR "erroneous propagation for FUNC1")
+endif()
+
+
+function(FUNC2)
+ block()
+ set(VAR1 "set")
+ unset(VAR2)
+ return(PROPAGATE VAR1 VAR2)
+ endblock()
+endfunction()
+
+set(VAR1 "initial")
+set(VAR2 "initial")
+func2()
+if((NOT DEFINED VAR1 OR NOT VAR1 STREQUAL "set")
+ OR DEFINED VAR2)
+ message(SEND_ERROR "erroneous propagation for FUNC2")
+endif()
+
+
+function(FUNC3)
+ block(SCOPE_FOR POLICIES)
+ set(VAR1 "set")
+ unset(VAR2)
+ return(PROPAGATE VAR1 VAR2)
+ endblock()
+endfunction()
+
+set(VAR1 "initial")
+set(VAR2 "initial")
+func3()
+if((NOT DEFINED VAR1 OR NOT VAR1 STREQUAL "set")
+ OR DEFINED VAR2)
+ message(SEND_ERROR "erroneous propagation for FUNC3")
+endif()
+
+
+function(FUNC4)
+ while(TRUE)
+ set(VAR1 "set")
+ unset(VAR2)
+ return(PROPAGATE VAR1 VAR2)
+ endwhile()
+endfunction()
+
+set(VAR1 "initial")
+set(VAR2 "initial")
+func4()
+if((NOT DEFINED VAR1 OR NOT VAR1 STREQUAL "set")
+ OR DEFINED VAR2)
+ message(SEND_ERROR "erroneous propagation for FUNC4")
+endif()
+
+
+function(FUNC5)
+ foreach(item IN ITEMS A B)
+ set(VAR1 "set")
+ unset(VAR2)
+ return(PROPAGATE VAR1 VAR2)
+ endforeach()
+endfunction()
+
+set(VAR1 "initial")
+set(VAR2 "initial")
+func5()
+if((NOT DEFINED VAR1 OR NOT VAR1 STREQUAL "set")
+ OR DEFINED VAR2)
+ message(SEND_ERROR "erroneous propagation for FUNC5")
+endif()
+
+
+function(FUNC6)
+ if(TRUE)
+ set(VAR1 "set")
+ unset(VAR2)
+ return(PROPAGATE VAR1 VAR2)
+ endif()
+endfunction()
+
+set(VAR1 "initial")
+set(VAR2 "initial")
+func6()
+if((NOT DEFINED VAR1 OR NOT VAR1 STREQUAL "set")
+ OR DEFINED VAR2)
+ message(SEND_ERROR "erroneous propagation for FUNC6")
+endif()
+
+
+function(FUNC7)
+ if(FALSE)
+ else()
+ set(VAR1 "set")
+ unset(VAR2)
+ return(PROPAGATE VAR1 VAR2)
+ endif()
+endfunction()
+
+set(VAR1 "initial")
+set(VAR2 "initial")
+func7()
+if((NOT DEFINED VAR1 OR NOT VAR1 STREQUAL "set")
+ OR DEFINED VAR2)
+ message(SEND_ERROR "erroneous propagation for FUNC7")
+endif()
+
+
+set(VAR1 "initial")
+set(VAR2 "initial")
+cmake_language(CALL func7)
+if((NOT DEFINED VAR1 OR NOT VAR1 STREQUAL "set")
+ OR DEFINED VAR2)
+ message(SEND_ERROR "erroneous propagation for cmake_language(CALL FUNC7)")
+endif()
+
+
+set(VAR1 "initial")
+set(VAR2 "initial")
+cmake_language(EVAL CODE "
+ function(FUNC8)
+ set(VAR1 \"set\")
+ unset(VAR2)
+ return(PROPAGATE VAR1 VAR2)
+ endfunction()
+
+ func8()")
+if((NOT DEFINED VAR1 OR NOT VAR1 STREQUAL "set")
+ OR DEFINED VAR2)
+ message(SEND_ERROR "erroneous propagation for cmake_language(EVAL CODE)")
+endif()
diff --git a/Tests/RunCMake/return/PropagateNothing.cmake b/Tests/RunCMake/return/PropagateNothing.cmake
new file mode 100644
index 0000000..0ace58e
--- /dev/null
+++ b/Tests/RunCMake/return/PropagateNothing.cmake
@@ -0,0 +1,2 @@
+
+return(PROPAGATE)
diff --git a/Tests/RunCMake/return/RunCMakeTest.cmake b/Tests/RunCMake/return/RunCMakeTest.cmake
index 2cc6c9d..f9e06a5 100644
--- a/Tests/RunCMake/return/RunCMakeTest.cmake
+++ b/Tests/RunCMake/return/RunCMakeTest.cmake
@@ -1,3 +1,12 @@
include(RunCMake)
run_cmake(ReturnFromForeach)
+
+run_cmake(WrongArgument)
+run_cmake(PropagateNothing)
+run_cmake(PropagateFromFunction)
+run_cmake(PropagateFromDirectory)
+
+run_cmake(CMP0140-NEW)
+run_cmake(CMP0140-OLD)
+run_cmake(CMP0140-WARN)
diff --git a/Tests/RunCMake/return/WrongArgument-result.txt b/Tests/RunCMake/return/WrongArgument-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/return/WrongArgument-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/return/WrongArgument-stderr.txt b/Tests/RunCMake/return/WrongArgument-stderr.txt
new file mode 100644
index 0000000..4d1c5ad
--- /dev/null
+++ b/Tests/RunCMake/return/WrongArgument-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at WrongArgument.cmake:[0-9]+ \(return\):
+ return called with unsupported argument "WRONG_ARG"
+Call Stack \(most recent call first\):
+ CMakeLists.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/return/WrongArgument.cmake b/Tests/RunCMake/return/WrongArgument.cmake
new file mode 100644
index 0000000..d03b19f
--- /dev/null
+++ b/Tests/RunCMake/return/WrongArgument.cmake
@@ -0,0 +1,2 @@
+
+return(WRONG_ARG)
diff --git a/Tests/RunCMake/return/subdir/CMakeLists.txt b/Tests/RunCMake/return/subdir/CMakeLists.txt
new file mode 100644
index 0000000..e575d47
--- /dev/null
+++ b/Tests/RunCMake/return/subdir/CMakeLists.txt
@@ -0,0 +1,5 @@
+
+set(VAR1 "set")
+unset(VAR2)
+
+return(PROPAGATE VAR1 VAR2)