a167503547995ddd8904abf8c7b2c88471234bf5
[platform/upstream/cmake.git] / Tests / CMakeTests / ListTest.cmake.in
1 macro(TEST command expected)
2   if("x${result}" STREQUAL "x${expected}")
3     #message("TEST \"${command}\" success: \"${result}\" expected: \"${expected}\"")
4   else()
5     message(SEND_ERROR "${CMAKE_CURRENT_LIST_LINE}: TEST \"${command}\" failed: \"${result}\" expected: \"${expected}\"")
6   endif()
7 endmacro()
8
9 set(mylist andy bill ken brad)
10
11 list(LENGTH mylist result)
12 TEST("LENGTH mylist result" "4")
13 list(LENGTH "mylist" result)
14 TEST("LENGTH \"mylist\" result" "4")
15
16 list(LENGTH "nonexiting_list1" result)
17 TEST("LENGTH \"nonexiting_list1\" result" "0")
18
19 list(GET mylist 3 2 1 0 result)
20 TEST("GET mylist 3 2 1 0 result" "brad;ken;bill;andy")
21
22 list(GET mylist 0 item0)
23 list(GET mylist 1 item1)
24 list(GET mylist 2 item2)
25 list(GET mylist 3 item3)
26 set(result "${item3}" "${item0}" "${item1}" "${item2}")
27 TEST("GET individual 3 2 1 0 result" "brad;andy;bill;ken")
28
29 list(GET mylist -1 -2 -3 -4 result)
30 TEST("GET mylist -1 -2 -3 -4 result" "brad;ken;bill;andy")
31
32 list(GET mylist -1 2 -3 0 result)
33 TEST("GET mylist -1 2 -3 0 ${result}" "brad;ken;bill;andy")
34
35 list(GET "nonexiting_list2" 1 result)
36 TEST("GET \"nonexiting_list2\" 1 result" "NOTFOUND")
37
38 set(result andy)
39 list(APPEND result brad)
40 TEST("APPEND result brad" "andy;brad")
41
42 list(APPEND "nonexiting_list3" brad)
43 set(result "${nonexiting_list3}")
44 TEST("APPEND \"nonexiting_list3\" brad" "brad")
45
46 list(INSERT "nonexiting_list4" 0 andy bill brad ken)
47 set(result "${nonexiting_list4}")
48 TEST("APPEND \"nonexiting_list4\" andy bill brad ken" "andy;bill;brad;ken")
49
50 set(result andy brad)
51 list(INSERT result -1 bill ken)
52 TEST("INSERT result -1 bill ken" "andy;bill;ken;brad")
53
54 set(result andy bill brad ken bob)
55 list(REMOVE_ITEM result bob)
56 TEST("REMOVE_ITEM result bob" "andy;bill;brad;ken")
57
58 set(result andy bill bob brad ken peter)
59 list(REMOVE_ITEM result peter bob)
60 TEST("REMOVE_ITEM result peter bob" "andy;bill;brad;ken")
61
62 set(result bob andy bill bob brad ken bob)
63 list(REMOVE_ITEM result bob)
64 TEST("REMOVE_ITEM result bob" "andy;bill;brad;ken")
65
66 set(result andy bill bob brad ken peter)
67 list(REMOVE_AT result 2 -1)
68 TEST("REMOVE_AT result 2 -1" "andy;bill;brad;ken")
69
70 # ken is at index 2, nobody is not in the list so -1 should be returned
71 set(mylist andy bill ken brad)
72 list(FIND mylist ken result)
73 TEST("FIND mylist ken result" "2")
74
75 list(FIND mylist nobody result)
76 TEST("FIND mylist nobody result" "-1")
77
78 set(result ken bill andy brad)
79 list(SORT result)
80 TEST("SORT result" "andy;bill;brad;ken")
81
82 set(result andy bill brad ken)
83 list(REVERSE result)
84 TEST("REVERSE result" "ken;brad;bill;andy")
85
86 set(result bill andy bill brad ken ken ken)
87 list(REMOVE_DUPLICATES result)
88 TEST("REMOVE_DUPLICATES result" "bill;andy;brad;ken")
89
90 # these commands should just do nothing if the list is already empty
91 set(result "")
92 list(REMOVE_DUPLICATES result)
93 TEST("REMOVE_DUPLICATES empty result" "")
94
95 list(REVERSE result)
96 TEST("REVERSE empty result" "")
97
98 list(SORT result)
99 TEST("SORT empty result" "")