ListTest.cmake.in 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. MACRO(TEST command expected)
  2. IF("x${result}" STREQUAL "x${expected}")
  3. #MESSAGE("TEST \"${command}\" success: \"${result}\" expected: \"${expected}\"")
  4. ELSE("x${result}" STREQUAL "x${expected}")
  5. MESSAGE(SEND_ERROR "${CMAKE_CURRENT_LIST_LINE}: TEST \"${command}\" failed: \"${result}\" expected: \"${expected}\"")
  6. ENDIF("x${result}" STREQUAL "x${expected}")
  7. ENDMACRO(TEST command expected)
  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. LIST(CONTAINS mylist ken result)
  54. TEST("CONTAINS mylist ken result" "TRUE")
  55. LIST(CONTAINS mylist nobody result)
  56. TEST("CONTAINS mylist nobody result" "FALSE")
  57. SET(result ken bill andy brad)
  58. LIST(SORT result)
  59. TEST("SORT result" "andy;bill;brad;ken")
  60. SET(result andy bill brad ken)
  61. LIST(REVERSE result)
  62. TEST("REVERSE result" "ken;brad;bill;andy")