Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Tests / ReturnTest / CMakeLists.txt
blob7c9156bf831ceb18189034f14fcaa3817e47578f
1 # a simple C only test case
2 cmake_minimum_required (VERSION 2.6)
3 project (ReturnTest)
5 set (CMAKE_C_FLAGS "${CMAKE_ANSI_CFLAGS} ${CMAKE_C_FLAGS}")
7 function (FAILED testname)
8   message (SEND_ERROR "${testname} failed ${ARGN}")
9 endfunction (FAILED)
11 function (PASS testname)
12   message ("${testname} passed ${ARGN}")
13 endfunction (PASS)
15 # test simple return
16 function (simple)
17   set(simpleResult 1 PARENT_SCOPE)
18   return()
19   set(simpleResult 0 PARENT_SCOPE)
20 endfunction (simple)
21 simple()
22 if ("${simpleResult}")
23   pass ("simple")
24 else ("${simpleResult}")
25   failed ("simple got: ${simpleResult}")
26 endif ("${simpleResult}")
28 #test return in an if statement
29 set (simple2IF 1)
30 function (simple2)
31   set(simple2Result 1 PARENT_SCOPE)
32   if (simple2IF)
33     return()
34   endif (simple2IF)
35   set(simple2Result 0 PARENT_SCOPE)
36 endfunction (simple2)
37 simple2()
38 if ("${simple2Result}")
39   pass ("simple2")
40 else ("${simple2Result}")
41   failed ("simple2 got: ${simple2Result}")
42 endif ("${simple2Result}")
44 #test return in a foreach loop
45 function (looptest)
46   foreach (iter RANGE 1 5)
47     set (looptestResult "${iter}" PARENT_SCOPE)
48     if ("${iter}" EQUAL 3)
49       return ()
50     endif ("${iter}" EQUAL 3)
51   endforeach (iter)
52 endfunction (looptest)
53 looptest()
54 if ("${looptestResult}" EQUAL 3)
55   pass ("looptest")
56 else ("${looptestResult}" EQUAL 3)
57   failed ("looptest got: ${looptestResult}")
58 endif ("${looptestResult}" EQUAL 3)
60 #test return in a while loop
61 function (whiletest)
62   set (iter "a")
63   while(NOT "${iter}" STREQUAL "aaaaa")
64     set (whiletestResult "${iter}" PARENT_SCOPE)
65     if ("${iter}" STREQUAL "aaa")
66       return ()
67     endif ("${iter}" STREQUAL "aaa")
68     set (iter "${iter}a")
69   endwhile(NOT "${iter}" STREQUAL "aaaaa")
70 endfunction (whiletest)
71 whiletest()
72 if ("${whiletestResult}" STREQUAL "aaa")
73   pass ("whiletest")
74 else ("${whiletestResult}" STREQUAL "aaa")
75   failed ("whiletest got: ${whiletestResult}")
76 endif ("${whiletestResult}" STREQUAL "aaa")
78 # check subdir return
79 add_subdirectory(subdir)
80 get_directory_property(subdirResult DIRECTORY subdir DEFINITION subdirreturn)
81 if ("${subdirResult}" EQUAL 1)
82   pass ("subdir")
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
96 macro (mymacro)
97   set (foo 1)
98   if (foo)
99     return()
100   endif (foo)
101 endmacro(mymacro)
103 # test simple return
104 function (simple3)
105   set (bar 0)
106   set(simple3Result 1 PARENT_SCOPE)
107   if (bar)
108   else (bar)
109     mymacro()
110   endif(bar)
111   set(simple3Result 0 PARENT_SCOPE)
112 endfunction (simple3)
113 simple3()
114 if ("${simple3Result}")
115   pass ("macrotest")
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)
125     break ()
126   endif ("${iter}" EQUAL 3)
127 endforeach (iter)
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
135 set (iter "a")
136 while(NOT "${iter}" STREQUAL "aaaaa")
137   if ("${iter}" STREQUAL "aaa")
138     break ()
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)