diff options
author | Alex Turbov <i.zaufi@gmail.com> | 2019-02-17 16:47:50 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2019-02-19 14:42:36 (GMT) |
commit | a84e509844b74d445b654cd9d0be98a8f0e0641e (patch) | |
tree | 30c0de2b685b6103ce0325966b4e1395f658c081 /Tests/RunCMake/list/POP_FRONT.cmake | |
parent | 8ec1942f62a659154abdd99602440757f5eef485 (diff) | |
download | CMake-a84e509844b74d445b654cd9d0be98a8f0e0641e.zip CMake-a84e509844b74d445b654cd9d0be98a8f0e0641e.tar.gz CMake-a84e509844b74d445b654cd9d0be98a8f0e0641e.tar.bz2 |
list: add sub-commands PREPEND, POP_BACK, POP_FRONT
Diffstat (limited to 'Tests/RunCMake/list/POP_FRONT.cmake')
-rw-r--r-- | Tests/RunCMake/list/POP_FRONT.cmake | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/Tests/RunCMake/list/POP_FRONT.cmake b/Tests/RunCMake/list/POP_FRONT.cmake new file mode 100644 index 0000000..a2f8f3c --- /dev/null +++ b/Tests/RunCMake/list/POP_FRONT.cmake @@ -0,0 +1,79 @@ +cmake_policy(SET CMP0054 NEW) + +function(assert_expected_list_len list_var expected_size) + list(LENGTH ${list_var} _size) + if(NOT _size EQUAL ${expected_size}) + message(FATAL_ERROR "list size expected to be `${expected_size}`, got `${_size}` instead") + endif() +endfunction() + +# Pop from undefined list +list(POP_FRONT test) +if(DEFINED test) + message(FATAL_ERROR "`test` expected to be undefined") +endif() + +# Pop from empty list +set(test) +list(POP_FRONT test) +if(DEFINED test) + message(FATAL_ERROR "`test` expected to be undefined") +endif() + +# Default pop from 1-item list +list(APPEND test one) +list(POP_FRONT test) +assert_expected_list_len(test 0) + +# Pop from 1-item list to var +list(APPEND test one) +list(POP_FRONT test one) +assert_expected_list_len(test 0) +if(NOT DEFINED one) + message(FATAL_ERROR "`one` expected to be defined") +endif() +if(NOT one STREQUAL "one") + message(FATAL_ERROR "`one` has unexpected value `${one}`") +endif() + +unset(one) +unset(two) + +# Pop from 1-item list to vars +list(APPEND test one) +list(POP_FRONT test one two) +assert_expected_list_len(test 0) +if(NOT DEFINED one) + message(FATAL_ERROR "`one` expected to be defined") +endif() +if(NOT one STREQUAL "one") + message(FATAL_ERROR "`one` has unexpected value `${one}`") +endif() +if(DEFINED two) + message(FATAL_ERROR "`two` expected to be undefined") +endif() + +unset(one) +unset(two) + +# Default pop from 2-item list +list(APPEND test one two) +list(POP_FRONT test) +assert_expected_list_len(test 1) +if(NOT test STREQUAL "two") + message(FATAL_ERROR "`test` has unexpected value `${test}`") +endif() + +# Pop from 2-item list +list(PREPEND test one) +list(POP_FRONT test one) +assert_expected_list_len(test 1) +if(NOT DEFINED one) + message(FATAL_ERROR "`one` expected to be defined") +endif() +if(NOT one STREQUAL "one") + message(FATAL_ERROR "`one` has unexpected value `${one}`") +endif() +if(NOT test STREQUAL "two") + message(FATAL_ERROR "`test` has unexpected value `${test}`") +endif() |