diff --git a/cmake/cmake_test/add_section.cmake b/cmake/cmake_test/add_section.cmake index d21e027..fd50aa7 100644 --- a/cmake/cmake_test/add_section.cmake +++ b/cmake/cmake_test/add_section.cmake @@ -119,9 +119,15 @@ function(ct_add_section) set(_as_options EXPECTFAIL) set(_as_one_value_args NAME PRINT_LENGTH) set(_as_multi_value_args "") + unset(CT_ADD_SECTION_NAME) cmake_parse_arguments(CT_ADD_SECTION "${_as_options}" "${_as_one_value_args}" "${_as_multi_value_args}" ${ARGN} ) + + if(NOT DEFINED CT_ADD_SECTION_NAME OR CT_ADD_SECTION_NAME STREQUAL "") + cpp_raise(CT_INVALID_NAME_ERROR "A section was not given a name. Use the NAME keyword argument to provide a non-empty string name.") + endif() + # This is to set a default value for the print length # argument to prevent any weird empty strings from getting through if(NOT DEFINED CT_ADD_SECTION_PRINT_LENGTH) diff --git a/cmake/cmake_test/add_test.cmake b/cmake/cmake_test/add_test.cmake index 4192903..a4b82bb 100644 --- a/cmake/cmake_test/add_test.cmake +++ b/cmake/cmake_test/add_test.cmake @@ -98,6 +98,10 @@ macro(ct_add_test) cmake_parse_arguments(CT_ADD_TEST "${_at_options}" "${_at_one_value_args}" "${_at_multi_value_args}" ${ARGN} ) + if(NOT DEFINED CT_ADD_TEST_NAME OR CT_ADD_TEST_NAME STREQUAL "") + cpp_raise(CT_INVALID_NAME_ERROR "A test was not given a name. Use the NAME keyword argument to provide a non-empty string name.") + endif() + if(_at_exec_expectfail AND ("${${CT_ADD_TEST_NAME}}" STREQUAL "" OR "${${CT_ADD_TEST_NAME}}" STREQUAL "_")) set("${CT_ADD_TEST_NAME}" "_") set(CMAKETEST_TEST "_") diff --git a/tests/cmake_test/add_section.cmake b/tests/cmake_test/add_section.cmake index eeaf4e6..16b758c 100644 --- a/tests/cmake_test/add_section.cmake +++ b/tests/cmake_test/add_section.cmake @@ -5,6 +5,26 @@ ct_add_test(NAME test_add_section_top_level) function(${test_add_section_top_level}) + + ct_add_section(NAME signature) + function(${CMAKETEST_SECTION}) + ct_add_section(NAME [[No name keyword]] EXPECTFAIL) + function(${CMAKETEST_SECTION}) + ct_add_section([[Ignored the NAME keyword]]) + function(${CMAKETEST_SECTION}) + + endfunction() + endfunction() + + ct_add_section(NAME [[No name value]] EXPECTFAIL) + function(${CMAKETEST_SECTION}) + ct_add_section(NAME) + function(${CMAKETEST_SECTION}) + + endfunction() + endfunction() + endfunction() + ct_add_section(NAME section_0) function(${section_0}) cpp_set_global(TEST_ADD_SECTION_S0 TRUE)