1 # a simple C only test case
2 cmake_minimum_required (VERSION 2.6)
5 set (CMAKE_C_FLAGS "${CMAKE_ANSI_CFLAGS} ${CMAKE_C_FLAGS}")
7 function (FAILED testname)
8 message (SEND_ERROR "${testname} failed ${ARGN}")
11 function (PASS testname)
12 message ("${testname} passed ${ARGN}")
17 set(simpleResult 1 PARENT_SCOPE)
19 set(simpleResult 0 PARENT_SCOPE)
22 if ("${simpleResult}")
24 else ("${simpleResult}")
25 failed ("simple got: ${simpleResult}")
26 endif ("${simpleResult}")
28 #test return in an if statement
31 set(simple2Result 1 PARENT_SCOPE)
35 set(simple2Result 0 PARENT_SCOPE)
38 if ("${simple2Result}")
40 else ("${simple2Result}")
41 failed ("simple2 got: ${simple2Result}")
42 endif ("${simple2Result}")
44 #test return in a foreach loop
46 foreach (iter RANGE 1 5)
47 set (looptestResult "${iter}" PARENT_SCOPE)
48 if ("${iter}" EQUAL 3)
50 endif ("${iter}" EQUAL 3)
52 endfunction (looptest)
54 if ("${looptestResult}" EQUAL 3)
56 else ("${looptestResult}" EQUAL 3)
57 failed ("looptest got: ${looptestResult}")
58 endif ("${looptestResult}" EQUAL 3)
60 #test return in a while loop
63 while(NOT "${iter}" STREQUAL "aaaaa")
64 set (whiletestResult "${iter}" PARENT_SCOPE)
65 if ("${iter}" STREQUAL "aaa")
67 endif ("${iter}" STREQUAL "aaa")
69 endwhile(NOT "${iter}" STREQUAL "aaaaa")
70 endfunction (whiletest)
72 if ("${whiletestResult}" STREQUAL "aaa")
74 else ("${whiletestResult}" STREQUAL "aaa")
75 failed ("whiletest got: ${whiletestResult}")
76 endif ("${whiletestResult}" STREQUAL "aaa")
79 add_subdirectory(subdir)
80 get_directory_property(subdirResult DIRECTORY subdir DEFINITION subdirreturn)
81 if ("${subdirResult}" EQUAL 1)
83 else ("${subdirResult}" EQUAL 1)
84 failed ("subdir got: ${subdirResult}")
85 endif ("${subdirResult}" EQUAL 1)
87 # check return from a file
88 include(include_return.cmake)
89 if ("${include_returnResult}" EQUAL 1)
90 pass ("include_return")
91 else ("${include_returnResult}" EQUAL 1)
92 failed ("include_return got: ${include_returnResult}")
93 endif ("${include_returnResult}" EQUAL 1)
95 # check return from within a macro
106 set(simple3Result 1 PARENT_SCOPE)
111 set(simple3Result 0 PARENT_SCOPE)
112 endfunction (simple3)
114 if ("${simple3Result}")
116 else ("${simple3Result}")
117 failed ("macrotest got: ${simple3Result}")
118 endif ("${simple3Result}")
121 # test break command now in a foreach
122 foreach (iter RANGE 1 5)
123 set (break1 "${iter}")
124 if ("${iter}" EQUAL 3)
126 endif ("${iter}" EQUAL 3)
128 if ("${break1}" EQUAL 3)
129 pass ("break in foreach")
130 else ("${break1}" EQUAL 3)
131 failed ("break in foreach got: ${break1}")
132 endif ("${break1}" EQUAL 3)
134 # test break in a while loop
136 while(NOT "${iter}" STREQUAL "aaaaa")
137 if ("${iter}" STREQUAL "aaa")
139 endif ("${iter}" STREQUAL "aaa")
140 set (iter "${iter}a")
141 endwhile(NOT "${iter}" STREQUAL "aaaaa")
142 if ("${iter}" STREQUAL "aaa")
143 pass ("break in a while")
144 else ("${iter}" STREQUAL "aaa")
145 failed ("break in a whi;e got: ${whiletestResult}")
146 endif ("${iter}" STREQUAL "aaa")
149 add_executable (ReturnTest returnTest.c)