1 # a simple C only test case
2 cmake_minimum_required (VERSION 2.6)
5 function (FAILED testname)
6 message (SEND_ERROR "${testname} failed ${ARGN}")
9 function (PASS testname)
10 message ("${testname} passed ${ARGN}")
15 set(simpleResult 1 PARENT_SCOPE)
17 set(simpleResult 0 PARENT_SCOPE)
20 if ("${simpleResult}")
23 failed ("simple got: ${simpleResult}")
26 #test return in an if statement
29 set(simple2Result 1 PARENT_SCOPE)
33 set(simple2Result 0 PARENT_SCOPE)
36 if ("${simple2Result}")
39 failed ("simple2 got: ${simple2Result}")
42 #test return in a foreach loop
44 foreach (iter RANGE 1 5)
45 set (looptestResult "${iter}" PARENT_SCOPE)
46 if ("${iter}" EQUAL 3)
52 if ("${looptestResult}" EQUAL 3)
55 failed ("looptest got: ${looptestResult}")
58 #test return in a while loop
61 while(NOT "${iter}" STREQUAL "aaaaa")
62 set (whiletestResult "${iter}" PARENT_SCOPE)
63 if ("${iter}" STREQUAL "aaa")
70 if ("${whiletestResult}" STREQUAL "aaa")
73 failed ("whiletest got: ${whiletestResult}")
77 add_subdirectory(subdir)
78 get_directory_property(subdirResult DIRECTORY subdir DEFINITION subdirreturn)
79 if ("${subdirResult}" EQUAL 1)
82 failed ("subdir got: ${subdirResult}")
85 # check return from a file
86 include(include_return.cmake)
87 if ("${include_returnResult}" EQUAL 1)
88 pass ("include_return")
90 failed ("include_return got: ${include_returnResult}")
93 # check return from within a macro
104 set(simple3Result 1 PARENT_SCOPE)
109 set(simple3Result 0 PARENT_SCOPE)
112 if ("${simple3Result}")
115 failed ("macrotest got: ${simple3Result}")
119 # test break command now in a foreach
120 foreach (iter RANGE 1 5)
121 set (break1 "${iter}")
122 if ("${iter}" EQUAL 3)
126 if ("${break1}" EQUAL 3)
127 pass ("break in foreach")
129 failed ("break in foreach got: ${break1}")
132 # test break in a while loop
134 while(NOT "${iter}" STREQUAL "aaaaa")
135 if ("${iter}" STREQUAL "aaa")
138 set (iter "${iter}a")
140 if ("${iter}" STREQUAL "aaa")
141 pass ("break in a while")
143 failed ("break in a while got: ${whiletestResult}")
147 add_executable (ReturnTest returnTest.c)