1 # a simple C only test case
2 cmake_minimum_required (VERSION 2.8.12)
5 function(FAILED testname)
6 message(SEND_ERROR "${testname} failed ${ARGN}")
9 function(PASS testname)
10 message("${testname} passed ${ARGN}")
23 FAILED("COUNT Got: ${COUNT}")
28 if("${ARGC}" EQUAL "3")
31 FAILED("ARGC" "Got: ${ARGC}")
37 function(test_argn_function argument)
38 if("${ARGN}" EQUAL "3")
41 FAILED("ARGN" "Got: ${ARGN}")
44 Test_Argn_Function(ignored 3)
46 # test argument naming and raise scope
47 function(track_find_variable cache_variable is_changed)
48 set("${is_changed}" changed PARENT_SCOPE)
50 track_find_variable(testvar is_changed)
51 if ("${is_changed}" STREQUAL changed)
52 pass("same argument name test")
54 fail("same argument name test" "Got: ${is_changed}")
59 if (tester_res STREQUAL "${CMAKE_CURRENT_LIST_FILE}")
60 pass("CMAKE_CURRENT_LIST_FILE test")
62 fail("CMAKE_CURRENT_LIST_FILE test" "Got: ${tester_res}")
67 # test recursion and return via set(... PARENT_SCOPE)
68 function (factorial argument result)
72 math (EXPR temp "${argument} - 1")
73 factorial (${temp} tresult)
74 math (EXPR lresult "${argument}*${tresult}")
76 set ("${result}" "${lresult}" PARENT_SCOPE)
80 if (fresult EQUAL 120)
83 failed ("factorial, computed ${fresult} instead of 120")
89 function(strange_function m)
90 set("${m}" strange_function PARENT_SCOPE)
94 set(second_var "second_var")
95 if("x${var}" STREQUAL "xstrange_function" AND "x${second_var}" STREQUAL "xsecond_var")
96 PASS("Case Test" "(${var} ${second_var})")
98 FAILED("Case test" "(${var} ${second_var})")
101 # test backing up command
102 function(ADD_EXECUTABLE exec)
103 _ADD_EXECUTABLE(mini${exec} ${ARGN})
107 function(undef_var m)
108 set("${m}" PARENT_SCOPE)
111 set(FUNCTION_UNDEFINED 1)
112 undef_var(FUNCTION_UNDEFINED)
113 if(DEFINED FUNCTION_UNDEFINED)
114 FAILED("Function Undefine Test" "(${FUNCTION_UNDEFINED})")
116 PASS("Function Undefine Test" "(${FUNCTION_UNDEFINED})")
119 # Subdirectory scope raise.
120 set(SUBDIR_UNDEFINED 1)
121 add_subdirectory(SubDirScope)
122 if(DEFINED SUBDIR_UNDEFINED)
123 FAILED("Subdir Undefine Test" "(${SUBDIR_UNDEFINED})")
125 PASS("Subdir Undefine Test" "(${SUBDIR_UNDEFINED})")
127 if(DEFINED SUBDIR_DEFINED)
128 PASS("Subdir Define Test" "(${SUBDIR_DEFINED})")
130 FAILED("Subdir Define Test" "(${SUBDIR_DEFINED})")
133 # Test function-scoped directory.
134 function(ADD_SUBDIR2 dir)
135 add_subdirectory("${dir}" "${dir}2")
136 # The parent scope sets in the subdir should be visible here.
137 if(DEFINED SUBDIR_UNDEFINED)
138 FAILED("Subdir Function Undefine Test 1" "(${SUBDIR_UNDEFINED})")
140 PASS("Subdir Function Undefine Test 1" "(${SUBDIR_UNDEFINED})")
142 if(DEFINED SUBDIR_DEFINED)
143 PASS("Subdir Function Define Test 1" "(${SUBDIR_DEFINED})")
145 FAILED("Subdir Function Define Test 1" "(${SUBDIR_DEFINED})")
149 # Reset test variables.
150 set(SUBDIR_UNDEFINED 1)
154 ADD_SUBDIR2(SubDirScope)
156 # The parent scope sets in the subdir should not be visible here.
157 if(DEFINED SUBDIR_UNDEFINED)
158 PASS("Subdir Function Undefine Test 2" "(${SUBDIR_UNDEFINED})")
160 FAILED("Subdir Function Undefine Test 2" "(${SUBDIR_UNDEFINED})")
162 if(DEFINED SUBDIR_DEFINED)
163 FAILED("Subdir Function Define Test 2" "(${SUBDIR_DEFINED})")
165 PASS("Subdir Function Define Test 2" "(${SUBDIR_DEFINED})")
168 add_executable(FunctionTest functionTest.c)
170 # Use the PROJECT_LABEL property: in IDEs, the project label should appear
171 # in the UI rather than the target name. If this were a good test of the
172 # property rather than just a smoke test, it would verify that the label
173 # actually appears in the UI of the IDE... Or at least that the text appears
174 # somewhere in the generated project files.
175 set_property(TARGET miniFunctionTest
176 PROPERTY PROJECT_LABEL "Test de Fonctionnement")