cmake_parse_arguments: Add additional unit tests

Add additional unit tests for some corner cases in argument splitting.
This commit is contained in:
Matthew Woehlke 2016-09-28 15:20:42 -04:00
parent 41291b20f3
commit 66c70cd9f1
5 changed files with 84 additions and 29 deletions

View File

@ -1,15 +1,5 @@
include(${CMAKE_CURRENT_LIST_DIR}/test_utils.cmake)
function(test_multi list)
set(i 0)
foreach(value IN LISTS ${list})
math(EXPR j "${i} + 1")
set(${list}[${i}] "${value}")
TEST(${list}[${i}] "${ARGV${j}}")
set(i ${j})
endforeach()
endfunction()
function(test1)
cmake_parse_arguments(PARSE_ARGV 0
pref "OPT1;OPT2" "SINGLE1;SINGLE2" "MULTI1;MULTI2")
@ -33,7 +23,7 @@ function(test2 arg1)
TEST(pref_OPT2 FALSE)
TEST(pref_SINGLE1 "foo;bar")
TEST(pref_SINGLE2 UNDEFINED)
test_multi(pref_MULTI1 bar "foo;bar")
TEST(pref_MULTI1 bar "foo;bar")
TEST(pref_MULTI2 UNDEFINED)
TEST(pref_UNPARSED_ARGUMENTS UNDEFINED)
endfunction()
@ -43,6 +33,6 @@ function(test3 arg1)
cmake_parse_arguments(PARSE_ARGV 0
pref "" "" "")
test_multi(pref_UNPARSED_ARGUMENTS "foo;bar" dog cat)
TEST(pref_UNPARSED_ARGUMENTS "foo;bar" dog cat)
endfunction()
test3("foo;bar" dog cat)

View File

@ -0,0 +1,53 @@
include(${CMAKE_CURRENT_LIST_DIR}/test_utils.cmake)
function(test1)
cmake_parse_arguments(PARSE_ARGV 0
mpref "" "" "MULTI")
TEST(mpref_MULTI foo "foo\;bar")
cmake_parse_arguments(PARSE_ARGV 1
upref "" "" "MULTI")
TEST(upref_UNPARSED_ARGUMENTS foo "foo\;bar")
endfunction()
test1(MULTI foo "foo\;bar")
function(test2)
cmake_parse_arguments(PARSE_ARGV 0
mpref "" "" "MULTI")
TEST(mpref_MULTI "foo;" "bar;")
cmake_parse_arguments(PARSE_ARGV 1
upref "" "" "MULTI")
TEST(upref_UNPARSED_ARGUMENTS "foo;" "bar;")
endfunction()
test2(MULTI "foo;" "bar;")
function(test3)
cmake_parse_arguments(PARSE_ARGV 0
mpref "" "" "MULTI")
TEST(mpref_MULTI "[foo;]" "bar\\")
cmake_parse_arguments(PARSE_ARGV 1
upref "" "" "MULTI")
TEST(upref_UNPARSED_ARGUMENTS "[foo;]" "bar\\")
endfunction()
test3(MULTI "[foo;]" "bar\\")
function(test4)
cmake_parse_arguments(PARSE_ARGV 0
mpref "" "" "MULTI")
TEST(mpref_MULTI foo "bar;none")
cmake_parse_arguments(PARSE_ARGV 1
upref "" "" "MULTI")
TEST(upref_UNPARSED_ARGUMENTS foo "bar;none")
endfunction()
test4(MULTI foo bar\\ none)

View File

@ -10,3 +10,4 @@ run_cmake(BadArgvN1)
run_cmake(BadArgvN2)
run_cmake(BadArgvN3)
run_cmake(BadArgvN4)
run_cmake(CornerCasesArgvN)

View File

@ -17,4 +17,5 @@ SET (asdf "some value")
TEST(asdf "some value")
SET (asdf some list)
TEST(asdf some list)
TEST(asdf "some;list")

View File

@ -1,5 +1,14 @@
macro(TEST variable)
SET(expected "${ARGN}")
function(TEST variable)
if(ARGC GREATER 2)
set(i 0)
foreach(value IN LISTS ${variable})
math(EXPR j "${i} + 1")
set(${variable}[${i}] "${value}")
TEST(${variable}[${i}] "${ARGV${j}}")
set(i ${j})
endforeach()
else()
set(expected "${ARGN}")
if("${expected}" STREQUAL "UNDEFINED")
if(DEFINED ${variable})
message(FATAL_ERROR "'${variable}' shall be undefined but has value '${${variable}}'")
@ -17,4 +26,5 @@ macro(TEST variable)
message(FATAL_ERROR "'${variable}' shall be '${expected}'")
endif()
endif()
endmacro()
endif()
endfunction()