diff options
Diffstat (limited to 'Tests/RunCMake/set')
-rw-r--r-- | Tests/RunCMake/set/CMakeLists.txt | 3 | ||||
-rw-r--r-- | Tests/RunCMake/set/ParentPulling-stderr.txt | 3 | ||||
-rw-r--r-- | Tests/RunCMake/set/ParentPulling.cmake | 13 | ||||
-rw-r--r-- | Tests/RunCMake/set/ParentPullingRecursive-stderr.txt | 144 | ||||
-rw-r--r-- | Tests/RunCMake/set/ParentPullingRecursive.cmake | 104 | ||||
-rw-r--r-- | Tests/RunCMake/set/ParentScope-result.txt | 1 | ||||
-rw-r--r-- | Tests/RunCMake/set/ParentScope.cmake | 33 | ||||
-rw-r--r-- | Tests/RunCMake/set/RunCMakeTest.cmake | 5 |
8 files changed, 306 insertions, 0 deletions
diff --git a/Tests/RunCMake/set/CMakeLists.txt b/Tests/RunCMake/set/CMakeLists.txt new file mode 100644 index 0000000..4b3de84 --- /dev/null +++ b/Tests/RunCMake/set/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.12) +project(${RunCMake_TEST} NONE) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/set/ParentPulling-stderr.txt b/Tests/RunCMake/set/ParentPulling-stderr.txt new file mode 100644 index 0000000..768549b --- /dev/null +++ b/Tests/RunCMake/set/ParentPulling-stderr.txt @@ -0,0 +1,3 @@ +^before PARENT_SCOPE blah=value2 +after PARENT_SCOPE blah=value2 +in parent scope, blah=value2$ diff --git a/Tests/RunCMake/set/ParentPulling.cmake b/Tests/RunCMake/set/ParentPulling.cmake new file mode 100644 index 0000000..2614533 --- /dev/null +++ b/Tests/RunCMake/set/ParentPulling.cmake @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.0) +project(Minimal NONE) + +function(test_set) + set(blah "value2") + message("before PARENT_SCOPE blah=${blah}") + set(blah ${blah} PARENT_SCOPE) + message("after PARENT_SCOPE blah=${blah}") +endfunction() + +set(blah value1) +test_set() +message("in parent scope, blah=${blah}") diff --git a/Tests/RunCMake/set/ParentPullingRecursive-stderr.txt b/Tests/RunCMake/set/ParentPullingRecursive-stderr.txt new file mode 100644 index 0000000..f3260ae --- /dev/null +++ b/Tests/RunCMake/set/ParentPullingRecursive-stderr.txt @@ -0,0 +1,144 @@ +---------- +variable values at top before calls: +top_implicit_inner_set: -->top<-- +top_implicit_inner_unset: <undefined> +top_explicit_inner_set: -->top<-- +top_explicit_inner_unset: <undefined> +top_explicit_inner_tounset: -->top<-- +top_implicit_outer_set: -->top<-- +top_explicit_outer_unset: <undefined> +top_explicit_outer_set: -->top<-- +top_explicit_outer_unset: <undefined> +top_explicit_outer_tounset: -->top<-- +outer_implicit_inner_set: <undefined> +outer_implicit_inner_unset: <undefined> +outer_explicit_inner_set: <undefined> +outer_explicit_inner_unset: <undefined> +outer_explicit_inner_tounset: <undefined> +---------- +---------- +variable values at outer start: +top_implicit_inner_set: -->top<-- +top_implicit_inner_unset: <undefined> +top_explicit_inner_set: -->top<-- +top_explicit_inner_unset: <undefined> +top_explicit_inner_tounset: -->top<-- +top_implicit_outer_set: -->top<-- +top_explicit_outer_unset: <undefined> +top_explicit_outer_set: -->top<-- +top_explicit_outer_unset: <undefined> +top_explicit_outer_tounset: -->top<-- +outer_implicit_inner_set: <undefined> +outer_implicit_inner_unset: <undefined> +outer_explicit_inner_set: <undefined> +outer_explicit_inner_unset: <undefined> +outer_explicit_inner_tounset: <undefined> +---------- +---------- +variable values at outer before inner: +top_implicit_inner_set: -->top<-- +top_implicit_inner_unset: <undefined> +top_explicit_inner_set: -->top<-- +top_explicit_inner_unset: <undefined> +top_explicit_inner_tounset: -->top<-- +top_implicit_outer_set: -->top<-- +top_explicit_outer_unset: <undefined> +top_explicit_outer_set: -->top<-- +top_explicit_outer_unset: <undefined> +top_explicit_outer_tounset: -->top<-- +outer_implicit_inner_set: -->outer<-- +outer_implicit_inner_unset: <undefined> +outer_explicit_inner_set: -->outer<-- +outer_explicit_inner_unset: <undefined> +outer_explicit_inner_tounset: -->outer<-- +---------- +---------- +variable values at inner start: +top_implicit_inner_set: -->top<-- +top_implicit_inner_unset: <undefined> +top_explicit_inner_set: -->top<-- +top_explicit_inner_unset: <undefined> +top_explicit_inner_tounset: -->top<-- +top_implicit_outer_set: -->top<-- +top_explicit_outer_unset: <undefined> +top_explicit_outer_set: -->top<-- +top_explicit_outer_unset: <undefined> +top_explicit_outer_tounset: -->top<-- +outer_implicit_inner_set: -->outer<-- +outer_implicit_inner_unset: <undefined> +outer_explicit_inner_set: -->outer<-- +outer_explicit_inner_unset: <undefined> +outer_explicit_inner_tounset: -->outer<-- +---------- +---------- +variable values at inner end: +top_implicit_inner_set: -->top<-- +top_implicit_inner_unset: <undefined> +top_explicit_inner_set: -->top<-- +top_explicit_inner_unset: <undefined> +top_explicit_inner_tounset: -->top<-- +top_implicit_outer_set: -->top<-- +top_explicit_outer_unset: <undefined> +top_explicit_outer_set: -->top<-- +top_explicit_outer_unset: <undefined> +top_explicit_outer_tounset: -->top<-- +outer_implicit_inner_set: -->outer<-- +outer_implicit_inner_unset: <undefined> +outer_explicit_inner_set: -->outer<-- +outer_explicit_inner_unset: <undefined> +outer_explicit_inner_tounset: -->outer<-- +---------- +---------- +variable values at outer after inner: +top_implicit_inner_set: -->top<-- +top_implicit_inner_unset: <undefined> +top_explicit_inner_set: -->inner<-- +top_explicit_inner_unset: -->inner<-- +top_explicit_inner_tounset: <undefined> +top_implicit_outer_set: -->top<-- +top_explicit_outer_unset: <undefined> +top_explicit_outer_set: -->top<-- +top_explicit_outer_unset: <undefined> +top_explicit_outer_tounset: -->top<-- +outer_implicit_inner_set: -->outer<-- +outer_implicit_inner_unset: <undefined> +outer_explicit_inner_set: -->inner<-- +outer_explicit_inner_unset: -->inner<-- +outer_explicit_inner_tounset: <undefined> +---------- +---------- +variable values at outer end: +top_implicit_inner_set: -->top<-- +top_implicit_inner_unset: <undefined> +top_explicit_inner_set: -->inner<-- +top_explicit_inner_unset: -->inner<-- +top_explicit_inner_tounset: <undefined> +top_implicit_outer_set: -->top<-- +top_explicit_outer_unset: <undefined> +top_explicit_outer_set: -->top<-- +top_explicit_outer_unset: <undefined> +top_explicit_outer_tounset: -->top<-- +outer_implicit_inner_set: -->outer<-- +outer_implicit_inner_unset: <undefined> +outer_explicit_inner_set: -->inner<-- +outer_explicit_inner_unset: -->inner<-- +outer_explicit_inner_tounset: <undefined> +---------- +---------- +variable values at top after calls: +top_implicit_inner_set: -->top<-- +top_implicit_inner_unset: <undefined> +top_explicit_inner_set: -->outer<-- +top_explicit_inner_unset: -->outer<-- +top_explicit_inner_tounset: <undefined> +top_implicit_outer_set: -->top<-- +top_explicit_outer_unset: -->outer<-- +top_explicit_outer_set: -->outer<-- +top_explicit_outer_unset: -->outer<-- +top_explicit_outer_tounset: <undefined> +outer_implicit_inner_set: <undefined> +outer_implicit_inner_unset: <undefined> +outer_explicit_inner_set: <undefined> +outer_explicit_inner_unset: <undefined> +outer_explicit_inner_tounset: <undefined> +---------- diff --git a/Tests/RunCMake/set/ParentPullingRecursive.cmake b/Tests/RunCMake/set/ParentPullingRecursive.cmake new file mode 100644 index 0000000..a3e29f5 --- /dev/null +++ b/Tests/RunCMake/set/ParentPullingRecursive.cmake @@ -0,0 +1,104 @@ +cmake_minimum_required(VERSION 3.0) +project(Minimal NONE) + +function(report where) + message("----------") + message("variable values at ${where}:") + foreach(var IN ITEMS + top_implicit_inner_set top_implicit_inner_unset + top_explicit_inner_set top_explicit_inner_unset top_explicit_inner_tounset + top_implicit_outer_set top_explicit_outer_unset + top_explicit_outer_set top_explicit_outer_unset top_explicit_outer_tounset + + outer_implicit_inner_set outer_implicit_inner_unset + outer_explicit_inner_set outer_explicit_inner_unset outer_explicit_inner_tounset) + if(DEFINED ${var}) + message("${var}: -->${${var}}<--") + else() + message("${var}: <undefined>") + endif() + endforeach() + message("----------") +endfunction() + +macro(set_values upscope downscope value) + # Pull the value in implicitly. + set(dummy ${${upscope}_implicit_${downscope}_set}) + set(dummy ${${upscope}_implicit_${downscope}_unset}) + # Pull it down explicitly. + set(${upscope}_explicit_${downscope}_set "${value}" PARENT_SCOPE) + set(${upscope}_explicit_${downscope}_unset "${value}" PARENT_SCOPE) + set(${upscope}_explicit_${downscope}_tounset PARENT_SCOPE) +endmacro() + +function(inner) + report("inner start") + + set_values(top inner inner) + set_values(outer inner inner) + + report("inner end") +endfunction() + +function(outer) + report("outer start") + + set_values(top outer outer) + + # Set values for inner to manipulate. + set(outer_implicit_inner_set outer) + set(outer_implicit_inner_unset) + set(outer_explicit_inner_set outer) + set(outer_explicit_inner_unset) + set(outer_explicit_inner_tounset outer) + + report("outer before inner") + + inner() + + report("outer after inner") + + # Do what inner does so that we can test the values that inner should have + # pulled through to here. + set_values(top inner outer) + + report("outer end") +endfunction() + +# variable name is: +# +# <upscope>_<pulltype>_<downscope>_<settype> +# +# where the value is the name of the scope it was set in. The scopes available +# are "top", "outer", and "inner". The pull type may either be "implicit" or +# "explicit" based on whether the pull is due to a variable dereference or a +# PARENT_SCOPE setting. The settype is "set" where both scopes set a value, +# "unset" where upscope unsets it and downscope sets it, and "tounset" where +# upscope sets it and downscope unsets it. +# +# We test the following combinations: +# +# - outer overriding top's values; +# - inner overriding top's values; +# - inner overriding outer's values; and +# - outer overriding inner's values in top after inner has run. + +# Set values for inner to manipulate. +set(top_implicit_inner_set top) +set(top_implicit_inner_unset) +set(top_explicit_inner_set top) +set(top_explicit_inner_unset) +set(top_explicit_inner_tounset top) + +# Set values for outer to manipulate. +set(top_implicit_outer_set top) +set(top_implicit_outer_unset) +set(top_explicit_outer_set top) +set(top_explicit_outer_unset) +set(top_explicit_outer_tounset top) + +report("top before calls") + +outer() + +report("top after calls") diff --git a/Tests/RunCMake/set/ParentScope-result.txt b/Tests/RunCMake/set/ParentScope-result.txt new file mode 100644 index 0000000..573541a --- /dev/null +++ b/Tests/RunCMake/set/ParentScope-result.txt @@ -0,0 +1 @@ +0 diff --git a/Tests/RunCMake/set/ParentScope.cmake b/Tests/RunCMake/set/ParentScope.cmake new file mode 100644 index 0000000..9bd6bca --- /dev/null +++ b/Tests/RunCMake/set/ParentScope.cmake @@ -0,0 +1,33 @@ +set(FOO ) +set(BAR "bar") +set(BAZ "baz") +set(BOO "boo") + +function(_parent_scope) + set(FOO "foo" PARENT_SCOPE) + set(BAR "" PARENT_SCOPE) + set(BAZ PARENT_SCOPE) + unset(BOO PARENT_SCOPE) +endfunction() + +_parent_scope() + +if(NOT DEFINED FOO) + message(FATAL_ERROR "FOO not defined") +elseif(NOT "${FOO}" STREQUAL "foo") + message(FATAL_ERROR "FOO should be \"foo\", not \"${FOO}\"") +endif() + +if(NOT DEFINED BAR) + message(FATAL_ERROR "BAR not defined") +elseif(NOT "${BAR}" STREQUAL "") + message(FATAL_ERROR "BAR should be an empty string, not \"${BAR}\"") +endif() + +if(DEFINED BAZ) + message(FATAL_ERROR "BAZ defined") +endif() + +if(DEFINED BOO) + message(FATAL_ERROR "BOO defined") +endif() diff --git a/Tests/RunCMake/set/RunCMakeTest.cmake b/Tests/RunCMake/set/RunCMakeTest.cmake new file mode 100644 index 0000000..b8e8cf1 --- /dev/null +++ b/Tests/RunCMake/set/RunCMakeTest.cmake @@ -0,0 +1,5 @@ +include(RunCMake) + +run_cmake(ParentScope) +run_cmake(ParentPulling) +run_cmake(ParentPullingRecursive) |