CMakeParseArguments: add a RunCMake test suite

This commit is contained in:
Matthias Maennich 2015-12-05 18:57:41 +01:00 committed by Brad King
parent 2913876c58
commit cbbdfc2b61
11 changed files with 185 additions and 0 deletions

View File

@ -177,6 +177,7 @@ add_RunCMake_test(build_command)
add_RunCMake_test(execute_process)
add_RunCMake_test(export)
add_RunCMake_test(cmake_minimum_required)
add_RunCMake_test(cmake_parse_arguments)
add_RunCMake_test(continue)
add_RunCMake_test(ctest_build)
add_RunCMake_test(ctest_configure)

View File

@ -0,0 +1,3 @@
cmake_minimum_required(VERSION 3.4)
project(${RunCMake_TEST} NONE)
include(${RunCMake_TEST}.cmake)

View File

@ -0,0 +1,16 @@
include(${CMAKE_CURRENT_LIST_DIR}/test_utils.cmake)
include(CMakeParseArguments)
# example from the documentation
# OPTIONAL is a keyword and therefore terminates the definition of
# the multi-value DEFINITION before even a single value has been added
set(options OPTIONAL FAST)
set(oneValueArgs DESTINATION RENAME)
set(multiValueArgs TARGETS CONFIGURATIONS)
cmake_parse_arguments(MY_INSTALL "${options}" "${oneValueArgs}"
"${multiValueArgs}"
TARGETS foo DESTINATION OPTIONAL)
TEST(MY_INSTALL_DESTINATION UNDEFINED)
TEST(MY_INSTALL_OPTIONAL TRUE)

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,17 @@
CMake Error at Errors.cmake:3 \(cmake_parse_arguments\):
CMAKE_PARSE_ARGUMENTS Function invoked with incorrect arguments for
function named: CMAKE_PARSE_ARGUMENTS
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
+
CMake Error at Errors.cmake:4 \(cmake_parse_arguments\):
CMAKE_PARSE_ARGUMENTS Function invoked with incorrect arguments for
function named: CMAKE_PARSE_ARGUMENTS
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
+
CMake Error at Errors.cmake:5 \(cmake_parse_arguments\):
CMAKE_PARSE_ARGUMENTS Function invoked with incorrect arguments for
function named: CMAKE_PARSE_ARGUMENTS
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)

View File

@ -0,0 +1,6 @@
include(CMakeParseArguments)
cmake_parse_arguments()
cmake_parse_arguments(prefix OPT)
cmake_parse_arguments(prefix OPT SINGLE)
cmake_parse_arguments(prefix OPT SINGLE MULTI) # not an error

View File

@ -0,0 +1,69 @@
include(${CMAKE_CURRENT_LIST_DIR}/test_utils.cmake)
include(CMakeParseArguments)
# unparsed arguments
cmake_parse_arguments(pref "" "" "")
TEST(pref_UNPARSED_ARGUMENTS UNDEFINED)
cmake_parse_arguments(pref "" "" "" FOO)
TEST(pref_UNPARSED_ARGUMENTS "FOO")
cmake_parse_arguments(pref "" "" "" FOO BAR)
TEST(pref_UNPARSED_ARGUMENTS "FOO;BAR")
cmake_parse_arguments(pref "" "" "")
TEST(pref_UNPARSED_ARGUMENTS UNDEFINED)
# options
cmake_parse_arguments(pref "OPT1" "" "")
TEST(pref_OPT1 FALSE)
cmake_parse_arguments(pref "OPT1;OPT2" "" "")
TEST(pref_OPT1 FALSE)
TEST(pref_OPT2 FALSE)
cmake_parse_arguments(pref "OPT1" "" "" OPT1)
TEST(pref_OPT1 TRUE)
cmake_parse_arguments(pref "OPT1;OPT2" "" "" OPT1 OPT2)
TEST(pref_OPT1 TRUE)
TEST(pref_OPT2 TRUE)
cmake_parse_arguments(pref "OPT1;OPT2" "" "")
TEST(pref_OPT1 FALSE)
TEST(pref_OPT2 FALSE)
# single arguments
cmake_parse_arguments(pref "" "SINGLE1" "")
TEST(pref_SINGLE1 UNDEFINED)
cmake_parse_arguments(pref "" "SINGLE1;SINGLE2" "")
TEST(pref_SINGLE1 UNDEFINED)
TEST(pref_SINGLE2 UNDEFINED)
cmake_parse_arguments(pref "" "SINGLE1" "" SINGLE1 foo)
TEST(pref_SINGLE1 foo)
cmake_parse_arguments(pref "" "SINGLE1;SINGLE2" "" SINGLE1 foo SINGLE2 bar)
TEST(pref_SINGLE1 foo)
TEST(pref_SINGLE2 bar)
cmake_parse_arguments(pref "" "SINGLE1;SINGLE2" "")
TEST(pref_SINGLE1 UNDEFINED)
TEST(pref_SINGLE2 UNDEFINED)
# multi arguments
cmake_parse_arguments(pref "" "" "MULTI1")
TEST(pref_MULTI1 UNDEFINED)
cmake_parse_arguments(pref "" "" "MULTI1;MULTI2")
TEST(pref_MULTI1 UNDEFINED)
TEST(pref_MULTI2 UNDEFINED)
cmake_parse_arguments(pref "" "" "MULTI1" MULTI1 foo)
TEST(pref_MULTI1 foo)
cmake_parse_arguments(pref "" "" "MULTI1;MULTI2" MULTI1 foo bar MULTI2 bar foo)
TEST(pref_MULTI1 foo bar)
TEST(pref_MULTI2 bar foo)
cmake_parse_arguments(pref "" "" "MULTI1;MULTI2")
TEST(pref_MULTI1 UNDEFINED)
TEST(pref_MULTI2 UNDEFINED)

