ListTest.cmake.in 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. set(mylist andy bill ken brad)
  9. list(LENGTH mylist result)
  10. TEST("LENGTH mylist result" "4")
  11. list(LENGTH "mylist" result)
  12. TEST("LENGTH \"mylist\" result" "4")
  13. list(LENGTH "nonexiting_list1" result)
  14. TEST("LENGTH \"nonexiting_list1\" result" "0")
  15. list(GET mylist 3 2 1 0 result)
  16. TEST("GET mylist 3 2 1 0 result" "brad;ken;bill;andy")
  17. list(GET mylist 0 item0)
  18. list(GET mylist 1 item1)
  19. list(GET mylist 2 item2)
  20. list(GET mylist 3 item3)
  21. set(result "${item3}" "${item0}" "${item1}" "${item2}")
  22. TEST("GET individual 3 2 1 0 result" "brad;andy;bill;ken")
  23. list(GET mylist -1 -2 -3 -4 result)
  24. TEST("GET mylist -1 -2 -3 -4 result" "brad;ken;bill;andy")
  25. list(GET mylist -1 2 -3 0 result)
  26. TEST("GET mylist -1 2 -3 0 ${result}" "brad;ken;bill;andy")
  27. list(GET "nonexiting_list2" 1 result)
  28. TEST("GET \"nonexiting_list2\" 1 result" "NOTFOUND")
  29. set(result andy)
  30. list(APPEND result brad)
  31. TEST("APPEND result brad" "andy;brad")
  32. list(APPEND "nonexiting_list3" brad)
  33. set(result "${nonexiting_list3}")
  34. TEST("APPEND \"nonexiting_list3\" brad" "brad")
  35. list(INSERT "nonexiting_list4" 0 andy bill brad ken)
  36. set(result "${nonexiting_list4}")
  37. TEST("APPEND \"nonexiting_list4\" andy bill brad ken" "andy;bill;brad;ken")
  38. set(result andy brad)
  39. list(INSERT result -1 bill ken)
  40. TEST("INSERT result -1 bill ken" "andy;bill;ken;brad")
  41. set(result andy bill brad ken bob)
  42. list(REMOVE_ITEM result bob)
  43. TEST("REMOVE_ITEM result bob" "andy;bill;brad;ken")
  44. set(result andy bill bob brad ken peter)
  45. list(REMOVE_ITEM result peter bob)
  46. TEST("REMOVE_ITEM result peter bob" "andy;bill;brad;ken")
  47. set(result bob andy bill bob brad ken bob)
  48. list(REMOVE_ITEM result bob)
  49. TEST("REMOVE_ITEM result bob" "andy;bill;brad;ken")
  50. set(result andy bill bob brad ken peter)
  51. list(REMOVE_AT result 2 -1)
  52. TEST("REMOVE_AT result 2 -1" "andy;bill;brad;ken")
  53. # ken is at index 2, nobody is not in the list so -1 should be returned
  54. set(mylist andy bill ken brad)
  55. list(FIND mylist ken result)
  56. TEST("FIND mylist ken result" "2")
  57. list(FIND mylist nobody result)
  58. TEST("FIND mylist nobody result" "-1")
  59. set(result ken bill andy brad)
  60. list(SORT result)
  61. TEST("SORT result" "andy;bill;brad;ken")
  62. set(result andy bill brad ken)
  63. list(REVERSE result)
  64. TEST("REVERSE result" "ken;brad;bill;andy")
  65. set(result bill andy bill brad ken ken ken)
  66. list(REMOVE_DUPLICATES result)
  67. TEST("REMOVE_DUPLICATES result" "bill;andy;brad;ken")
  68. # these commands should just do nothing if the list is already empty
  69. set(result "")
  70. list(REMOVE_DUPLICATES result)
  71. TEST("REMOVE_DUPLICATES empty result" "")
  72. list(REVERSE result)
  73. TEST("REVERSE empty result" "")
  74. list(SORT result)
  75. TEST("SORT empty result" "")