2012-09-29 15:02:38 +04:00
include ( "@CMAKE_CURRENT_SOURCE_DIR@/CheckCMakeTest.cmake" )
2012-08-13 21:47:32 +04:00
macro ( TEST command expected )
if ( "x${result}" STREQUAL "x${expected}" )
#message("TEST \"${command}\" success: \"${result}\" expected: \"${expected}\"")
2012-08-13 21:50:14 +04:00
else ( )
2012-08-13 21:47:32 +04:00
message ( SEND_ERROR "${CMAKE_CURRENT_LIST_LINE}: TEST \" ${ command } \" failed: \"${result}\" expected: \"${expected}\"")
2012-08-13 21:50:14 +04:00
endif ( )
endmacro ( )
2006-02-10 22:11:12 +03:00
2012-08-13 21:47:32 +04:00
set ( mylist andy bill ken brad )
2006-02-10 22:11:12 +03:00
2012-08-13 21:47:32 +04:00
list ( LENGTH mylist result )
2006-02-10 22:11:12 +03:00
TEST ( "LENGTH mylist result" "4" )
2012-08-13 21:47:32 +04:00
list ( LENGTH "mylist" result )
2006-02-10 22:11:12 +03:00
TEST ( "LENGTH \" mylist\ " result" "4" )
2012-08-13 21:47:32 +04:00
list ( LENGTH "nonexiting_list1" result )
2006-05-15 17:25:06 +04:00
TEST ( "LENGTH \" nonexiting_list1\ " result" "0" )
2012-08-13 21:47:32 +04:00
list ( GET mylist 3 2 1 0 result )
2006-02-10 22:11:12 +03:00
TEST ( "GET mylist 3 2 1 0 result" "brad;ken;bill;andy" )
2012-08-13 21:47:32 +04:00
list ( GET mylist 0 item0 )
list ( GET mylist 1 item1 )
list ( GET mylist 2 item2 )
list ( GET mylist 3 item3 )
set ( result "${item3}" "${item0}" "${item1}" "${item2}" )
2006-02-10 22:11:12 +03:00
TEST ( "GET individual 3 2 1 0 result" "brad;andy;bill;ken" )
2012-08-13 21:47:32 +04:00
list ( GET mylist -1 -2 -3 -4 result )
2006-02-10 22:11:12 +03:00
TEST ( "GET mylist -1 -2 -3 -4 result" "brad;ken;bill;andy" )
2012-08-13 21:47:32 +04:00
list ( GET mylist -1 2 -3 0 result )
2006-02-10 22:11:12 +03:00
TEST ( "GET mylist -1 2 -3 0 ${result}" "brad;ken;bill;andy" )
2012-08-13 21:47:32 +04:00
list ( GET "nonexiting_list2" 1 result )
2006-05-15 17:25:06 +04:00
TEST ( "GET \" nonexiting_list2\ " 1 result" "NOTFOUND" )
2012-08-13 21:47:32 +04:00
set ( result andy )
list ( APPEND result brad )
2006-05-15 17:25:06 +04:00
TEST ( "APPEND result brad" "andy;brad" )
2012-08-13 21:47:32 +04:00
list ( APPEND "nonexiting_list3" brad )
set ( result "${nonexiting_list3}" )
2006-05-15 18:14:16 +04:00
TEST ( "APPEND \" nonexiting_list3\ " brad" "brad" )
2012-08-13 21:47:32 +04:00
list ( INSERT "nonexiting_list4" 0 andy bill brad ken )
set ( result "${nonexiting_list4}" )
2006-05-15 18:14:16 +04:00
TEST ( "APPEND \" nonexiting_list4\ " andy bill brad ken" "andy;bill;brad;ken" )
2006-02-10 22:11:12 +03:00
2012-08-13 21:47:32 +04:00
set ( result andy brad )
list ( INSERT result -1 bill ken )
2006-02-10 22:11:12 +03:00
TEST ( "INSERT result -1 bill ken" "andy;bill;ken;brad" )
2012-08-13 21:47:32 +04:00
set ( result andy bill brad ken bob )
list ( REMOVE_ITEM result bob )
2006-05-15 17:57:49 +04:00
TEST ( "REMOVE_ITEM result bob" "andy;bill;brad;ken" )
2006-02-10 22:11:12 +03:00
2012-08-13 21:47:32 +04:00
set ( result andy bill bob brad ken peter )
list ( REMOVE_ITEM result peter bob )
2006-05-15 17:57:49 +04:00
TEST ( "REMOVE_ITEM result peter bob" "andy;bill;brad;ken" )
2012-08-13 21:47:32 +04:00
set ( result bob andy bill bob brad ken bob )
list ( REMOVE_ITEM result bob )
2006-05-15 17:57:49 +04:00
TEST ( "REMOVE_ITEM result bob" "andy;bill;brad;ken" )
2006-02-10 22:11:12 +03:00
2012-08-13 21:47:32 +04:00
set ( result andy bill bob brad ken peter )
list ( REMOVE_AT result 2 -1 )
2006-05-15 17:57:49 +04:00
TEST ( "REMOVE_AT result 2 -1" "andy;bill;brad;ken" )
2007-07-12 19:56:45 +04:00
2007-08-15 18:26:50 +04:00
# ken is at index 2, nobody is not in the list so -1 should be returned
2012-08-13 21:47:32 +04:00
set ( mylist andy bill ken brad )
list ( FIND mylist ken result )
2007-08-15 18:26:50 +04:00
TEST ( "FIND mylist ken result" "2" )
2007-07-12 19:56:45 +04:00
2012-08-13 21:47:32 +04:00
list ( FIND mylist nobody result )
2007-08-15 18:26:50 +04:00
TEST ( "FIND mylist nobody result" "-1" )
2007-07-12 19:56:45 +04:00
2012-08-13 21:47:32 +04:00
set ( result ken bill andy brad )
list ( SORT result )
2007-07-12 19:56:45 +04:00
TEST ( "SORT result" "andy;bill;brad;ken" )
2012-08-13 21:47:32 +04:00
set ( result andy bill brad ken )
list ( REVERSE result )
2007-07-12 19:56:45 +04:00
TEST ( "REVERSE result" "ken;brad;bill;andy" )
2008-03-13 00:02:10 +03:00
2012-08-13 21:47:32 +04:00
set ( result bill andy bill brad ken ken ken )
list ( REMOVE_DUPLICATES result )
2008-03-13 00:02:10 +03:00
TEST ( "REMOVE_DUPLICATES result" "bill;andy;brad;ken" )
2012-08-16 01:05:05 +04:00
# these commands should just do nothing if the list is already empty
set ( result "" )
list ( REMOVE_DUPLICATES result )
TEST ( "REMOVE_DUPLICATES empty result" "" )
list ( REVERSE result )
TEST ( "REVERSE empty result" "" )
list ( SORT result )
TEST ( "SORT empty result" "" )
2012-09-29 15:02:38 +04:00
set ( No-Arguments-RESULT 1 )
2012-09-29 17:41:29 +04:00
set ( No-Arguments-STDERR ".*CMake Error at (@CMAKE_CURRENT_SOURCE_DIR@/)?List-No-Arguments.cmake:1 \\(list\\):.*list must be called with at least two arguments.*" )
2012-09-29 15:02:38 +04:00
2012-09-29 17:41:29 +04:00
# these trigger top-level condition
2012-09-29 15:02:38 +04:00
foreach ( cmd IN ITEMS Append Find Get Insert Length Reverse Remove_At Remove_Duplicates Remove_Item Sort )
set ( ${ cmd } -No-Arguments-RESULT 1 )
2012-09-29 17:41:29 +04:00
set ( ${ cmd } -No-Arguments-STDERR ".*CMake Error at List-${cmd}-No-Arguments.cmake:1 \\(list\\):.*list must be called with at least two arguments.*" )
2012-09-29 15:02:38 +04:00
string ( TOUPPER ${ cmd } cmd_upper )
set ( _test_file_name "${CMAKE_CURRENT_BINARY_DIR}/List-${cmd}-No-Arguments.cmake" )
file ( WRITE "${_test_file_name}" "list(${cmd_upper})\n" )
check_cmake_test_single ( List "${cmd}-No-Arguments" "${_test_file_name}" )
endforeach ( )
2012-09-29 17:41:29 +04:00
set ( Get-List-Only-STDERR "at least three" )
set ( Find-List-Only-STDERR "three" )
set ( Insert-List-Only-STDERR "at least three" )
set ( Length-List-Only-STDERR "two" )
set ( Remove_At-List-Only-STDERR "at least two" )
set ( Remove_Item-List-Only-STDERR "two or more" )
foreach ( cmd IN ITEMS Find Get Insert Length Remove_At Remove_Item )
string ( TOUPPER ${ cmd } cmd_upper )
set ( ${ cmd } -List-Only-RESULT 1 )
set ( ${ cmd } -List-Only-STDERR ".*CMake Error at List-${cmd}-List-Only.cmake:1 \\(list\\):.*list sub-command ${cmd_upper} requires ${${cmd}-List-Only-STDERR} arguments.*" )
set ( _test_file_name "${CMAKE_CURRENT_BINARY_DIR}/List-${cmd}-List-Only.cmake" )
file ( WRITE "${_test_file_name}" "list(${cmd_upper} mylist)\n" )
check_cmake_test_single ( List "${cmd}-List-Only" "${_test_file_name}" )
endforeach ( )
2012-09-29 15:02:38 +04:00
set ( Length-Too-Many-Arguments-RESULT 1 )
set ( Length-Too-Many-Arguments-STDERR ".*CMake Error at (@CMAKE_CURRENT_SOURCE_DIR@/)?List-Length-Too-Many-Arguments.cmake:1 \\(list\\):.*list sub-command LENGTH requires two arguments.*" )
set ( Reverse-Too-Many-Arguments-RESULT 1 )
set ( Reverse-Too-Many-Arguments-STDERR ".*CMake Error at (@CMAKE_CURRENT_SOURCE_DIR@/)?List-Reverse-Too-Many-Arguments.cmake:1 \\(list\\):.*list sub-command REVERSE only takes one argument.*" )
set ( Remove_Duplicates-Too-Many-Arguments-RESULT 1 )
set ( Remove_Duplicates-Too-Many-Arguments-STDERR ".*CMake Error at (@CMAKE_CURRENT_SOURCE_DIR@/)?List-Remove_Duplicates-Too-Many-Arguments.cmake:1 \\(list\\):.*list sub-command REMOVE_DUPLICATES only takes one argument.*" )
set ( Sort-Too-Many-Arguments-RESULT 1 )
set ( Sort-Too-Many-Arguments-STDERR ".*CMake Error at (@CMAKE_CURRENT_SOURCE_DIR@/)?List-Sort-Too-Many-Arguments.cmake:1 \\(list\\):.*list sub-command SORT only takes one argument.*" )
2012-09-29 16:41:07 +04:00
set ( Invalid-Subcommand-RESULT 1 )
set ( Invalid-Subcommand-STDERR ".*CMake Error at (@CMAKE_CURRENT_SOURCE_DIR@/)?List-Invalid-Subcommand.cmake:1 \\(list\\):.*list does not recognize sub-command NO_SUCH_SUBCOMMAND.*" )
foreach ( cmd Get Insert Remove_At )
set ( ${ cmd } -Invalid-Index-RESULT 1 )
set ( ${ cmd } -Invalid-Index-STDERR ".*CMake Error at (@CMAKE_CURRENT_SOURCE_DIR@/)?List-${cmd}-Invalid-Index.cmake:2 \\(list\\):.*list index: 3 out of range \\(-3, 2\\).*" )
endforeach ( )
foreach ( cmd Remove_Item Reverse Remove_Duplicates Sort Remove_At )
string ( TOUPPER ${ cmd } Cmd )
set ( ${ cmd } -Nonexistent-List-RESULT 1 )
set ( ${ cmd } -Nonexistent-List-STDERR ".*CMake Error at (@CMAKE_CURRENT_SOURCE_DIR@/)?List-${cmd}-Nonexistent-List.cmake:2 \\(list\\):.*sub-command ${Cmd} requires list to be present.*" )
endforeach ( )
2012-09-29 15:02:38 +04:00
2012-09-30 12:44:18 +04:00
set ( Get-CMP0007-Warn-RESULT 0 )
set ( Get-CMP0007-Warn-STDERR ".*CMake Warning \\(dev\\) at (@CMAKE_CURRENT_SOURCE_DIR@/)?List-Get-CMP0007-Warn.cmake:3 \\(list\\):.*Policy CMP0007 is not set:.*" )
2012-09-29 15:02:38 +04:00
check_cmake_test ( List
N o - A r g u m e n t s
L e n g t h - T o o - M a n y - A r g u m e n t s
R e v e r s e - T o o - M a n y - A r g u m e n t s
R e m o v e _ D u p l i c a t e s - T o o - M a n y - A r g u m e n t s
S o r t - T o o - M a n y - A r g u m e n t s
2012-09-29 16:41:07 +04:00
I n v a l i d - S u b c o m m a n d
G e t - I n v a l i d - I n d e x
I n s e r t - I n v a l i d - I n d e x
R e m o v e _ I t e m - N o n e x i s t e n t - L i s t
R e v e r s e - N o n e x i s t e n t - L i s t
R e m o v e _ D u p l i c a t e s - N o n e x i s t e n t - L i s t
S o r t - N o n e x i s t e n t - L i s t
R e m o v e _ A t - N o n e x i s t e n t - L i s t
R e m o v e _ A t - I n v a l i d - I n d e x
2012-09-30 12:44:18 +04:00
G e t - C M P 0 0 0 7 - W a r n
2012-09-29 15:02:38 +04:00
)
2012-09-30 12:44:18 +04:00
set ( thelist "" NEW OLD )
foreach ( _pol ${ thelist } )
cmake_policy ( SET CMP0007 ${ _pol } )
list ( GET thelist 1 thevalue )
if ( NOT thevalue STREQUAL _pol )
message ( SEND_ERROR "returned element '${thevalue}', but expected '${_pol}'" )
endif ( )
endforeach ( _pol )