View File

@ -0,0 +1,25 @@
include(${CMAKE_CURRENT_LIST_DIR}/test_utils.cmake)
include(CMakeParseArguments)
# specify two keywords for each category and set the first keyword of each
# within ARGN
cmake_parse_arguments(pref "OPT1;OPT2" "SINGLE1;SINGLE2" "MULTI1;MULTI2"
OPT1 SINGLE1 foo MULTI1 bar foo bar)
TEST(pref_OPT1 TRUE)
TEST(pref_OPT2 FALSE)
TEST(pref_SINGLE1 foo)
TEST(pref_SINGLE2 UNDEFINED)
TEST(pref_MULTI1 bar foo bar)
TEST(pref_MULTI2 UNDEFINED)
TEST(pref_UNPARSED_ARGUMENTS UNDEFINED)
# same as above but reversed ARGN
cmake_parse_arguments(pref "OPT1;OPT2" "SINGLE1;SINGLE2" "MULTI1;MULTI2"
MULTI1 bar foo bar SINGLE1 foo OPT1)
TEST(pref_OPT1 TRUE)
TEST(pref_OPT2 FALSE)
TEST(pref_SINGLE1 foo)
TEST(pref_SINGLE2 UNDEFINED)
TEST(pref_MULTI1 bar foo bar)
TEST(pref_MULTI2 UNDEFINED)
TEST(pref_UNPARSED_ARGUMENTS UNDEFINED)

View File

@ -0,0 +1,7 @@
include(RunCMake)
run_cmake(Utils)
run_cmake(Initialization)
run_cmake(Mix)
run_cmake(CornerCases)
run_cmake(Errors)

View File

@ -0,0 +1,20 @@
include(${CMAKE_CURRENT_LIST_DIR}/test_utils.cmake)
# test the TEST macro itself
TEST(asdf UNDEFINED)
SET (asdf FALSE)
TEST(asdf FALSE)
SET (asdf TRUE)
TEST(asdf TRUE)
SET (asdf TRUE)
TEST(asdf TRUE)
SET (asdf "some value")
TEST(asdf "some value")
SET (asdf some list)
TEST(asdf "some;list")

View File

@ -0,0 +1,20 @@
macro(TEST variable)
SET(expected "${ARGN}")
if ( "${expected}" STREQUAL "UNDEFINED" )
if (DEFINED ${variable})
message(FATAL_ERROR "'${variable}' shall be undefined but has value '${${variable}}'")
endif()
elseif( "${expected}" STREQUAL "FALSE" )
if (NOT ${variable} STREQUAL "FALSE")
message(FATAL_ERROR "'${variable}' shall be FALSE")
endif()
elseif( "${expected}" STREQUAL "TRUE" )
if (NOT ${variable} STREQUAL "TRUE")
message(FATAL_ERROR "'${variable}' shall be TRUE")
endif()
else()
if (NOT ${variable} STREQUAL "${expected}")
message(FATAL_ERROR "'${variable}' shall be '${expected}'")
endif()
endif()
endmacro()