Skip to content

Commit

Permalink
Add helpful error message for when a name is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
AutonomicPerfectionist committed Dec 13, 2023
1 parent 5b46b44 commit d45fb5f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmake/cmake_test/add_section.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions cmake/cmake_test/add_test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 "_")
Expand Down
20 changes: 20 additions & 0 deletions tests/cmake_test/add_section.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d45fb5f

Please sign in to comment.