Skip to content

Commit

Permalink
WIP: Add unit tests for TRIBITS_REPORT_INVALID_TRIBITS_USAGE() (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
bartlettroscoe committed May 8, 2019
1 parent f27828f commit e7e1509
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 4 deletions.
2 changes: 1 addition & 1 deletion test/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ TRIBITS_ADD_ADVANCED_TEST( TestingFunctionMacro_UnitTests
-D${PROJECT_NAME}_TRIBITS_DIR=${${PROJECT_NAME}_TRIBITS_DIR}
-P "${CMAKE_CURRENT_SOURCE_DIR}/TestingFunctionMacro_UnitTests.cmake"
PASS_REGULAR_EXPRESSION_ALL
"Final UnitTests Result: num_run = 544"
"Final UnitTests Result: num_run = 550"
"Final UnitTests Result: PASSED"
)

Expand Down
57 changes: 56 additions & 1 deletion test/core/TestingFunctionMacro_UnitTests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ INCLUDE(TribitsStripQuotesFromStr)
INCLUDE(TribitsStandardizePaths)
INCLUDE(TribitsGetVersionDate)
INCLUDE(TribitsTplFindIncludeDirsAndLibraries)
INCLUDE(TribitsReportInvalidTribitsUsage)
INCLUDE(UnitTestHelpers)
INCLUDE(GlobalSet)
INCLUDE(GlobalNullSet)
Expand Down Expand Up @@ -556,6 +557,59 @@ FUNCTION(UNITTEST_TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE)
ENDFUNCTION()


FUNCTION(UNITTEST_TRIBITS_REPORT_INVALID_TRIBITS_USAGE)

MESSAGE("\n***")
MESSAGE("*** Testing TRIBITS_REPORT_INVALID_TRIBITS_USAGE()")
MESSAGE("***\n")

SET(MESSAGE_WRAPPER_UNIT_TEST_MODE TRUE)
SET(PROJECT_NAME TRITU_PROJECT)

MESSAGE("TRIBITS_REPORT_INVALID_TRIBITS_USAGE(): Default (FATAL_ERROR)")
GLOBAL_SET(MESSAGE_WRAPPER_INPUT)
TRIBITS_REPORT_INVALID_TRIBITS_USAGE("Something went" " very wrong" " I think 1!")
UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
"FATAL_ERROR;Something went; very wrong; I think 1!")

MESSAGE("TRIBITS_REPORT_INVALID_TRIBITS_USAGE(): FATAL_ERROR")
GLOBAL_SET(MESSAGE_WRAPPER_INPUT)
SET(${PROJECT_NAME}_ASSERT_CORRECT_TRIBITS_USAGE FATAL_ERROR)
TRIBITS_REPORT_INVALID_TRIBITS_USAGE("Something went" " very wrong" " I think 2!")
UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
"FATAL_ERROR;Something went; very wrong; I think 2!")

MESSAGE("TRIBITS_REPORT_INVALID_TRIBITS_USAGE(): SEND_ERROR")
GLOBAL_SET(MESSAGE_WRAPPER_INPUT)
SET(${PROJECT_NAME}_ASSERT_CORRECT_TRIBITS_USAGE SEND_ERROR)
TRIBITS_REPORT_INVALID_TRIBITS_USAGE("Something went very wrong I think 3!")
UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
"SEND_ERROR;Something went very wrong I think 3!")

MESSAGE("TRIBITS_REPORT_INVALID_TRIBITS_USAGE(): WARNING")
GLOBAL_SET(MESSAGE_WRAPPER_INPUT)
SET(${PROJECT_NAME}_ASSERT_CORRECT_TRIBITS_USAGE WARNING)
TRIBITS_REPORT_INVALID_TRIBITS_USAGE("Something went very wrong I think 4!")
UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
"WARNING;Something went very wrong I think 4!")

MESSAGE("TRIBITS_REPORT_INVALID_TRIBITS_USAGE(): IGNORE")
GLOBAL_SET(MESSAGE_WRAPPER_INPUT)
SET(${PROJECT_NAME}_ASSERT_CORRECT_TRIBITS_USAGE IGNORE)
TRIBITS_REPORT_INVALID_TRIBITS_USAGE("Something went very wrong I think 5!")
UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
"")

MESSAGE("TRIBITS_REPORT_INVALID_TRIBITS_USAGE(): INVALID_ARGUMENT")
GLOBAL_SET(MESSAGE_WRAPPER_INPUT)
SET(${PROJECT_NAME}_ASSERT_CORRECT_TRIBITS_USAGE INVALID_ARGUMENT)
TRIBITS_REPORT_INVALID_TRIBITS_USAGE("Something went very wrong I think 6!")
UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
"FATAL_ERROR;Error, invalid value for; TRITU_PROJECT_ASSERT_CORRECT_TRIBITS_USAGE =; 'INVALID_ARGUMENT'!; Value values include 'FATAL_ERROR', 'SEND_ERROR', 'WARNING', and 'IGNORE'!")

ENDFUNCTION()


FUNCTION(UNITEST_TRIBITS_ADD_TEST_BASIC)

MESSAGE("\n***")
Expand Down Expand Up @@ -3590,6 +3644,7 @@ UNITEST_TRIBITS_STRIP_QUOTES_FROM_STR()
UNITEST_TRIBITS_GET_VERSION_DATE_FROM_RAW_GIT_COMMIT_UTC_TIME()
UNITEST_TRIBITS_GET_RAW_GIT_COMMIT_UTC_TIME()
UNITTEST_TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE()
UNITTEST_TRIBITS_REPORT_INVALID_TRIBITS_USAGE()

# Set the default test categories
SET(${PROJECT_NAME}_TEST_CATEGORIES NIGHTLY)
Expand Down Expand Up @@ -3641,4 +3696,4 @@ MESSAGE("*** Determine final result of all unit tests")
MESSAGE("***\n")

# Pass in the number of expected tests that must pass!
UNITTEST_FINAL_RESULT(544)
UNITTEST_FINAL_RESULT(550)
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ ELSE()
SET(__TribitsReportInvalidTribitsUsage_INCLUDED__ TRUE)
ENDIF()

INCLUDE(MessageWrapper)

# Called to report incorrect usage
#
# Usage:
Expand Down Expand Up @@ -74,12 +76,12 @@ FUNCTION(TRIBITS_REPORT_INVALID_TRIBITS_USAGE)
ELSEIF (${PROJECT_NAME}_ASSERT_CORRECT_TRIBITS_USAGE STREQUAL "IGNORE")
SET(PRINT_ERR_MSG)
ELSE()
MESSAGE(FATAL_ERROR "Error, invalid value for"
MESSAGE_WRAPPER(FATAL_ERROR "Error, invalid value for"
" ${PROJECT_NAME}_ASSERT_CORRECT_TRIBITS_USAGE ="
" '${${PROJECT_NAME}_ASSERT_CORRECT_TRIBITS_USAGE}'!"
" Value values include 'FATAL_ERROR', 'SEND_ERROR', 'WARNING', and 'IGNORE'!")
ENDIF()
IF (PRINT_ERR_MSG)
MESSAGE(${PRINT_ERR_MSG} ${ARGN})
MESSAGE_WRAPPER(${PRINT_ERR_MSG} ${ARGN})
ENDIF()
ENDFUNCTION()

0 comments on commit e7e1509

Please sign in to comment.