Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error message when forgetting a name and fix bug with expectfail not working with unit names with special characters #100

Merged
merged 2 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion cmake/cmake_test/expectfail_subprocess.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function(ct_expectfail_subprocess _es_curr_section_instance)
endforeach()

# Append this section's ID definition so it is executed
list(APPEND _es_section_id_defines "set(${_es_section_friendly_name} \"${_es_section_id}\")")
list(APPEND _es_section_id_defines "set([[${_es_section_friendly_name}]] \"${_es_section_id}\")")

# Replace list delimiters with newlines for full call list
string (REGEX REPLACE "(^|[^\\\\]);" "\\1\n" _es_section_id_defines "${_es_section_id_defines}")
Expand Down
6 changes: 3 additions & 3 deletions cmake/cmake_test/templates/expectfail.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

cmake_minimum_required(VERSION @_ct_min_cmake_version@) #Required for FetchContent_MakeAvailable()

project(@_es_section_file@ LANGUAGES C) #Needed so dummy libraries don't complain about not having a linkage language
project([[@_es_section_file@]] LANGUAGES C) #Needed so dummy libraries don't complain about not having a linkage language


#Enable colors in Unix environments, ignored on Windows. Will not work with pipes
Expand All @@ -30,12 +30,12 @@ ct_register_exception_handler()
@_es_section_id_defines@

# Set the expect fail target unit so all children can be correctly executed
cpp_set_global("CT_EXPECTFAIL_TGT" "@_es_section_id@")
cpp_set_global("CT_EXPECTFAIL_TGT" [[@_es_section_id@]])

set(CMAKEPP_LANG_DEBUG_MODE "@CMAKEPP_LANG_DEBUG_MODE@")

#Include root file
include("@_es_section_file@")
include([[@_es_section_file@]])

#Execute the only test there is, ignoring subsections that do not comprise the call tree
ct_exec_tests()
2 changes: 1 addition & 1 deletion cmake/cmake_test/templates/lists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ cpp_set_global("CT_DEBUG_MODE" "@ct_debug_mode@")
include("cmake_test/cmake_test")
set(CMAKEPP_LANG_DEBUG_MODE "@CMAKEPP_LANG_DEBUG_MODE@")

include("@_ad_test_file@")
include([[@_ad_test_file@]])
ct_exec_tests()
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
Loading