Commit f4b7ba9c authored by Ken Martin's avatar Ken Martin
Browse files

ENH: add testing for return and break commands

parent 0e69d380
......@@ -46,6 +46,7 @@ IF(BUILD_TESTING)
ADD_TEST_MACRO(LinkLine LinkLine)
ADD_TEST_MACRO(MacroTest miniMacroTest)
ADD_TEST_MACRO(FunctionTest miniFunctionTest)
ADD_TEST_MACRO(ReturnTest ReturnTest)
ADD_TEST_MACRO(Properties Properties)
ADD_TEST_MACRO(Assembler HelloAsm)
ADD_TEST_MACRO(SourceGroups SourceGroups)
# a simple C only test case
project (ReturnTest)
function (FAILED testname)
message (SEND_ERROR "${testname} failed ${ARGN}")
endfunction (FAILED)
function (PASS testname)
message ("${testname} passed ${ARGN}")
endfunction (PASS)
# test simple return
function (simple)
set(simpleResult 1 PARENT_SCOPE)
set(simpleResult 0 PARENT_SCOPE)
endfunction (simple)
if ("${simpleResult}")
pass ("simple")
else ("${simpleResult}")
failed ("simple got: ${simpleResult}")
endif ("${simpleResult}")
#test return in an if statement
set (simple2IF 1)
function (simple2)
set(simple2Result 1 PARENT_SCOPE)
if (simple2IF)
endif (simple2IF)
set(simple2Result 0 PARENT_SCOPE)
endfunction (simple2)
if ("${simple2Result}")
pass ("simple2")
else ("${simple2Result}")
failed ("simple2 got: ${simple2Result}")
endif ("${simple2Result}")
#test return in a foreach loop
function (looptest)
foreach (iter RANGE 1 5)
set (looptestResult "${iter}" PARENT_SCOPE)
if ("${iter}" EQUAL 3)
return ()
endif ("${iter}" EQUAL 3)
endforeach (iter)
endfunction (looptest)
if ("${looptestResult}" EQUAL 3)
pass ("looptest")
else ("${looptestResult}" EQUAL 3)
failed ("looptest got: ${looptestResult}")
endif ("${looptestResult}" EQUAL 3)
#test return in a while loop
function (whiletest)
set (iter "a")
while(NOT "${iter}" STREQUAL "aaaaa")
set (whiletestResult "${iter}" PARENT_SCOPE)
if ("${iter}" STREQUAL "aaa")
return ()
endif ("${iter}" STREQUAL "aaa")
set (iter "${iter}a")
endwhile(NOT "${iter}" STREQUAL "aaaaa")
endfunction (whiletest)
if ("${whiletestResult}" STREQUAL "aaa")
pass ("whiletest")
else ("${whiletestResult}" STREQUAL "aaa")
failed ("whiletest got: ${whiletestResult}")
endif ("${whiletestResult}" STREQUAL "aaa")
# check subdir return
get_directory_property(subdirResult DIRECTORY subdir DEFINITION subdirreturn)
if ("${subdirResult}" EQUAL 1)
pass ("subdir")
else ("${subdirResult}" EQUAL 1)
failed ("subdir got: ${subdirResult}")
endif ("${subdirResult}" EQUAL 1)
# check return from within a macro
macro (mymacro)
set (foo 1)
if (foo)
endif (foo)
# test simple return
function (simple3)
set (bar 0)
set(simple3Result 1 PARENT_SCOPE)
if (bar)
else (bar)
set(simple3Result 0 PARENT_SCOPE)
endfunction (simple3)
if ("${simple3Result}")
pass ("macrotest")
else ("${simple3Result}")
failed ("macrotest got: ${simple3Result}")
endif ("${simple3Result}")
# test break command now in a foreach
foreach (iter RANGE 1 5)
set (break1 "${iter}")
if ("${iter}" EQUAL 3)
break ()
endif ("${iter}" EQUAL 3)
endforeach (iter)
if ("${break1}" EQUAL 3)
pass ("break in foreach")
else ("${break1}" EQUAL 3)
failed ("break in foreach got: ${break1}")
endif ("${break1}" EQUAL 3)
# test break in a while loop
set (iter "a")
while(NOT "${iter}" STREQUAL "aaaaa")
if ("${iter}" STREQUAL "aaa")
break ()
endif ("${iter}" STREQUAL "aaa")
set (iter "${iter}a")
endwhile(NOT "${iter}" STREQUAL "aaaaa")
if ("${iter}" STREQUAL "aaa")
pass ("break in a while")
else ("${iter}" STREQUAL "aaa")
failed ("break in a whi;e got: ${whiletestResult}")
endif ("${iter}" STREQUAL "aaa")
add_executable (ReturnTest returnTest.c)
#include <stdio.h>
int main(int argc, char* argv[])
printf("Running command: %s with %d arguments\n", argv[0], argc);
return 0;
set (subdirreturn 1)
set (subdirreturn 0)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment