CMakeLists.txt 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. # a simple C only test case
  2. cmake_minimum_required (VERSION 2.6)
  3. project (ReturnTest)
  4. function (FAILED testname)
  5. message (SEND_ERROR "${testname} failed ${ARGN}")
  6. endfunction ()
  7. function (PASS testname)
  8. message ("${testname} passed ${ARGN}")
  9. endfunction ()
  10. # test simple return
  11. function (simple)
  12. set(simpleResult 1 PARENT_SCOPE)
  13. return()
  14. set(simpleResult 0 PARENT_SCOPE)
  15. endfunction ()
  16. simple()
  17. if ("${simpleResult}")
  18. pass ("simple")
  19. else ()
  20. failed ("simple got: ${simpleResult}")
  21. endif ()
  22. #test return in an if statement
  23. set (simple2IF 1)
  24. function (simple2)
  25. set(simple2Result 1 PARENT_SCOPE)
  26. if (simple2IF)
  27. return()
  28. endif ()
  29. set(simple2Result 0 PARENT_SCOPE)
  30. endfunction ()
  31. simple2()
  32. if ("${simple2Result}")
  33. pass ("simple2")
  34. else ()
  35. failed ("simple2 got: ${simple2Result}")
  36. endif ()
  37. #test return in a foreach loop
  38. function (looptest)
  39. foreach (iter RANGE 1 5)
  40. set (looptestResult "${iter}" PARENT_SCOPE)
  41. if ("${iter}" EQUAL 3)
  42. return ()
  43. endif ()
  44. endforeach ()
  45. endfunction ()
  46. looptest()
  47. if ("${looptestResult}" EQUAL 3)
  48. pass ("looptest")
  49. else ()
  50. failed ("looptest got: ${looptestResult}")
  51. endif ()
  52. #test return in a while loop
  53. function (whiletest)
  54. set (iter "a")
  55. while(NOT "${iter}" STREQUAL "aaaaa")
  56. set (whiletestResult "${iter}" PARENT_SCOPE)
  57. if ("${iter}" STREQUAL "aaa")
  58. return ()
  59. endif ()
  60. set (iter "${iter}a")
  61. endwhile()
  62. endfunction ()
  63. whiletest()
  64. if ("${whiletestResult}" STREQUAL "aaa")
  65. pass ("whiletest")
  66. else ()
  67. failed ("whiletest got: ${whiletestResult}")
  68. endif ()
  69. # check subdir return
  70. add_subdirectory(subdir)
  71. get_directory_property(subdirResult DIRECTORY subdir DEFINITION subdirreturn)
  72. if ("${subdirResult}" EQUAL 1)
  73. pass ("subdir")
  74. else ()
  75. failed ("subdir got: ${subdirResult}")
  76. endif ()
  77. # check return from a file
  78. include(include_return.cmake)
  79. if ("${include_returnResult}" EQUAL 1)
  80. pass ("include_return")
  81. else ()
  82. failed ("include_return got: ${include_returnResult}")
  83. endif ()
  84. # check return from within a macro
  85. macro (mymacro)
  86. set (foo 1)
  87. if (foo)
  88. return()
  89. endif ()
  90. endmacro()
  91. # test simple return
  92. function (simple3)
  93. set (bar 0)
  94. set(simple3Result 1 PARENT_SCOPE)
  95. if (bar)
  96. else ()
  97. mymacro()
  98. endif()
  99. set(simple3Result 0 PARENT_SCOPE)
  100. endfunction ()
  101. simple3()
  102. if ("${simple3Result}")
  103. pass ("macrotest")
  104. else ()
  105. failed ("macrotest got: ${simple3Result}")
  106. endif ()
  107. # test break command now in a foreach
  108. foreach (iter RANGE 1 5)
  109. set (break1 "${iter}")
  110. if ("${iter}" EQUAL 3)
  111. break ()
  112. endif ()
  113. endforeach ()
  114. if ("${break1}" EQUAL 3)
  115. pass ("break in foreach")
  116. else ()
  117. failed ("break in foreach got: ${break1}")
  118. endif ()
  119. # test break in a while loop
  120. set (iter "a")
  121. while(NOT "${iter}" STREQUAL "aaaaa")
  122. if ("${iter}" STREQUAL "aaa")
  123. break ()
  124. endif ()
  125. set (iter "${iter}a")
  126. endwhile()
  127. if ("${iter}" STREQUAL "aaa")
  128. pass ("break in a while")
  129. else ()
  130. failed ("break in a while got: ${whiletestResult}")
  131. endif ()
  132. add_executable (ReturnTest returnTest.c)