diff --git a/test/core/CompilerOptions_UnitTests.cmake b/test/core/CompilerOptions_UnitTests.cmake index 42d20b035..b4996f9e5 100644 --- a/test/core/CompilerOptions_UnitTests.cmake +++ b/test/core/CompilerOptions_UnitTests.cmake @@ -807,10 +807,7 @@ endfunction() # ##################################################################### -# Assume that all unit tests will pass by default -global_set(UNITTEST_OVERALL_PASS TRUE) -global_set(UNITTEST_OVERALL_NUMPASSED 0) -global_set(UNITTEST_OVERALL_NUMRUN 0) +unittest_initialize_vars() # Set common/base options set(PROJECT_NAME "DummyProject") diff --git a/test/core/TestingFunctionMacro_UnitTests.cmake b/test/core/TestingFunctionMacro_UnitTests.cmake index 848010113..e26bdf881 100644 --- a/test/core/TestingFunctionMacro_UnitTests.cmake +++ b/test/core/TestingFunctionMacro_UnitTests.cmake @@ -4360,10 +4360,7 @@ endfunction() set(${PROJECT_NAME}_HOSTNAME testhost.nowhere.com) set(CMAKE_HOST_SYSTEM_NAME UnspecifiedHostSystemName) -# Assume that all unit tests will pass by default -global_set(UNITTEST_OVERALL_PASS TRUE) -global_set(UNITTEST_OVERALL_NUMPASSED 0) -global_set(UNITTEST_OVERALL_NUMRUN 0) +unittest_initialize_vars() # Set up the tribits_add_test(...) and tribits_add_advanced_test() functions # for unit test mode. diff --git a/test/core/TribitsAdjustPackageEnables_UnitTests.cmake b/test/core/TribitsAdjustPackageEnables_UnitTests.cmake index 6e13397ca..e770e8927 100644 --- a/test/core/TribitsAdjustPackageEnables_UnitTests.cmake +++ b/test/core/TribitsAdjustPackageEnables_UnitTests.cmake @@ -441,10 +441,7 @@ endfunction() # ##################################################################### -# Assume that all unit tests will pass by default -global_set(UNITTEST_OVERALL_PASS TRUE) -global_set(UNITTEST_OVERALL_NUMPASSED 0) -global_set(UNITTEST_OVERALL_NUMRUN 0) +unittest_initialize_vars() # A) Test enabled/disable logic unittest_enable_no_packages() diff --git a/test/core/TribitsProcessExtraRepositoriesList_UnitTests.cmake b/test/core/TribitsProcessExtraRepositoriesList_UnitTests.cmake index 359c5cbdd..b936de563 100644 --- a/test/core/TribitsProcessExtraRepositoriesList_UnitTests.cmake +++ b/test/core/TribitsProcessExtraRepositoriesList_UnitTests.cmake @@ -568,10 +568,7 @@ endfunction() # ##################################################################### -# Assume that all unit tests will pass by default -global_set(UNITTEST_OVERALL_PASS TRUE) -global_set(UNITTEST_OVERALL_NUMPASSED 0) -global_set(UNITTEST_OVERALL_NUMRUN 0) +unittest_initialize_vars() # Set common/base options set(PROJECT_NAME "DummyProject") diff --git a/test/core/TribitsProcessPackagesAndDirsLists_UnitTests.cmake b/test/core/TribitsProcessPackagesAndDirsLists_UnitTests.cmake index d8186aa26..3f805243c 100644 --- a/test/core/TribitsProcessPackagesAndDirsLists_UnitTests.cmake +++ b/test/core/TribitsProcessPackagesAndDirsLists_UnitTests.cmake @@ -221,10 +221,7 @@ endfunction() # ##################################################################### -# Assume that all unit tests will pass by default -global_set(UNITTEST_OVERALL_PASS TRUE) -global_set(UNITTEST_OVERALL_NUMPASSED 0) -global_set(UNITTEST_OVERALL_NUMRUN 0) +unittest_initialize_vars() # Set common/base options set(PROJECT_NAME "DummyProject") diff --git a/test/core/TribitsReadAllProjectDepsFilesCreateDepsGraph_UnitTests.cmake b/test/core/TribitsReadAllProjectDepsFilesCreateDepsGraph_UnitTests.cmake index 305884974..dfdd76a78 100644 --- a/test/core/TribitsReadAllProjectDepsFilesCreateDepsGraph_UnitTests.cmake +++ b/test/core/TribitsReadAllProjectDepsFilesCreateDepsGraph_UnitTests.cmake @@ -738,10 +738,7 @@ endfunction() # ################################################################################ -# Assume that all unit tests will pass by default -global_set(UNITTEST_OVERALL_PASS TRUE) -global_set(UNITTEST_OVERALL_NUMPASSED 0) -global_set(UNITTEST_OVERALL_NUMRUN 0) +unittest_initialize_vars() # Unit tests for code macros that are used to declare/define dependencies unitest_tribits_define_repository_packages_dirs_classifications_empty() diff --git a/test/core/TribitsWriteClientExportFiles_UnitTests.cmake b/test/core/TribitsWriteClientExportFiles_UnitTests.cmake index c6c6cfd02..d6591ade3 100644 --- a/test/core/TribitsWriteClientExportFiles_UnitTests.cmake +++ b/test/core/TribitsWriteClientExportFiles_UnitTests.cmake @@ -245,10 +245,7 @@ endfunction() # ##################################################################### -# Assume that all unit tests will pass by default -global_set(UNITTEST_OVERALL_PASS TRUE) -global_set(UNITTEST_OVERALL_NUMPASSED 0) -global_set(UNITTEST_OVERALL_NUMRUN 0) +unittest_initialize_vars() # # Run the unit tests diff --git a/test/ctest_driver/CTestDriverUnitTests.cmake b/test/ctest_driver/CTestDriverUnitTests.cmake index 96aacb6bf..d81d299e7 100644 --- a/test/ctest_driver/CTestDriverUnitTests.cmake +++ b/test/ctest_driver/CTestDriverUnitTests.cmake @@ -138,10 +138,7 @@ endfunction() # Execute the unit tests # -# Assume that all unit tests will pass by default -global_set(UNITTEST_OVERALL_PASS TRUE) -global_set(UNITTEST_OVERALL_NUMPASSED 0) -global_set(UNITTEST_OVERALL_NUMRUN 0) +unittest_initialize_vars() # Run the unit test functions unittest_tribits_read_ctest_tag_file() diff --git a/tribits/core/package_arch/TribitsAddAdvancedTest.cmake b/tribits/core/package_arch/TribitsAddAdvancedTest.cmake index dd035e8de..be4914951 100644 --- a/tribits/core/package_arch/TribitsAddAdvancedTest.cmake +++ b/tribits/core/package_arch/TribitsAddAdvancedTest.cmake @@ -945,7 +945,7 @@ function(tribits_add_advanced_test TEST_NAME_IN) set(TEST_SCRIPT_STR "") - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR "\n" "#\n" "# This is a CMake script and must be run as \"cmake -P \"\n" @@ -1187,7 +1187,7 @@ function(tribits_add_advanced_test TEST_NAME_IN) string(REPLACE ";" "," FILES_TO_COPY_COMMA_SEP "${FILES_TO_COPY_COMMA_SEP}" ) # NOTE: Above, we have to replace ';' with ',' or the lower commands - # append_string_var() will replace ';' with ''. This is *not* what we + # string(APPEND ) will replace ';' with ''. This is *not* what we # want. In DriveAdvancedTest.cmake, we will replace the ',' with ';' # again :-) @@ -1234,7 +1234,7 @@ function(tribits_add_advanced_test TEST_NAME_IN) # Write the vars for COPY_FILES_TO_TEST_DIR - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR "\n" "set( TEST_${TEST_CMND_IDX}_COPY_FILES_TO_TEST_DIR" " \"${FILES_TO_COPY_COMMA_SEP}\")\n" @@ -1244,13 +1244,13 @@ function(tribits_add_advanced_test TEST_NAME_IN) "${TEST_CMND_STR}" ) endif() - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR "\n" "set( TEST_${TEST_CMND_IDX}_SOURCE_DIR" " \"${COPY_FILES_TO_TEST_DIR_SOURCE_DIR}\")\n" ) - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR "\n" "set( TEST_${TEST_CMND_IDX}_DEST_DIR" " \"${COPY_FILES_TO_TEST_DIR_DEST_DIR}\")\n" @@ -1263,7 +1263,7 @@ function(tribits_add_advanced_test TEST_NAME_IN) tribits_join_exec_process_set_args( TEST_CMND_STR "${TEST_CMND_ARRAY}" ) #print_var(TEST_CMND_STR) - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR "\n" "set( TEST_${TEST_CMND_IDX}_CMND ${TEST_CMND_STR} )\n" ) @@ -1275,7 +1275,7 @@ function(tribits_add_advanced_test TEST_NAME_IN) endif() if (PARSE_MESSAGE) - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR "\n" "set( TEST_${TEST_CMND_IDX}_MESSAGE \"${PARSE_MESSAGE}\" )\n" ) @@ -1285,25 +1285,25 @@ function(tribits_add_advanced_test TEST_NAME_IN) if ("${PARSE_WORKING_DIRECTORY}" STREQUAL "TEST_NAME") set(PARSE_WORKING_DIRECTORY ${TEST_NAME}) endif() - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR "\n" "set( TEST_${TEST_CMND_IDX}_WORKING_DIRECTORY \"${PARSE_WORKING_DIRECTORY}\" )\n" ) - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR "\n" "set( TEST_${TEST_CMND_IDX}_SKIP_CLEAN_WORKING_DIRECTORY ${PARSE_SKIP_CLEAN_WORKING_DIRECTORY} )\n" ) endif() if (PARSE_OUTPUT_FILE) - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR "\n" "set( TEST_${TEST_CMND_IDX}_OUTPUT_FILE \"${PARSE_OUTPUT_FILE}\" )\n" ) endif() if (PARSE_NO_ECHO_OUTPUT) - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR "\n" "set( TEST_${TEST_CMND_IDX}_NO_ECHO_OUTPUT \"${PARSE_NO_ECHO_OUTPUT}\" )\n" ) @@ -1312,58 +1312,58 @@ function(tribits_add_advanced_test TEST_NAME_IN) # Set up pass/fail if (PARSE_PASS_ANY) - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR "\n" "set( TEST_${TEST_CMND_IDX}_PASS_ANY TRUE )\n" ) elseif (PARSE_STANDARD_PASS_OUTPUT) - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR "\n" "set( TEST_${TEST_CMND_IDX}_PASS_REGULAR_EXPRESSION \"End Result: TEST PASSED\" )\n" ) elseif (PARSE_PASS_REGULAR_EXPRESSION) - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR "\n" "set( TEST_${TEST_CMND_IDX}_PASS_REGULAR_EXPRESSION \"${PARSE_PASS_REGULAR_EXPRESSION}\" )\n" ) elseif (PARSE_PASS_REGULAR_EXPRESSION_ALL) - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR "\n" "set( TEST_${TEST_CMND_IDX}_PASS_REGULAR_EXPRESSION_ALL " ) foreach(REGEX_STR ${PARSE_PASS_REGULAR_EXPRESSION_ALL}) - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR "\"${REGEX_STR}\" " ) endforeach() - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR ")\n" ) endif() if (PARSE_FAIL_REGULAR_EXPRESSION) - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR "\n" "set( TEST_${TEST_CMND_IDX}_FAIL_REGULAR_EXPRESSION \"${PARSE_FAIL_REGULAR_EXPRESSION}\" )\n" ) endif() if (PARSE_ALWAYS_FAIL_ON_NONZERO_RETURN) - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR "\n" "set( TEST_${TEST_CMND_IDX}_ALWAYS_FAIL_ON_NONZERO_RETURN TRUE )\n" ) endif() if (PARSE_ALWAYS_FAIL_ON_ZERO_RETURN) - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR "\n" "set( TEST_${TEST_CMND_IDX}_ALWAYS_FAIL_ON_ZERO_RETURN TRUE )\n" ) endif() if (PARSE_WILL_FAIL) - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR "\n" "set( TEST_${TEST_CMND_IDX}_WILL_FAIL TRUE )\n" ) @@ -1451,7 +1451,7 @@ function(tribits_add_advanced_test TEST_NAME_IN) # F.2) Write the cmake -P script # - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR "\n" "set(PROJECT_NAME ${PROJECT_NAME})\n" "\n" diff --git a/tribits/core/package_arch/TribitsCreateClientTemplateHeaders.cmake b/tribits/core/package_arch/TribitsCreateClientTemplateHeaders.cmake index 3288e28ba..cc2c6ca42 100644 --- a/tribits/core/package_arch/TribitsCreateClientTemplateHeaders.cmake +++ b/tribits/core/package_arch/TribitsCreateClientTemplateHeaders.cmake @@ -128,14 +128,14 @@ function(tribits_create_client_template_headers BASE_DIR) # Create the client header file set(CLIENT_HEADER_STR "") - append_string_var(CLIENT_HEADER_STR + string(APPEND CLIENT_HEADER_STR "#include \"${DECL_HEADER_BASE}${${PARENT_PACKAGE_NAME}_TEMPLATE_DECL_EXT}\"\n" ) if (HAVE_${PARENT_PACKAGE_NAME_UC}_EXPLICIT_INSTANTIATION) set(TEMPLATE_INSTANT_TYPE_NAME "explicit instantiation") else() set(TEMPLATE_INSTANT_TYPE_NAME "implicit instantiation") - append_string_var(CLIENT_HEADER_STR + string(APPEND CLIENT_HEADER_STR "#include \"${DECL_HEADER_BASE}${${PARENT_PACKAGE_NAME}_TEMPLATE_DEF_EXT}\"\n" ) endif() @@ -161,7 +161,7 @@ function(tribits_create_client_template_headers BASE_DIR) # Create the SIERRA BJAM version of the header file foreach(OUTPUT_DIR ${PARSE_ADDITIONAL_OUTPUT_DIRS}) set(EXTERNAL_CLIENT_HEADER_STR "") - append_string_var(EXTERNAL_CLIENT_HEADER_STR + string(APPEND EXTERNAL_CLIENT_HEADER_STR "#include \"${DECL_HEADER_BASE}${${PARENT_PACKAGE_NAME}_TEMPLATE_DECL_EXT}\"\n" "#ifndef HAVE_${PARENT_PACKAGE_NAME_UC}_EXPLICIT_INSTANTIATION\n" "# include \"${DECL_HEADER_BASE}${${PARENT_PACKAGE_NAME}_TEMPLATE_DEF_EXT}\"\n" diff --git a/tribits/core/package_arch/TribitsGlobalMacros.cmake b/tribits/core/package_arch/TribitsGlobalMacros.cmake index 56adf17e0..91c2a6cf4 100644 --- a/tribits/core/package_arch/TribitsGlobalMacros.cmake +++ b/tribits/core/package_arch/TribitsGlobalMacros.cmake @@ -84,7 +84,7 @@ include(TribitsTplDeclareLibraries) # Deprecated # macro(tribits_assert_and_setup_project_and_static_system_vars) - append_string_var(IN_SOURCE_ERROR_COMMON_MSG + string(APPEND IN_SOURCE_ERROR_COMMON_MSG "\nYou must now run something like:\n" " $ cd ${CMAKE_CURRENT_SOURCE_DIR}/\n" " $ rm -r CMakeCache.txt CMakeFiles/" @@ -1312,7 +1312,7 @@ function(tribits_generate_repo_version_file_string PROJECT_REPO_VERSION_FILE_ST tribits_generate_single_repo_version_string( ${CMAKE_CURRENT_SOURCE_DIR} SINGLE_REPO_VERSION) - append_string_var(REPO_VERSION_FILE_STR + string(APPEND REPO_VERSION_FILE_STR "*** Base Git Repo: ${PROJECT_NAME}\n" "${SINGLE_REPO_VERSION}\n" ) @@ -1336,7 +1336,7 @@ function(tribits_generate_repo_version_file_string PROJECT_REPO_VERSION_FILE_ST tribits_generate_single_repo_version_string( "${CMAKE_CURRENT_SOURCE_DIR}/${EXTRAREPO_DIR}" SINGLE_REPO_VERSION) - append_string_var(REPO_VERSION_FILE_STR + string(APPEND REPO_VERSION_FILE_STR "*** Git Repo: ${EXTRAREPO_DIR}\n" "${SINGLE_REPO_VERSION}\n" ) diff --git a/tribits/core/package_arch/TribitsLibraryMacros.cmake b/tribits/core/package_arch/TribitsLibraryMacros.cmake index 7087ebbae..85cbe0184 100644 --- a/tribits/core/package_arch/TribitsLibraryMacros.cmake +++ b/tribits/core/package_arch/TribitsLibraryMacros.cmake @@ -165,7 +165,7 @@ function(tribits_configure_file PACKAGE_NAME_CONFIG_FILE) endif() if (${PARENT_PACKAGE_NAME}_HIDE_DEPRECATED_CODE) - append_string_var(${PARENT_PACKAGE_NAME_UC}_DEPRECATED_DECLARATIONS + string(APPEND ${PARENT_PACKAGE_NAME_UC}_DEPRECATED_DECLARATIONS "\n#define ${PARENT_PACKAGE_NAME_UC}_HIDE_DEPRECATED_CODE") endif() diff --git a/tribits/core/package_arch/TribitsProcessEnabledTpl.cmake b/tribits/core/package_arch/TribitsProcessEnabledTpl.cmake index dd4eece4a..ee5d67598 100644 --- a/tribits/core/package_arch/TribitsProcessEnabledTpl.cmake +++ b/tribits/core/package_arch/TribitsProcessEnabledTpl.cmake @@ -57,13 +57,13 @@ function(tribits_process_enabled_tpl TPL_NAME) # Setup the processing string set(PROCESSING_MSG_STRING "Processing enabled TPL: ${TPL_NAME} (") if (TPL_${TPL_NAME}_ENABLING_PKG) - append_string_var(PROCESSING_MSG_STRING + string(APPEND PROCESSING_MSG_STRING "enabled by ${TPL_${TPL_NAME}_ENABLING_PKG}," ) else() - append_string_var(PROCESSING_MSG_STRING + string(APPEND PROCESSING_MSG_STRING "enabled explicitly," ) endif() - append_string_var(PROCESSING_MSG_STRING + string(APPEND PROCESSING_MSG_STRING " disable with -DTPL_ENABLE_${TPL_NAME}=OFF)" ) # Print the processing header diff --git a/tribits/core/package_arch/TribitsReportInvalidTribitsUsage.cmake b/tribits/core/package_arch/TribitsReportInvalidTribitsUsage.cmake index 4db279fd3..442a4928f 100644 --- a/tribits/core/package_arch/TribitsReportInvalidTribitsUsage.cmake +++ b/tribits/core/package_arch/TribitsReportInvalidTribitsUsage.cmake @@ -37,11 +37,7 @@ # ************************************************************************ # @HEADER -if (__TribitsReportInvalidTribitsUsage_INCLUDED__) - return() -else() - set(__TribitsReportInvalidTribitsUsage_INCLUDED__ TRUE) -endif() +include_guard() include(MessageWrapper) diff --git a/tribits/core/package_arch/TribitsTplFindIncludeDirsAndLibraries.cmake b/tribits/core/package_arch/TribitsTplFindIncludeDirsAndLibraries.cmake index dfcedc290..50c3a2b10 100644 --- a/tribits/core/package_arch/TribitsTplFindIncludeDirsAndLibraries.cmake +++ b/tribits/core/package_arch/TribitsTplFindIncludeDirsAndLibraries.cmake @@ -37,11 +37,7 @@ # ************************************************************************ # @HEADER -if (TribitsTplFindIncludeDirsAndLibraries_INCLUDED) - return() -else() - set(TribitsTplFindIncludeDirsAndLibraries_INCLUDED TRUE) -endif() +include_guard() include(AdvancedSet) include(AppendSet) @@ -54,7 +50,7 @@ include(CMakeParseArguments) include(SetNotFound) include(Split) -# + # @FUNCTION: tribits_tpl_allow_pre_find_package() # # Function that determines if a TriBITS find module file @@ -146,7 +142,6 @@ function(tribits_tpl_allow_pre_find_package TPL_NAME ALLOW_PACKAGE_PREFIND_OUT endfunction() -# # @FUNCTION: tribits_tpl_find_include_dirs_and_libraries() # # Function that sets up cache variables for users to specify where to find a @@ -683,7 +678,6 @@ function(tribits_tpl_find_include_dirs_and_libraries TPL_NAME) endfunction() -# # @FUNCTION: tribits_tpl_tentatively_enable() # # Function that sets up for an optionally enabled TPL that is attempted to be @@ -728,10 +722,8 @@ function(tribits_tpl_tentatively_enable TPL_NAME) endfunction() +# Set find error and print error message # -# Utility macro -# - macro(tribits_tpl_find_include_dirs_and_libraries_handle_fail) set(_${TPL_NAME}_ENABLE_SUCCESS FALSE) global_set(TPL_${TPL_NAME}_NOT_FOUND TRUE) diff --git a/tribits/core/utils/AppendStringVar.cmake b/tribits/core/utils/AppendStringVar.cmake index 63d5cc7b4..5735e56cd 100644 --- a/tribits/core/utils/AppendStringVar.cmake +++ b/tribits/core/utils/AppendStringVar.cmake @@ -55,6 +55,10 @@ include(PrintVar) # If one wants to ignore the meaning of these special characters and are okay # with just adding one string at a time, then use `append_string_var_ext()`_. # +# **DEPRECATED**: Instead, use:: +# +# string(APPEND "" "" ...) +# function(append_string_var STRING_VAR_OUT) #message("APPEND_STRING_VAR: ${STRING_VAR_OUT} {${ARGN}}") concat_strings( STRING_VAR "${${STRING_VAR_OUT}}" ${ARGN} ) diff --git a/tribits/core/utils/DriveAdvancedTest.cmake b/tribits/core/utils/DriveAdvancedTest.cmake index 1950cac80..628b4ed57 100644 --- a/tribits/core/utils/DriveAdvancedTest.cmake +++ b/tribits/core/utils/DriveAdvancedTest.cmake @@ -387,7 +387,7 @@ function(drive_advanced_test) if (CMND_IDX EQUAL 0) set(TEST_NAMES_STR "TEST_0") else() - append_string_var( TEST_NAMES_STR ", TEST_${CMND_IDX}" ) + string(APPEND TEST_NAMES_STR ", TEST_${CMND_IDX}" ) endif() endforeach() message("Running test commands: ${TEST_NAMES_STR}") diff --git a/tribits/core/utils/MessageWrapper.cmake b/tribits/core/utils/MessageWrapper.cmake index 59b17d13a..cf7a0723d 100644 --- a/tribits/core/utils/MessageWrapper.cmake +++ b/tribits/core/utils/MessageWrapper.cmake @@ -37,14 +37,10 @@ # ************************************************************************ # @HEADER -if (MESSAGE_WRAPPER_INCLUDED) - return() -endif() -set(MESSAGE_WRAPPER_INCLUDED TRUE) +include_guard() include(GlobalSet) -# # @FUNCTION: message_wrapper() # # Function that wraps the standard CMake/CTest ``message()`` function call in diff --git a/tribits/core/utils/PrintVar.cmake b/tribits/core/utils/PrintVar.cmake index 7b60a9b0c..bf0290aa1 100644 --- a/tribits/core/utils/PrintVar.cmake +++ b/tribits/core/utils/PrintVar.cmake @@ -37,12 +37,8 @@ # ************************************************************************ # @HEADER -if (PRINT_VAR_INCLUDED) - return() -endif() -set(PRINT_VAR_INCLUDED TRUE) +include_guard() -# # @FUNCTION: print_var() # # Unconditionally print a variable giving its name then value. diff --git a/tribits/core/utils/UnitTestHelpers.cmake b/tribits/core/utils/UnitTestHelpers.cmake index 183d3d949..ce163a35c 100644 --- a/tribits/core/utils/UnitTestHelpers.cmake +++ b/tribits/core/utils/UnitTestHelpers.cmake @@ -41,7 +41,22 @@ include(CMakeParseArguments) include(GlobalSet) +# @MACRO: unittest_initialize_vars() # +# Call to initialize the unit test variables before running unit tests. +# +# Usage:: +# +# unittest_initialize_vars() +# +macro(unittest_initialize_vars) + # Assume that all unit tests will pass by default + global_set(UNITTEST_OVERALL_PASS TRUE) + global_set(UNITTEST_OVERALL_NUMPASSED 0) + global_set(UNITTEST_OVERALL_NUMRUN 0) +endmacro() + + # @FUNCTION: unittest_compare_const() # # Perform a single unit test equality check and update overall test statistics @@ -83,7 +98,102 @@ function(unittest_compare_const VAR_NAME CONST_VAL) endfunction() +# @FUNCTION: unittest_string_block_compare() # +# Compare two string blocks (with multiple newlines '\n') line-by-line and +# print the first line that fails the comparison. +# +# Usage:: +# +# unittest_string_block_compare( +# "" +# ) +# +# This updates the global variables ``UNITTEST_OVERALL_NUMRUN``, +# ``UNITTEST_OVERALL_NUMPASSED``, and ``UNITTEST_OVERALL_PASS`` which are used +# by the unit test harness system to assess overall pass/fail. +# +function(unittest_string_block_compare stringVar stringExpected) + + # Don't ignore empty elements in list() operations (they are very important + # here) + cmake_policy(PUSH) + cmake_policy(SET CMP0007 NEW) + + message("\nCheck: ${stringVar} equals expected string:") + + math( EXPR NUMRUN ${UNITTEST_OVERALL_NUMRUN}+1 ) + global_set(UNITTEST_OVERALL_NUMRUN ${NUMRUN}) + + string(REPLACE "\n" ";" stringList "${${stringVar}}") + string(REPLACE "\n" ";" stringExpectedList "${stringExpected}") + + list(LENGTH stringList stringLen) + list(LENGTH stringExpectedList stringExpectedLen) + + # minLen = min(stringLen, stringExpectedLen) + set(minLen ${stringLen}) + if (stringExpectedLen LESS minLen) + set(minLen ${stringExpectedLen}) + endif() + + set(allMatched TRUE) + set(idx 0) + while (idx LESS minLen) + list(GET stringList ${idx} stringEle) + list(GET stringExpectedList ${idx} stringExpectedEle) + if (NOT stringEle STREQUAL stringExpectedEle) + message( + " Error: Line ${idx} of ${stringVar}:\n" + " '${stringEle}'\n" + " !=\n" + " '${stringExpectedEle}'\n" + " [FAILED]\n" + ) + global_set(UNITTEST_OVERALL_PASS FALSE) + message(WARNING "Stack trace for failed unit test") + set(allMatched FALSED) + break() + endif() + math(EXPR idx "${idx}+1") + endwhile() + + if (NOT allMatched) + # The error handling was already handled above + elseif (NOT stringLen EQUAL stringExpectedLen) + # The lines of the strings matched but one of the strings had more lines + # than the other + if (stringLen GREATER stringExpectedLen) + list(GET stringList ${stringExpectedLen} nextLine) + message( + " Error: ${stringVar} has ${stringLen} lines where expected string has" + "only ${stringExpectedLen} lines and the next extra line is:\n" + " '${nextLine}'\n" + " [FAILED]\n" + ) + elseif (stringExpectedLen GREATER stringLen) + list(GET stringExpectedList ${stringLen} nextLine) + message( + " Error: Expected string has ${stringExpectedLen} lines where ${stringVar} has" + "only ${stringLen} lines and the next extra line is:\n" + " '${nextLine}'\n" + " [FAILED]\n" + ) + endif() + global_set(UNITTEST_OVERALL_PASS FALSE) + message(WARNING "Stack trace for failed unit test") + else() + # The strings matched exactly! + message(" [PASSED]\n") + math( EXPR NUMPASSED ${UNITTEST_OVERALL_NUMPASSED}+1 ) + global_set(UNITTEST_OVERALL_NUMPASSED ${NUMPASSED}) + endif() + + cmake_policy(POP) + +endfunction() + + # @FUNCTION: unittest_string_regex() # # Perform a series regexes of given strings and update overall test statistics. @@ -140,7 +250,6 @@ function(unittest_string_regex INPUT_STRING) endfunction() -# # @FUNCTION: unittest_has_substr_const() # # Check that a given string var contains the given substring and update @@ -187,7 +296,6 @@ function(unittest_has_substr_const VAR_NAME SUBSTR_VAL) endfunction() -# # @FUNCTION: unittest_not_has_substr_const() # # Check that a given string var does **NOT** contains the given substring and @@ -234,7 +342,6 @@ function(unittest_not_has_substr_const VAR_NAME SUBSTR_VAL) endfunction() -# # @FUNCTION: unittest_file_regex() # # Perform a series regexes of given strings and update overall test statistics. @@ -256,7 +363,6 @@ function(unittest_file_regex INPUT_FILE) endfunction() -# # @FUNCTION: unittest_final_result() # # Print final statistics from all tests and assert final pass/fail diff --git a/tribits/ctest_driver/TribitsCTestDriverCoreHelpers.cmake b/tribits/ctest_driver/TribitsCTestDriverCoreHelpers.cmake index 350652e60..ed329adf1 100644 --- a/tribits/ctest_driver/TribitsCTestDriverCoreHelpers.cmake +++ b/tribits/ctest_driver/TribitsCTestDriverCoreHelpers.cmake @@ -394,7 +394,7 @@ macro(enable_only_modified_packages) file(STRINGS ${EXTRAREPO_MODIFIED_FILES_FILE_NAME} EXTRAREPO_MODIFIED_FILES_STR) set(EXTRAREPO_FILES_STR "") foreach(STR_LINE ${EXTRAREPO_MODIFIED_FILES_STR}) - append_string_var(EXTRAREPO_FILES_STR "${EXTRAREPO_DIR}/${STR_LINE}\n") + string(APPEND EXTRAREPO_FILES_STR "${EXTRAREPO_DIR}/${STR_LINE}\n") endforeach() file(APPEND "${MODIFIED_FILES_FILE_NAME}" ${EXTRAREPO_FILES_STR})