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