diff options
author | Brad King <brad.king@kitware.com> | 2019-12-09 16:25:23 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2019-12-09 16:25:35 (GMT) |
commit | f62c674202045f877eaed9da0f9cbe2046452b40 (patch) | |
tree | 691535f0ad6788dfbec850ef0c72ffaa09d5cb54 /Tests | |
parent | 17cb41926725a232393796bcd157d86b74fd6ad3 (diff) | |
parent | d30468a2f69f80c4f7d9d16b68f347bc3815dacc (diff) | |
download | CMake-f62c674202045f877eaed9da0f9cbe2046452b40.zip CMake-f62c674202045f877eaed9da0f9cbe2046452b40.tar.gz CMake-f62c674202045f877eaed9da0f9cbe2046452b40.tar.bz2 |
Merge topic 'foreach-ZIP_LISTS'
d30468a2f6 foreach: Allow multiple iteration variables for `ZIP_LIST` mode
f3e51a2b1d foreach: Introduce `IN ZIP_LISTS` mode
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !4021
Diffstat (limited to 'Tests')
29 files changed, 201 insertions, 0 deletions
diff --git a/Tests/RunCMake/foreach/RunCMakeTest.cmake b/Tests/RunCMake/foreach/RunCMakeTest.cmake index 0f1fdd4..8f50203 100644 --- a/Tests/RunCMake/foreach/RunCMakeTest.cmake +++ b/Tests/RunCMake/foreach/RunCMakeTest.cmake @@ -2,3 +2,13 @@ include(RunCMake) run_cmake(BadRangeInFunction) run_cmake(foreach-all-test) +run_cmake(foreach-ITEMS-multiple-iter-vars-test) +run_cmake(foreach-LISTS-multiple-iter-vars-test) +run_cmake(foreach-ZIP_LISTS-test) +run_cmake(foreach-ITEMS-with-ZIP_LISTS-mix-test) +run_cmake(foreach-LISTS-with-ZIP_LISTS-mix-test) +run_cmake(foreach-ZIP_LISTS-with-ITEMS-mix-test) +run_cmake(foreach-ZIP_LISTS-with-LISTS-mix-test) +run_cmake(foreach-ZIP_LISTS-multiple-iter-vars-test) +run_cmake(foreach-ZIP_LISTS-iter-vars-mismatch-test-1) +run_cmake(foreach-ZIP_LISTS-iter-vars-mismatch-test-2) diff --git a/Tests/RunCMake/foreach/foreach-ITEMS-multiple-iter-vars-test-result.txt b/Tests/RunCMake/foreach/foreach-ITEMS-multiple-iter-vars-test-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/foreach/foreach-ITEMS-multiple-iter-vars-test-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/foreach/foreach-ITEMS-multiple-iter-vars-test-stderr.txt b/Tests/RunCMake/foreach/foreach-ITEMS-multiple-iter-vars-test-stderr.txt new file mode 100644 index 0000000..d174bb1 --- /dev/null +++ b/Tests/RunCMake/foreach/foreach-ITEMS-multiple-iter-vars-test-stderr.txt @@ -0,0 +1,4 @@ +^CMake Error at foreach-ITEMS-multiple-iter-vars-test.cmake:1 \(foreach\): + ITEMS or LISTS require exactly one iteration variable +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/foreach/foreach-ITEMS-multiple-iter-vars-test.cmake b/Tests/RunCMake/foreach/foreach-ITEMS-multiple-iter-vars-test.cmake new file mode 100644 index 0000000..55d33a8 --- /dev/null +++ b/Tests/RunCMake/foreach/foreach-ITEMS-multiple-iter-vars-test.cmake @@ -0,0 +1,2 @@ +foreach(one two IN ITEMS one two) +endforeach() diff --git a/Tests/RunCMake/foreach/foreach-ITEMS-with-ZIP_LISTS-mix-test-result.txt b/Tests/RunCMake/foreach/foreach-ITEMS-with-ZIP_LISTS-mix-test-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/foreach/foreach-ITEMS-with-ZIP_LISTS-mix-test-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/foreach/foreach-ITEMS-with-ZIP_LISTS-mix-test-stderr.txt b/Tests/RunCMake/foreach/foreach-ITEMS-with-ZIP_LISTS-mix-test-stderr.txt new file mode 100644 index 0000000..f7d5ae7 --- /dev/null +++ b/Tests/RunCMake/foreach/foreach-ITEMS-with-ZIP_LISTS-mix-test-stderr.txt @@ -0,0 +1,4 @@ +^CMake Error at foreach-ITEMS-with-ZIP_LISTS-mix-test.cmake:1 \(foreach\): + ZIP_LISTS can not be used with LISTS or ITEMS +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/foreach/foreach-ITEMS-with-ZIP_LISTS-mix-test.cmake b/Tests/RunCMake/foreach/foreach-ITEMS-with-ZIP_LISTS-mix-test.cmake new file mode 100644 index 0000000..28099a0 --- /dev/null +++ b/Tests/RunCMake/foreach/foreach-ITEMS-with-ZIP_LISTS-mix-test.cmake @@ -0,0 +1,2 @@ +foreach(i IN ITEMS one two three ZIP_LISTS blah) +endforeach() diff --git a/Tests/RunCMake/foreach/foreach-LISTS-multiple-iter-vars-test-result.txt b/Tests/RunCMake/foreach/foreach-LISTS-multiple-iter-vars-test-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/foreach/foreach-LISTS-multiple-iter-vars-test-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/foreach/foreach-LISTS-multiple-iter-vars-test-stderr.txt b/Tests/RunCMake/foreach/foreach-LISTS-multiple-iter-vars-test-stderr.txt new file mode 100644 index 0000000..f2f83c2 --- /dev/null +++ b/Tests/RunCMake/foreach/foreach-LISTS-multiple-iter-vars-test-stderr.txt @@ -0,0 +1,4 @@ +^CMake Error at foreach-LISTS-multiple-iter-vars-test.cmake:1 \(foreach\): + ITEMS or LISTS require exactly one iteration variable +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/foreach/foreach-LISTS-multiple-iter-vars-test.cmake b/Tests/RunCMake/foreach/foreach-LISTS-multiple-iter-vars-test.cmake new file mode 100644 index 0000000..78f3847 --- /dev/null +++ b/Tests/RunCMake/foreach/foreach-LISTS-multiple-iter-vars-test.cmake @@ -0,0 +1,2 @@ +foreach(one two IN LISTS one two) +endforeach() diff --git a/Tests/RunCMake/foreach/foreach-LISTS-with-ZIP_LISTS-mix-test-result.txt b/Tests/RunCMake/foreach/foreach-LISTS-with-ZIP_LISTS-mix-test-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/foreach/foreach-LISTS-with-ZIP_LISTS-mix-test-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/foreach/foreach-LISTS-with-ZIP_LISTS-mix-test-stderr.txt b/Tests/RunCMake/foreach/foreach-LISTS-with-ZIP_LISTS-mix-test-stderr.txt new file mode 100644 index 0000000..42f8d1e --- /dev/null +++ b/Tests/RunCMake/foreach/foreach-LISTS-with-ZIP_LISTS-mix-test-stderr.txt @@ -0,0 +1,4 @@ +^CMake Error at foreach-LISTS-with-ZIP_LISTS-mix-test.cmake:1 \(foreach\): + ZIP_LISTS can not be used with LISTS or ITEMS +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/foreach/foreach-LISTS-with-ZIP_LISTS-mix-test.cmake b/Tests/RunCMake/foreach/foreach-LISTS-with-ZIP_LISTS-mix-test.cmake new file mode 100644 index 0000000..8a919dd --- /dev/null +++ b/Tests/RunCMake/foreach/foreach-LISTS-with-ZIP_LISTS-mix-test.cmake @@ -0,0 +1,2 @@ +foreach(i IN LISTS one two three ZIP_LISTS blah) +endforeach() diff --git a/Tests/RunCMake/foreach/foreach-ZIP_LISTS-iter-vars-mismatch-test-1-result.txt b/Tests/RunCMake/foreach/foreach-ZIP_LISTS-iter-vars-mismatch-test-1-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/foreach/foreach-ZIP_LISTS-iter-vars-mismatch-test-1-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/foreach/foreach-ZIP_LISTS-iter-vars-mismatch-test-1-stderr.txt b/Tests/RunCMake/foreach/foreach-ZIP_LISTS-iter-vars-mismatch-test-1-stderr.txt new file mode 100644 index 0000000..fa51e46 --- /dev/null +++ b/Tests/RunCMake/foreach/foreach-ZIP_LISTS-iter-vars-mismatch-test-1-stderr.txt @@ -0,0 +1,4 @@ +^CMake Error at foreach-ZIP_LISTS-iter-vars-mismatch-test-1.cmake:1 \(foreach\): + Expected 3 list variables, but given 4 +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/foreach/foreach-ZIP_LISTS-iter-vars-mismatch-test-1.cmake b/Tests/RunCMake/foreach/foreach-ZIP_LISTS-iter-vars-mismatch-test-1.cmake new file mode 100644 index 0000000..458b6ca --- /dev/null +++ b/Tests/RunCMake/foreach/foreach-ZIP_LISTS-iter-vars-mismatch-test-1.cmake @@ -0,0 +1,2 @@ +foreach(less than lists IN ZIP_LISTS list_1 list_2 list_3 list_4) +endforeach() diff --git a/Tests/RunCMake/foreach/foreach-ZIP_LISTS-iter-vars-mismatch-test-2-result.txt b/Tests/RunCMake/foreach/foreach-ZIP_LISTS-iter-vars-mismatch-test-2-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/foreach/foreach-ZIP_LISTS-iter-vars-mismatch-test-2-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/foreach/foreach-ZIP_LISTS-iter-vars-mismatch-test-2-stderr.txt b/Tests/RunCMake/foreach/foreach-ZIP_LISTS-iter-vars-mismatch-test-2-stderr.txt new file mode 100644 index 0000000..7b6b484 --- /dev/null +++ b/Tests/RunCMake/foreach/foreach-ZIP_LISTS-iter-vars-mismatch-test-2-stderr.txt @@ -0,0 +1,4 @@ +^CMake Error at foreach-ZIP_LISTS-iter-vars-mismatch-test-2.cmake:1 \(foreach\): + Expected 3 list variables, but given 2 +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/foreach/foreach-ZIP_LISTS-iter-vars-mismatch-test-2.cmake b/Tests/RunCMake/foreach/foreach-ZIP_LISTS-iter-vars-mismatch-test-2.cmake new file mode 100644 index 0000000..d24d99c --- /dev/null +++ b/Tests/RunCMake/foreach/foreach-ZIP_LISTS-iter-vars-mismatch-test-2.cmake @@ -0,0 +1,2 @@ +foreach(greater than lists IN ZIP_LISTS list_1 list_2) +endforeach() diff --git a/Tests/RunCMake/foreach/foreach-ZIP_LISTS-multiple-iter-vars-test-stdout.txt b/Tests/RunCMake/foreach/foreach-ZIP_LISTS-multiple-iter-vars-test-stdout.txt new file mode 100644 index 0000000..e009d15 --- /dev/null +++ b/Tests/RunCMake/foreach/foreach-ZIP_LISTS-multiple-iter-vars-test-stdout.txt @@ -0,0 +1,6 @@ +-- foreach\(\.\.\. IN ZIP_LISTS\): +-- Begin output +-- | one, satu, raz +-- | two, dua, dva +-- | three, tiga, tri +-- End output diff --git a/Tests/RunCMake/foreach/foreach-ZIP_LISTS-multiple-iter-vars-test.cmake b/Tests/RunCMake/foreach/foreach-ZIP_LISTS-multiple-iter-vars-test.cmake new file mode 100644 index 0000000..9647dea --- /dev/null +++ b/Tests/RunCMake/foreach/foreach-ZIP_LISTS-multiple-iter-vars-test.cmake @@ -0,0 +1,42 @@ +function(foreachTest result list_var_1 list_var_2 list_var_3) + set(_options MUTE) + set(_one_value_args) + set(_multi_value_args) + cmake_parse_arguments(PARSE_ARGV 3 _arg "${_options}" "${_one_value_args}" "${_multi_value_args}") + + set(_has_any_output FALSE) + list(APPEND CMAKE_MESSAGE_INDENT "| ") + foreach(first second third IN ZIP_LISTS ${list_var_1} ${list_var_2} ${list_var_3}) + if(NOT first) + set(first "[undefiend]") + endif() + if(NOT second) + set(second "[undefiend]") + endif() + if(NOT third) + set(third "[undefiend]") + endif() + if(NOT _arg_MUTE) + message(STATUS "${first}, ${second}, ${third}") + endif() + set(_has_any_output TRUE) + endforeach() + set(${result} ${_has_any_output} PARENT_SCOPE) +endfunction() + +function(foreachTestDecorated list_var_1 list_var_2 list_var_3) + list(APPEND CMAKE_MESSAGE_INDENT " ") + message(STATUS "Begin output") + foreachTest(_has_any_output ${list_var_1} ${list_var_2} ${list_var_3}) + if(NOT _has_any_output) + message(STATUS "--> empty-output <--") + endif() + message(STATUS "End output") +endfunction() + +list(APPEND english one two three) +list(APPEND bahasa satu dua tiga) +list(APPEND russian raz dva tri) + +message(STATUS "foreach(... IN ZIP_LISTS):") +foreachTestDecorated(english bahasa russian) diff --git a/Tests/RunCMake/foreach/foreach-ZIP_LISTS-test-stdout.txt b/Tests/RunCMake/foreach/foreach-ZIP_LISTS-test-stdout.txt new file mode 100644 index 0000000..25433fd --- /dev/null +++ b/Tests/RunCMake/foreach/foreach-ZIP_LISTS-test-stdout.txt @@ -0,0 +1,19 @@ +-- foreach\(IN ZIP_LISTS\): +-- <<< empty lists case >>> +-- Begin output +-- --> empty-output <-- +-- End output +-- <<< same lengths lists case >>> +-- Begin output +-- | one, satu, raz +-- | two, dua, dva +-- | three, tiga, tri +-- End output +-- <<< different lengths lists case >>> +-- Begin output +-- | one, satu, raz +-- | two, dua, dva +-- | three, tiga, tri +-- | \[undefiend\], empat, \[undefiend\] +-- End output +-- <<< test variable value restored -- PASSED >>> diff --git a/Tests/RunCMake/foreach/foreach-ZIP_LISTS-test.cmake b/Tests/RunCMake/foreach/foreach-ZIP_LISTS-test.cmake new file mode 100644 index 0000000..56cfe64 --- /dev/null +++ b/Tests/RunCMake/foreach/foreach-ZIP_LISTS-test.cmake @@ -0,0 +1,68 @@ +function(foreachTest result list_var_1 list_var_2 list_var_3) + set(_options MUTE) + set(_one_value_args) + set(_multi_value_args) + cmake_parse_arguments(PARSE_ARGV 3 _arg "${_options}" "${_one_value_args}" "${_multi_value_args}") + + set(_has_any_output FALSE) + list(APPEND CMAKE_MESSAGE_INDENT "| ") + foreach(num IN ZIP_LISTS ${list_var_1} ${list_var_2} ${list_var_3}) + foreach(i RANGE 2) + if(NOT num_${i}) + set(num_${i} "[undefiend]") + endif() + endforeach() + if(NOT _arg_MUTE) + message(STATUS "${num_0}, ${num_1}, ${num_2}") + endif() + set(_has_any_output TRUE) + endforeach() + set(${result} ${_has_any_output} PARENT_SCOPE) +endfunction() + +function(foreachTestDecorated list_var_1 list_var_2 list_var_3) + list(APPEND CMAKE_MESSAGE_INDENT " ") + message(STATUS "Begin output") + foreachTest(_has_any_output ${list_var_1} ${list_var_2} ${list_var_3}) + if(NOT _has_any_output) + message(STATUS "--> empty-output <--") + endif() + message(STATUS "End output") +endfunction() + +message(STATUS "foreach(IN ZIP_LISTS):") +list(APPEND CMAKE_MESSAGE_INDENT " ") + +set(english) +set(bahasa) +set(russian) + +message(STATUS "<<< empty lists case >>>") +foreachTestDecorated(english bahasa russian) + +list(APPEND english one two three) +list(APPEND bahasa satu dua tiga) +list(APPEND russian raz dva tri) + +message(STATUS "<<< same lengths lists case >>>") +foreachTestDecorated(english bahasa russian) + +list(APPEND bahasa empat) + +message(STATUS "<<< different lengths lists case >>>") +foreachTestDecorated(english bahasa russian) + +set(num_0 "old-0") +set(num_1 "old-1") +set(num_2 "old-2") +foreachTest(_ english bahasa russian MUTE) +set(check PASSED) +foreach(i RANGE 2) + if(NOT "${num_${i}}" STREQUAL "old-${i}") + message(SEND_ERROR "num_${i} value is corrupted") + set(check FAILED) + endif() +endforeach() +message(STATUS "<<< test variable value restored -- ${check} >>>") + +list(POP_BACK CMAKE_MESSAGE_INDENT) diff --git a/Tests/RunCMake/foreach/foreach-ZIP_LISTS-with-ITEMS-mix-test-result.txt b/Tests/RunCMake/foreach/foreach-ZIP_LISTS-with-ITEMS-mix-test-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/foreach/foreach-ZIP_LISTS-with-ITEMS-mix-test-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/foreach/foreach-ZIP_LISTS-with-ITEMS-mix-test-stderr.txt b/Tests/RunCMake/foreach/foreach-ZIP_LISTS-with-ITEMS-mix-test-stderr.txt new file mode 100644 index 0000000..0dcab01 --- /dev/null +++ b/Tests/RunCMake/foreach/foreach-ZIP_LISTS-with-ITEMS-mix-test-stderr.txt @@ -0,0 +1,4 @@ +^CMake Error at foreach-ZIP_LISTS-with-ITEMS-mix-test.cmake:1 \(foreach\): + ZIP_LISTS can not be used with LISTS or ITEMS +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/foreach/foreach-ZIP_LISTS-with-ITEMS-mix-test.cmake b/Tests/RunCMake/foreach/foreach-ZIP_LISTS-with-ITEMS-mix-test.cmake new file mode 100644 index 0000000..71ed842 --- /dev/null +++ b/Tests/RunCMake/foreach/foreach-ZIP_LISTS-with-ITEMS-mix-test.cmake @@ -0,0 +1,2 @@ +foreach(i IN ZIP_LISTS blah ITEMS blah) +endforeach() diff --git a/Tests/RunCMake/foreach/foreach-ZIP_LISTS-with-LISTS-mix-test-result.txt b/Tests/RunCMake/foreach/foreach-ZIP_LISTS-with-LISTS-mix-test-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/foreach/foreach-ZIP_LISTS-with-LISTS-mix-test-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/foreach/foreach-ZIP_LISTS-with-LISTS-mix-test-stderr.txt b/Tests/RunCMake/foreach/foreach-ZIP_LISTS-with-LISTS-mix-test-stderr.txt new file mode 100644 index 0000000..a6b6e9c --- /dev/null +++ b/Tests/RunCMake/foreach/foreach-ZIP_LISTS-with-LISTS-mix-test-stderr.txt @@ -0,0 +1,4 @@ +^CMake Error at foreach-ZIP_LISTS-with-LISTS-mix-test.cmake:1 \(foreach\): + ZIP_LISTS can not be used with LISTS or ITEMS +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/foreach/foreach-ZIP_LISTS-with-LISTS-mix-test.cmake b/Tests/RunCMake/foreach/foreach-ZIP_LISTS-with-LISTS-mix-test.cmake new file mode 100644 index 0000000..11a97b2 --- /dev/null +++ b/Tests/RunCMake/foreach/foreach-ZIP_LISTS-with-LISTS-mix-test.cmake @@ -0,0 +1,2 @@ +foreach(i IN ZIP_LISTS blah LISTS blah) +endforeach() |