# @HEADER
# ************************************************************************
#
#            TriBITS: Tribal Build, Integrate, and Test System
#                    Copyright 2013 Sandia Corporation
#
# Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
# the U.S. Government retains certain rights in this software.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# 3. Neither the name of the Corporation nor the names of the
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# ************************************************************************
# @HEADER

MESSAGE("PROJECT_NAME = ${PROJECT_NAME}")
MESSAGE("${PROJECT_NAME}_TRIBITS_DIR = ${${PROJECT_NAME}_TRIBITS_DIR}")

SET( CMAKE_MODULE_PATH
  "${${PROJECT_NAME}_TRIBITS_DIR}/core/utils"
  "${${PROJECT_NAME}_TRIBITS_DIR}/core/package_arch"
  )

SET(TRIBITS_ADD_EXECUTABLE_UNIT_TESTING ON)

INCLUDE(MessageWrapper)
INCLUDE(TribitsTestCategories)
INCLUDE(TribitsAddTest)
INCLUDE(TribitsAddAdvancedTest)
INCLUDE(TribitsAddExecutableAndTest)
INCLUDE(TribitsETISupport)
INCLUDE(TribitsFindPythonInterp)
INCLUDE(TribitsTplFindIncludeDirsAndLibraries)
INCLUDE(UnitTestHelpers)
INCLUDE(GlobalSet)
INCLUDE(GlobalNullSet)
INCLUDE(AppendStringVar)


#####################################################################
#
# Unit tests for TRIBITS_ADD_XXX(...) CMake commands run as CMake code
#
# This file contains a set of unit tests for the package_arch macros
# TRIBITS_ADD_XXX(...) functions.  These unit tests are written in CMake
# itself.  This is not a very advanced unit testing system and it not that
# easy to work with.  However, it does perform some pretty strong testing and
# is much better than doing nothing.
#
#####################################################################


#
# Set up unit test functions that will be called below to actually run the
# unit tests.
#
# The reason that we use functions is so that we can change variables just
# inside of the functions that have their own variable scoping.  In that way,
# we can keep variables that are set in one unit test from affecting the
# others.
#


FUNCTION(UNITTEST_APPEND_STRING_VAR)

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

  MESSAGE("APPEND_STRING_VAR(): Testing simple concatenation")
  SET(SOME_STRING_VAR "")
  APPEND_STRING_VAR(SOME_STRING_VAR
     "begin\n" )
  APPEND_STRING_VAR(SOME_STRING_VAR
     "middle1" " middile2" " middle3\n" )
  APPEND_STRING_VAR(SOME_STRING_VAR
     "end\n" )
  UNITTEST_COMPARE_CONST(SOME_STRING_VAR
    "begin\nmiddle1 middile2 middle3\nend\n")

  MESSAGE("APPEND_STRING_VAR(): Testing with [] and {} which messes up ;")
  SET(SOME_STRING_VAR "")
  APPEND_STRING_VAR(SOME_STRING_VAR
     "[\n" )
  APPEND_STRING_VAR(SOME_STRING_VAR
     "{middle1" " middile2" " middle3}\n" )
  APPEND_STRING_VAR(SOME_STRING_VAR
     "]\n" )
  UNITTEST_COMPARE_CONST(SOME_STRING_VAR
    "[\n;{middle1; middile2; middle3}\n;]\n")

  MESSAGE("APPEND_STRING_VAR_EXT(): Testing with [] and {} which ignores ;")
  SET(SOME_STRING_VAR "")
  APPEND_STRING_VAR_EXT(SOME_STRING_VAR
     "[\n" )
  APPEND_STRING_VAR_EXT(SOME_STRING_VAR
     "{middle1 middile2 middle3}\n" )
  APPEND_STRING_VAR_EXT(SOME_STRING_VAR
     "]\n" )
  UNITTEST_COMPARE_CONST(SOME_STRING_VAR
    "[\n{middle1 middile2 middle3}\n]\n")

ENDFUNCTION()


FUNCTION(UNITTEST_TRIBITS_FIND_PYTHON_INTERP)

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

  SET(MESSAGE_WRAPPER_UNIT_TEST_MODE  TRUE)
  SET(TRIBITS_FIND_PYTHON_UNITTEST  TRUE)

  MESSAGE("TRIBITS_FIND_PYTHON_INTERP(): ${PROJECT_NAME}_USES_PYTHON=FALSE")
  SET(${PROJECT_NAME}_USES_PYTHON  FALSE)
  GLOBAL_SET(MESSAGE_WRAPPER_INPUT)
  TRIBITS_FIND_PYTHON_INTERP()
  UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
    "-- ;NOTE: Skipping check for Python because; ${PROJECT_NAME}_USES_PYTHON='FALSE'")
  UNITTEST_COMPARE_CONST(FIND_PythonInterp_ARGS
    "")

  MESSAGE("TRIBITS_FIND_PYTHON_INTERP(): ${PROJECT_NAME}_USES_PYTHON=")
  GLOBAL_SET(MESSAGE_WRAPPER_INPUT)
  SET(${PROJECT_NAME}_USES_PYTHON)
  SET(PYTHON_EXECUTABLE_UNITTEST_VAL /path/to/python2.4)
  TRIBITS_FIND_PYTHON_INTERP()
  UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
    "-- ;PYTHON_EXECUTABLE='/path/to/python2.4'")

  MESSAGE("TRIBITS_FIND_PYTHON_INTERP(): ${PROJECT_NAME}_USES_PYTHON=TRUE")
  GLOBAL_SET(MESSAGE_WRAPPER_INPUT)
  SET(${PROJECT_NAME}_USES_PYTHON TRUE)
  GLOBAL_SET(PYTHON_EXECUTABLE_UNITTEST_VAL /path/to/python2.4)
  TRIBITS_FIND_PYTHON_INTERP()
  UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
    "-- ;PYTHON_EXECUTABLE='/path/to/python2.4'")
  UNITTEST_COMPARE_CONST(FIND_PythonInterp_ARGS
    "PythonInterp")

  MESSAGE("TRIBITS_FIND_PYTHON_INTERP(): ${PROJECT_NAME}_REQUIRES_PYTHON=TRUE")
  GLOBAL_SET(MESSAGE_WRAPPER_INPUT)
  SET(${PROJECT_NAME}_USES_PYTHON FALSE)
  SET(${PROJECT_NAME}_REQUIRES_PYTHON TRUE)
  SET(PYTHON_EXECUTABLE_UNITTEST_VAL /path/to/python2.4)
  TRIBITS_FIND_PYTHON_INTERP()
  UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
    "-- ;PYTHON_EXECUTABLE='/path/to/python2.4'")
  UNITTEST_COMPARE_CONST(FIND_PythonInterp_ARGS
    "PythonInterp;REQUIRED")

  MESSAGE("TRIBITS_FIND_PYTHON_INTERP(): PythonInterp_FIND_VERSION=2.3")
  GLOBAL_SET(MESSAGE_WRAPPER_INPUT)
  SET(PythonInterp_FIND_VERSION 2.3)
  SET(PYTHON_EXECUTABLE_UNITTEST_VAL /dummy)
  TRIBITS_FIND_PYTHON_INTERP()
  UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
    "FATAL_ERROR;Error,; PythonInterp_FIND_VERSION=2.3 < 2.6; is not allowed!;-- ;PYTHON_EXECUTABLE='/dummy'")

ENDFUNCTION()


FUNCTION(UNITEST_TRIBITS_MISC)

  MESSAGE("\n***")
  MESSAGE("*** Testing miscellaneous TriBITS macro functionality")
  MESSAGE("***\n")

  MESSAGE("Testing MESSAGE_WRAPPER(...) without capture")
  SET(MESSAGE_WRAPPER_UNIT_TEST_MODE FALSE)
  GLOBAL_SET(MESSAGE_WRAPPER_INPUT "Dummy")
  MESSAGE_WRAPPER("Some message that should get printed and not intercepted")
  UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT "Dummy")

  MESSAGE("Testing MESSAGE_WRAPPER(...) with capture")
  SET(MESSAGE_WRAPPER_UNIT_TEST_MODE TRUE)
  GLOBAL_SET(MESSAGE_WRAPPER_INPUT "Dummy")
  MESSAGE_WRAPPER("Some message that should get intercepted")
  UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT "Dummy;Some message that should get intercepted")

  MESSAGE("Testing FIND_LIST_ELEMENT(${PROJECT_NAME}_VALID_CATEGORIES BASIC ELEMENT_FOUND)")
  FIND_LIST_ELEMENT(${PROJECT_NAME}_VALID_CATEGORIES BASIC ELEMENT_FOUND)
  UNITTEST_COMPARE_CONST(ELEMENT_FOUND "TRUE")

  MESSAGE("Testing FIND_LIST_ELEMENT(${PROJECT_NAME}_VALID_CATEGORIES BADCAT ELEMENT_FOUND)")
  FIND_LIST_ELEMENT(${PROJECT_NAME}_VALID_CATEGORIES BADCAT ELEMENT_FOUND)
  UNITTEST_COMPARE_CONST(ELEMENT_FOUND "FALSE")

  MESSAGE("Testing TRIBITS_GET_INVALID_CATEGORIES( ... BADCAT)")
  TRIBITS_GET_INVALID_CATEGORIES(INVALID_CATEGORIES BADCAT)
  UNITTEST_COMPARE_CONST( INVALID_CATEGORIES "BADCAT" )

  MESSAGE("Testing TRIBITS_GET_INVALID_CATEGORIES( ... BADCAT BASIC)")
  TRIBITS_GET_INVALID_CATEGORIES(INVALID_CATEGORIES BADCAT BASIC)
  UNITTEST_COMPARE_CONST( INVALID_CATEGORIES "BADCAT" )

  MESSAGE("Testing TRIBITS_GET_INVALID_CATEGORIES( ... BASIC BADCAT)")
  TRIBITS_GET_INVALID_CATEGORIES(INVALID_CATEGORIES BASIC BADCAT)
  UNITTEST_COMPARE_CONST( INVALID_CATEGORIES "BADCAT" )

  MESSAGE("Testing TRIBITS_GET_INVALID_CATEGORIES( ... BADCAT1 BADCAT2)")
  TRIBITS_GET_INVALID_CATEGORIES(INVALID_CATEGORIES BADCAT1 BADCAT2)
  UNITTEST_COMPARE_CONST( INVALID_CATEGORIES "BADCAT1;BADCAT2" )

  MESSAGE("Testing TRIBITS_GET_INVALID_CATEGORIES( ... BASIC BADCAT1 NIGHTLY BADCAT2 PERFORMANCE)")
  TRIBITS_GET_INVALID_CATEGORIES(INVALID_CATEGORIES BASIC BADCAT1 NIGHTLY BADCAT2 PERFORMANCE)
  UNITTEST_COMPARE_CONST( INVALID_CATEGORIES "BADCAT1;BADCAT2" )

  MESSAGE("Testing TRIBITS_FILTER_AND_ASSERT_CATEGORIES( ... BADCAT1 BASIC BADCAT2)")
  SET(MESSAGE_WRAPPER_UNIT_TEST_MODE TRUE)
  GLOBAL_SET(MESSAGE_WRAPPER_INPUT)
  SET(CATEGORIES BADCAT1 BASIC BADCAT2)
  TRIBITS_FILTER_AND_ASSERT_CATEGORIES(CATEGORIES)
  SET(MESSAGE_WRAPPER_UNIT_TEST_MODE FALSE)
  UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
    "SEND_ERROR;Error: The categories 'BADCAT1;BADCAT2' are not; in the list of valid categories '${${PROJECT_NAME}_VALID_CATEGORIES_STR}'!")
  UNITTEST_COMPARE_CONST(CATEGORIES "BADCAT1;BASIC;BADCAT2")

  MESSAGE("Testing TRIBITS_FILTER_AND_ASSERT_CATEGORIES( ... BASIC)")
  SET(MESSAGE_WRAPPER_UNIT_TEST_MODE TRUE)
  GLOBAL_SET(MESSAGE_WRAPPER_INPUT "Dummy")
  SET(CATEGORIES BASIC)
  TRIBITS_FILTER_AND_ASSERT_CATEGORIES(CATEGORIES)
  SET(MESSAGE_WRAPPER_UNIT_TEST_MODE FALSE)
  UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT "Dummy")
  UNITTEST_COMPARE_CONST(CATEGORIES "BASIC")

  MESSAGE("Testing TRIBITS_FILTER_AND_ASSERT_CATEGORIES( ... BASIC NIGHTLY)")
  SET(MESSAGE_WRAPPER_UNIT_TEST_MODE TRUE)
  GLOBAL_SET(MESSAGE_WRAPPER_INPUT "Dummy")
  SET(CATEGORIES BASIC NIGHTLY)
  TRIBITS_FILTER_AND_ASSERT_CATEGORIES(CATEGORIES)
  SET(MESSAGE_WRAPPER_UNIT_TEST_MODE FALSE)
  UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT "Dummy")
  UNITTEST_COMPARE_CONST(CATEGORIES "BASIC;NIGHTLY")

  MESSAGE("Testing TRIBITS_FILTER_AND_ASSERT_CATEGORIES( ... BASIC WEEKLY NIGHTLY)")
  SET(MESSAGE_WRAPPER_UNIT_TEST_MODE TRUE)
  GLOBAL_SET(MESSAGE_WRAPPER_INPUT "")
  SET(CATEGORIES BASIC WEEKLY NIGHTLY)
  TRIBITS_FILTER_AND_ASSERT_CATEGORIES(CATEGORIES)
  SET(MESSAGE_WRAPPER_UNIT_TEST_MODE FALSE)
  UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
    "WARNING;Warning: The test category 'WEEKLY' is deprecated; and is replaced with 'HEAVY'.  Please change to use 'HEAVY' instead.")
  UNITTEST_COMPARE_CONST(CATEGORIES "BASIC;HEAVY;NIGHTLY")

  MESSAGE("Testing TRIBITS_FILTER_AND_ASSERT_CATEGORIES( ... HEAVY)")
  SET(MESSAGE_WRAPPER_UNIT_TEST_MODE TRUE)
  GLOBAL_SET(MESSAGE_WRAPPER_INPUT "Dummy")
  SET(CATEGORIES HEAVY)
  TRIBITS_FILTER_AND_ASSERT_CATEGORIES(CATEGORIES)
  SET(MESSAGE_WRAPPER_UNIT_TEST_MODE FALSE)
  UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT "Dummy")
  UNITTEST_COMPARE_CONST(CATEGORIES "HEAVY")

  MESSAGE("Testing TRIBITS_FILTER_AND_ASSERT_CATEGORIES( ... BASIC HEAVY)")
  SET(MESSAGE_WRAPPER_UNIT_TEST_MODE TRUE)
  GLOBAL_SET(MESSAGE_WRAPPER_INPUT "Dummy")
  SET(CATEGORIES BASIC HEAVY)
  TRIBITS_FILTER_AND_ASSERT_CATEGORIES(CATEGORIES)
  SET(MESSAGE_WRAPPER_UNIT_TEST_MODE FALSE)
  UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT "Dummy")
  UNITTEST_COMPARE_CONST(CATEGORIES "BASIC;HEAVY")

ENDFUNCTION()


MACRO(UNITTEST_TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE_UNSET_VARS  TPL_NAME)
  SET(${TPL_NAME}_INCLUDE_DIRS "")
  SET(${TPL_NAME}_LIBRARY_NAMES "")
  SET(${TPL_NAME}_LIBRARY_DIRS "")
  SET(${TPL_NAME}_FORCE_PRE_FIND_PACKAGE FALSE)
  SET(TPL_${TPL_NAME}_INCLUDE_DIRS "")
  SET(TPL_${TPL_NAME}_LIBRARIES "")
  SET(TPL_${TPL_NAME}_LIBRARY_DIRS "")
ENDMACRO()


FUNCTION(UNITTEST_TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE)

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

  MESSAGE("TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE(): No vars set")
  UNITTEST_TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE_UNSET_VARS(SomeTpl)
  TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE(SomeTpl  SomeTpl_ALLOW_PACKAGE_PREFIND)
  UNITTEST_COMPARE_CONST(SomeTpl_ALLOW_PACKAGE_PREFIND  "TRUE")

  MESSAGE("TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE(): Set SomeTpl_INCLUDE_DIRS")
  UNITTEST_TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE_UNSET_VARS(SomeTpl)
  SET(SomeTpl_INCLUDE_DIRS "/some/include/dir")
  TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE(SomeTpl  SomeTpl_ALLOW_PACKAGE_PREFIND)
  UNITTEST_COMPARE_CONST(SomeTpl_ALLOW_PACKAGE_PREFIND  "FALSE")

  MESSAGE("TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE(): Set SomeTpl_LIBRARY_NAMES")
  UNITTEST_TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE_UNSET_VARS(SomeTpl)
  SET(SomeTpl_LIBRARY_NAMES "lib1;lib2")
  TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE(SomeTpl  SomeTpl_ALLOW_PACKAGE_PREFIND)
  UNITTEST_COMPARE_CONST(SomeTpl_ALLOW_PACKAGE_PREFIND  "FALSE")

  MESSAGE("TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE(): Set SomeTpl_LIBRARY_DIRS")
  UNITTEST_TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE_UNSET_VARS(SomeTpl)
  SET(SomeTpl_LIBRARY_DIRS "/some/lib/dir")
  TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE(SomeTpl  SomeTpl_ALLOW_PACKAGE_PREFIND)
  UNITTEST_COMPARE_CONST(SomeTpl_ALLOW_PACKAGE_PREFIND  "FALSE")

  MESSAGE("TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE(): Set SomeTpl_[INCLUDE_DIRS,LIBRARY_NAMES,LIBRARY_DIRS]")
  UNITTEST_TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE_UNSET_VARS(SomeTpl)
  SET(SomeTpl_INCLUDE_DIRS "/some/include/dir")
  SET(SomeTpl_LIBRARY_NAMES "lib1;lib2")
  SET(SomeTpl_LIBRARY_DIRS "/some/lib/dir")
  TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE(SomeTpl  SomeTpl_ALLOW_PACKAGE_PREFIND)
  UNITTEST_COMPARE_CONST(SomeTpl_ALLOW_PACKAGE_PREFIND  "FALSE")

  #SET(TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE_DEBUG TRUE)

  MESSAGE("TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE(): No vars set (2)")
  UNITTEST_TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE_UNSET_VARS(SomeTpl)
  TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE(SomeTpl  SomeTpl_ALLOW_PACKAGE_PREFIND)
  UNITTEST_COMPARE_CONST(SomeTpl_ALLOW_PACKAGE_PREFIND  "TRUE")

  MESSAGE("TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE(): Set SomeTpl_INCLUDE_DIRS (force prefind)")
  UNITTEST_TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE_UNSET_VARS(SomeTpl)
  SET(SomeTpl_INCLUDE_DIRS "/some/include/dir")
  SET(SomeTpl_FORCE_PRE_FIND_PACKAGE TRUE)
  TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE(SomeTpl  SomeTpl_ALLOW_PACKAGE_PREFIND)
  UNITTEST_COMPARE_CONST(SomeTpl_ALLOW_PACKAGE_PREFIND  "TRUE")

  MESSAGE("TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE(): Set SomeTpl_LIBRARY_NAMES (force prefind)")
  UNITTEST_TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE_UNSET_VARS(SomeTpl)
  SET(SomeTpl_LIBRARY_NAMES "lib1;lib2")
  SET(SomeTpl_FORCE_PRE_FIND_PACKAGE TRUE)
  TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE(SomeTpl  SomeTpl_ALLOW_PACKAGE_PREFIND)
  UNITTEST_COMPARE_CONST(SomeTpl_ALLOW_PACKAGE_PREFIND  "TRUE")

  MESSAGE("TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE(): Set SomeTpl_LIBRARY_DIRS (force prefind)")
  UNITTEST_TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE_UNSET_VARS(SomeTpl)
  SET(SomeTpl_LIBRARY_DIRS "/some/lib/dir")
  SET(SomeTpl_FORCE_PRE_FIND_PACKAGE TRUE)
  TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE(SomeTpl  SomeTpl_ALLOW_PACKAGE_PREFIND)
  UNITTEST_COMPARE_CONST(SomeTpl_ALLOW_PACKAGE_PREFIND  "TRUE")

  MESSAGE("TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE(): Set SomeTpl_[INCLUDE_DIRS,LIBRARY_NAMES,LIBRARY_DIRS] (force prefind)")
  UNITTEST_TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE_UNSET_VARS(SomeTpl)
  SET(SomeTpl_INCLUDE_DIRS "/some/include/dir")
  SET(SomeTpl_LIBRARY_NAMES "lib1;lib2")
  SET(SomeTpl_LIBRARY_DIRS "/some/lib/dir")
  SET(SomeTpl_FORCE_PRE_FIND_PACKAGE TRUE)
  TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE(SomeTpl  SomeTpl_ALLOW_PACKAGE_PREFIND)
  UNITTEST_COMPARE_CONST(SomeTpl_ALLOW_PACKAGE_PREFIND  "TRUE")

  MESSAGE("TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE(): No vars set (3)")
  UNITTEST_TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE_UNSET_VARS(SomeTpl)
  TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE(SomeTpl  SomeTpl_ALLOW_PACKAGE_PREFIND)
  UNITTEST_COMPARE_CONST(SomeTpl_ALLOW_PACKAGE_PREFIND  "TRUE")

  MESSAGE("TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE(): Set TPL_SomeTpl_INCLUDE_DIRS")
  UNITTEST_TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE_UNSET_VARS(SomeTpl)
  SET(TPL_SomeTpl_INCLUDE_DIRS "/some/include/dir")
  TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE(SomeTpl  SomeTpl_ALLOW_PACKAGE_PREFIND)
  UNITTEST_COMPARE_CONST(SomeTpl_ALLOW_PACKAGE_PREFIND  "FALSE")

  MESSAGE("TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE(): Set TPL_SomeTpl_LIBRARIES")
  UNITTEST_TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE_UNSET_VARS(SomeTpl)
  SET(TPL_SomeTpl_LIBRARIES "/some/include/dir")
  TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE(SomeTpl  SomeTpl_ALLOW_PACKAGE_PREFIND)
  UNITTEST_COMPARE_CONST(SomeTpl_ALLOW_PACKAGE_PREFIND  "FALSE")

  MESSAGE("TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE(): Set TPL_SomeTpl_LIBRARY_DIRS")
  UNITTEST_TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE_UNSET_VARS(SomeTpl)
  SET(TPL_SomeTpl_LIBRARY_DIRS "/some/lib/dir")
  TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE(SomeTpl  SomeTpl_ALLOW_PACKAGE_PREFIND)
  UNITTEST_COMPARE_CONST(SomeTpl_ALLOW_PACKAGE_PREFIND  "FALSE")

  MESSAGE("TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE(): Set TPL_SomeTpl_[INCLUDE_DIRS,LIBRARIES,LIBRARY_DIRS]")
  UNITTEST_TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE_UNSET_VARS(SomeTpl)
  SET(TPL_SomeTpl_INCLUDE_DIRS "/some/include/dir")
  SET(TPL_SomeTpl_LIBRARIES "/some/include/dir")
  SET(TPL_SomeTpl_LIBRARY_DIRS "/some/lib/dir")
  TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE(SomeTpl  SomeTpl_ALLOW_PACKAGE_PREFIND)
  UNITTEST_COMPARE_CONST(SomeTpl_ALLOW_PACKAGE_PREFIND  "FALSE")

  MESSAGE("TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE(): Set SomeTpl_INCLUDE_DIRS and TPL_SomeTpl_INCLUDE_DIRS (force update)")
  UNITTEST_TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE_UNSET_VARS(SomeTpl)
  SET(SomeTpl_INCLUDE_DIRS "/some/include/dir")
  SET(TPL_SomeTpl_INCLUDE_DIRS "/some/include/dir")
  SET(SomeTpl_FORCE_PRE_FIND_PACKAGE TRUE)
  TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE(SomeTpl  SomeTpl_ALLOW_PACKAGE_PREFIND)
  UNITTEST_COMPARE_CONST(SomeTpl_ALLOW_PACKAGE_PREFIND  "FALSE")

  #SET(TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE_DEBUG TRUE)

  # ToDo: Test that "force prefind" does not affect TPL_${TPL_NAME}_XXX logic

  MESSAGE("TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE(): No vars set (4)")
  UNITTEST_TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE_UNSET_VARS(SomeTpl)
  TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE(SomeTpl  SomeTpl_ALLOW_PACKAGE_PREFIND)
  UNITTEST_COMPARE_CONST(SomeTpl_ALLOW_PACKAGE_PREFIND  "TRUE")

ENDFUNCTION()


FUNCTION(UNITEST_TRIBITS_ADD_TEST_BASIC)

  MESSAGE("\n***")
  MESSAGE("*** Testing basic functionality of TRIBITS_ADD_TEST(...)")
  MESSAGE("***\n")

  # Needed by TRIBITS_ADD_TEST(...)
  SET(PACKAGE_NAME PackageA)
  SET(PARENT_PACKAGE_NAME PackageA)
  SET(${PACKAGE_NAME}_ENABLE_TESTS ON)

  # Used locally
  SET(EXEN SomeExec)
  SET(PACKEXEN ${PACKAGE_NAME}_${EXEN})

  SET(MESSAGE_WRAPPER_UNIT_TEST_MODE TRUE)

  MESSAGE("Unconditionally add test (no tracing)")
  TRIBITS_ADD_TEST( ${EXEN} ADDED_TESTS_NAMES_OUT ${EXEN}_TEST_NAMES )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe"
    )
  UNITTEST_COMPARE_CONST( # Don't trace by default
    MESSAGE_WRAPPER_INPUT
    ""
    )
  UNITTEST_COMPARE_CONST( # Don't capture unless I want to
    TRIBITS_SET_TEST_PROPERTIES_INPUT
    ""
    )
  UNITTEST_COMPARE_CONST( ${EXEN}_TEST_NAMES  "${PACKEXEN}" )

  # Turn on tracing for the rest of the tests!
  SET(${PROJECT_NAME}_TRACE_ADD_TEST ON)

  MESSAGE("Unconditionally add test (with tracing)")
  TRIBITS_ADD_TEST( ${EXEN} ADDED_TESTS_NAMES_OUT ${EXEN}_TEST_NAMES )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe"
    )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKEXEN}: Added test (BASIC, PROCESSORS=1)!"
    )
  UNITTEST_COMPARE_CONST( # Don't capture unless I want to
    TRIBITS_SET_TEST_PROPERTIES_INPUT
    ""
    )
  UNITTEST_COMPARE_CONST( ${EXEN}_TEST_NAMES  "${PACKEXEN}" )

  MESSAGE("Test in HOST")
  SET(${PROJECT_NAME}_HOSTNAME MyHost)
  TRIBITS_ADD_TEST( ${EXEN} HOST MyHost ADDED_TESTS_NAMES_OUT ${EXEN}_TEST_NAMES )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKEXEN}: Added test (BASIC, PROCESSORS=1)!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe"
    )
  UNITTEST_COMPARE_CONST( # Don't capture unless I want to
    TRIBITS_SET_TEST_PROPERTIES_INPUT
    ""
    )
  UNITTEST_COMPARE_CONST( ${EXEN}_TEST_NAMES  "${PACKEXEN}" )

  MESSAGE("Test not in HOST")
  SET(${PROJECT_NAME}_HOSTNAME TheHost)
  TRIBITS_ADD_TEST( ${EXEN} HOST MyHost ADDED_TESTS_NAMES_OUT ${EXEN}_TEST_NAMES )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKEXEN}: NOT added test because ${PROJECT_NAME}_HOSTNAME='TheHost' does not match list HOST='MyHost'!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    ""
    )
  UNITTEST_COMPARE_CONST( ${EXEN}_TEST_NAMES  "" )

  MESSAGE("Test in XHOST")
  SET(${PROJECT_NAME}_HOSTNAME MyHost)
  TRIBITS_ADD_TEST( ${EXEN} XHOST MyHost ADDED_TESTS_NAMES_OUT ${EXEN}_TEST_NAMES )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKEXEN}: NOT added test because ${PROJECT_NAME}_HOSTNAME='MyHost' matches list XHOST='MyHost'!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    ""
    )
  UNITTEST_COMPARE_CONST( ${EXEN}_TEST_NAMES  "" )

  MESSAGE("Test not in XHOST")
  SET(${PROJECT_NAME}_HOSTNAME TheHost)
  TRIBITS_ADD_TEST( ${EXEN} XHOST MyHost ADDED_TESTS_NAMES_OUT ${EXEN}_TEST_NAMES )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKEXEN}: Added test (BASIC, PROCESSORS=1)!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe"
    )
  UNITTEST_COMPARE_CONST( ${EXEN}_TEST_NAMES  "${PACKEXEN}" )

  MESSAGE("Test in HOSTTYPE")
  SET(CMAKE_HOST_SYSTEM_NAME MyHostType)
  TRIBITS_ADD_TEST( ${EXEN} HOSTTYPE MyHostType ADDED_TESTS_NAMES_OUT ${EXEN}_TEST_NAMES )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKEXEN}: Added test (BASIC, PROCESSORS=1)!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe"
    )
  UNITTEST_COMPARE_CONST( ${EXEN}_TEST_NAMES  "${PACKEXEN}" )

  MESSAGE("Test not in HOSTTYPE")
  SET(CMAKE_HOST_SYSTEM_NAME TheHostType)
  TRIBITS_ADD_TEST( ${EXEN} HOSTTYPE MyHostType ADDED_TESTS_NAMES_OUT ${EXEN}_TEST_NAMES )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKEXEN}: NOT added test because CMAKE_HOST_SYSTEM_NAME='TheHostType' does not match list HOSTTYPE='MyHostType'!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    ""
    )
  UNITTEST_COMPARE_CONST( ${EXEN}_TEST_NAMES  "" )

  MESSAGE("Test in XHOSTTYPE")
  SET(CMAKE_HOST_SYSTEM_NAME MyHostType)
  TRIBITS_ADD_TEST( ${EXEN} XHOSTTYPE MyHostType ADDED_TESTS_NAMES_OUT ${EXEN}_TEST_NAMES )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKEXEN}: NOT added test because CMAKE_HOST_SYSTEM_NAME='MyHostType' matches list XHOSTTYPE='MyHostType'!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    ""
    )
  UNITTEST_COMPARE_CONST( ${EXEN}_TEST_NAMES  "" )

  MESSAGE("Test not in XHOSTTYPE")
  SET(CMAKE_HOST_SYSTEM_NAME TheHostType)
  TRIBITS_ADD_TEST( ${EXEN} XHOSTTYPE MyHostType ADDED_TESTS_NAMES_OUT ${EXEN}_TEST_NAMES )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKEXEN}: Added test (BASIC, PROCESSORS=1)!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe"
    )
  UNITTEST_COMPARE_CONST( ${EXEN}_TEST_NAMES  "${PACKEXEN}" )

  MESSAGE("EXCLUDE_IF_NOT_TRUE <true>")
  SET(VAR_THAT_IS_TRUE TRUE)
  TRIBITS_ADD_TEST( ${EXEN} EXCLUDE_IF_NOT_TRUE  VAR_THAT_IS_TRUE
    ADDED_TESTS_NAMES_OUT ${EXEN}_TEST_NAMES )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKEXEN}: Added test (BASIC, PROCESSORS=1)!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe"
    )
  UNITTEST_COMPARE_CONST( ${EXEN}_TEST_NAMES  "${PACKEXEN}" )

  MESSAGE("EXCLUDE_IF_NOT_TRUE <true> <true>")
  SET(VAR_THAT_IS_TRUE1 TRUE)
  SET(VAR_THAT_IS_TRUE2 TRUE)
  TRIBITS_ADD_TEST( ${EXEN} EXCLUDE_IF_NOT_TRUE  VAR_THAT_IS_TRUE1 VAR_THAT_IS_TRUE2
    ADDED_TESTS_NAMES_OUT ${EXEN}_TEST_NAMES )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKEXEN}: Added test (BASIC, PROCESSORS=1)!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe"
    )
  UNITTEST_COMPARE_CONST( ${EXEN}_TEST_NAMES  "${PACKEXEN}" )

  MESSAGE("EXCLUDE_IF_NOT_TRUE <false>")
  SET(VAR_THAT_IS_FALSE FALSE)
  TRIBITS_ADD_TEST( ${EXEN} EXCLUDE_IF_NOT_TRUE  VAR_THAT_IS_FALSE
    ADDED_TESTS_NAMES_OUT ${EXEN}_TEST_NAMES )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKEXEN}: NOT added test because EXCLUDE_IF_NOT_TRUE VAR_THAT_IS_FALSE='FALSE'!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    ""
    )
  UNITTEST_COMPARE_CONST( ${EXEN}_TEST_NAMES  "" )

  MESSAGE("EXCLUDE_IF_NOT_TRUE <false> <true>")
  SET(VAR_THAT_IS_TRUE TRUE)
  SET(VAR_THAT_IS_FALSE FALSE)
  TRIBITS_ADD_TEST( ${EXEN} EXCLUDE_IF_NOT_TRUE  VAR_THAT_IS_FALSE  VAR_THAT_IS_TRUE
    ADDED_TESTS_NAMES_OUT ${EXEN}_TEST_NAMES )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKEXEN}: NOT added test because EXCLUDE_IF_NOT_TRUE VAR_THAT_IS_FALSE='FALSE'!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    ""
    )
  UNITTEST_COMPARE_CONST( ${EXEN}_TEST_NAMES  "" )

  MESSAGE("EXCLUDE_IF_NOT_TRUE <true> <false>")
  SET(VAR_THAT_IS_TRUE TRUE)
  SET(VAR_THAT_IS_FALSE FALSE)
  TRIBITS_ADD_TEST( ${EXEN} EXCLUDE_IF_NOT_TRUE  VAR_THAT_IS_TRUE  VAR_THAT_IS_FALSE
    ADDED_TESTS_NAMES_OUT ${EXEN}_TEST_NAMES )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKEXEN}: NOT added test because EXCLUDE_IF_NOT_TRUE VAR_THAT_IS_FALSE='FALSE'!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    ""
    )
  UNITTEST_COMPARE_CONST( ${EXEN}_TEST_NAMES  "" )

  MESSAGE("Add a single basic test with no arguments")
  GLOBAL_SET(TRIBITS_ADD_TEST_ADD_TEST_INPUT)
  TRIBITS_ADD_TEST( ${EXEN} ADDED_TESTS_NAMES_OUT ${EXEN}_TEST_NAMES )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe"
    )
  UNITTEST_COMPARE_CONST( ${EXEN}_TEST_NAMES  "${PACKEXEN}" )

  MESSAGE("Add a single basic test with a single argument")
  GLOBAL_SET(TRIBITS_ADD_TEST_ADD_TEST_INPUT)
  TRIBITS_ADD_TEST( ${EXEN} ARGS arg1 )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe;arg1"
    )

  MESSAGE("Add a single basic test with two arguments")
  GLOBAL_SET(TRIBITS_ADD_TEST_ADD_TEST_INPUT)
  TRIBITS_ADD_TEST( ${EXEN} ARGS "arg1 arg2" ADDED_TESTS_NAMES_OUT ${EXEN}_TEST_NAMES )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe;arg1;arg2"
    )
  UNITTEST_COMPARE_CONST( ${EXEN}_TEST_NAMES  "${PACKEXEN}" )

  MESSAGE("Add two tests with simple arguments")
  GLOBAL_SET(TRIBITS_ADD_TEST_ADD_TEST_INPUT)
  TRIBITS_ADD_TEST( ${EXEN} ARGS "arg1" "arg2 arg3"
    ADDED_TESTS_NAMES_OUT ${EXEN}_TEST_NAMES )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN}_0;${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe;arg1;${PACKEXEN}_1;${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe;arg2;arg3"
    )
  UNITTEST_COMPARE_CONST( ${EXEN}_TEST_NAMES  "${PACKEXEN}_0;${PACKEXEN}_1" )

  MESSAGE("Add a double quoted input argument")
  GLOBAL_SET(TRIBITS_ADD_TEST_ADD_TEST_INPUT)
  TRIBITS_ADD_TEST( ${EXEN} ARGS "--arg1=\"bob and cats\"" )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe;--arg1=\"bob and cats\""
    )

  MESSAGE("Add a double quoted with single quotes input argument")
  GLOBAL_SET(TRIBITS_ADD_TEST_ADD_TEST_INPUT)
  TRIBITS_ADD_TEST( ${EXEN} ARGS "--arg1=\"'bob' and 'cats'\"" )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe;--arg1=\"'bob' and 'cats'\""
    )

  MESSAGE("Add two tests with different postfixes and arguments")
  GLOBAL_SET(TRIBITS_ADD_TEST_ADD_TEST_INPUT)
  TRIBITS_ADD_TEST( ${EXEN}
    POSTFIX_AND_ARGS_0  pf_arg1  arg1
    POSTFIX_AND_ARGS_1  pf_arg23  arg2  arg3
    ADDED_TESTS_NAMES_OUT  ${EXEN}_TEST_NAMES
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN}_pf_arg1;${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe;arg1;${PACKEXEN}_pf_arg23;${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe;arg2;arg3"
    )
  UNITTEST_COMPARE_CONST( ${EXEN}_TEST_NAMES  "${PACKEXEN}_pf_arg1;${PACKEXEN}_pf_arg23" )

  MESSAGE("Add an executable with no prefix")
  GLOBAL_SET(TRIBITS_ADD_TEST_ADD_TEST_INPUT)
  TRIBITS_ADD_TEST( ${EXEN} NOEXEPREFIX ARGS arg1 )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN};${CMAKE_CURRENT_BINARY_DIR}/${EXEN}.exe;arg1"
    )

  MESSAGE("Add an executable with no suffix")
  GLOBAL_SET(TRIBITS_ADD_TEST_ADD_TEST_INPUT)
  TRIBITS_ADD_TEST( ${EXEN} NOEXESUFFIX ARGS arg1 )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN};arg1"
    )

  MESSAGE("Add an executable with no prefix and no suffix")
  GLOBAL_SET(TRIBITS_ADD_TEST_ADD_TEST_INPUT)
  TRIBITS_ADD_TEST( ${EXEN} NOEXEPREFIX NOEXESUFFIX ARGS arg1 )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN};${CMAKE_CURRENT_BINARY_DIR}/${EXEN};arg1"
    )

  MESSAGE("Add a test with a different name from the executable")
  GLOBAL_SET(TRIBITS_ADD_TEST_ADD_TEST_INPUT)
  TRIBITS_ADD_TEST( ${EXEN} NAME SomeOtherName ARGS arg1 )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKAGE_NAME}_SomeOtherName;${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe;arg1"
    )

  MESSAGE("Add a test with with a postfix appended to the executable name")
  GLOBAL_SET(TRIBITS_ADD_TEST_ADD_TEST_INPUT)
  TRIBITS_ADD_TEST( ${EXEN} NAME_POSTFIX somePostfix ARGS arg1
    ADDED_TESTS_NAMES_OUT ${EXEN}_TEST_NAMES )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN}_somePostfix;${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe;arg1"
    )
  UNITTEST_COMPARE_CONST( ${EXEN}_TEST_NAMES  "${PACKEXEN}_somePostfix" )

  MESSAGE("Add a test with the relative directory overridden")
  GLOBAL_SET(TRIBITS_ADD_TEST_ADD_TEST_INPUT)
  TRIBITS_ADD_TEST( ${EXEN} DIRECTORY "../somedir" ARGS arg1 )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN};${CMAKE_CURRENT_BINARY_DIR}/../somedir/${PACKEXEN}.exe;arg1"
    )

  MESSAGE("Add a test with the absolute directory overridden")
  GLOBAL_SET(TRIBITS_ADD_TEST_ADD_TEST_INPUT)
  TRIBITS_ADD_TEST( ${EXEN} DIRECTORY "/some/abs/path" ARGS arg1 )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN};/some/abs/path/${PACKEXEN}.exe;arg1"
    )

  MESSAGE("Tests not enabled")
  SET(${PACKAGE_NAME}_ENABLE_TESTS OFF)
  TRIBITS_ADD_TEST( ${EXEN} ADDED_TESTS_NAMES_OUT ${EXEN}_TEST_NAMES )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- PackageA_SomeExec: NOT added test because PackageA_ENABLE_TESTS='OFF'."
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    ""
    )
  UNITTEST_COMPARE_CONST( ${EXEN}_TEST_NAMES  "" )

ENDFUNCTION()


FUNCTION(UNITEST_TRIBITS_ADD_TEST_DISABLE)

  MESSAGE("\n***")
  MESSAGE("*** Testing test-by-test disable of TRIBITS_ADD_TEST(...)")
  MESSAGE("***\n")

  # Needed by TRIBITS_ADD_TEST(...)
  SET(PACKAGE_NAME PackageA)
  SET(${PACKAGE_NAME}_ENABLE_TESTS ON)

  # Used locally
  SET(EXEN SomeExec)
  SET(PACKEXEN ${PACKAGE_NAME}_${EXEN})

  MESSAGE("Check that TRIBITS_ADD_TEST(...) adds test")
  TRIBITS_ADD_TEST( ${EXEN} )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe"
    )

  MESSAGE("Check that TRIBITS_ADD_ADVANCED_TEST(...) adds test (no tracing)")
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( SomeCmnd
    TEST_0 CMND someCmnd
    ADDED_TEST_NAME_OUT  SomeCmnd_TEST_NAME
    )
  UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT "")
  UNITTEST_COMPARE_CONST(SomeCmnd_TEST_NAME "${PACKAGE_NAME}_SomeCmnd")
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_CMND_ARRAY_0
    "\"someCmnd\""
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS
    1
    )

  MESSAGE("Check that PackageA_SomeExec_DISABLE=ON disables TRIBITS_ADD_TEST(...) (no tracing)")
  SET(PackageA_SomeExec_DISABLE ON)
  TRIBITS_ADD_TEST( ${EXEN} )
  SET(PackageA_SomeExec_DISABLE OFF)
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    ""
    )

  MESSAGE("Check that PackageA_SomeCmnd_DISABLE=ON disables TRIBITS_ADD_ADVANCED_TEST(...) (no tracing)")
  SET(PackageA_SomeCmnd_DISABLE ON)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( SomeCmnd
    TEST_0 CMND someCmnd
    ADDED_TEST_NAME_OUT  SomeCmnd_TEST_NAME
    )
  SET(PackageA_SomeCmnd_DISABLE OFF)
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_CMND_ARRAY_0
    ""
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS
    ""
    )
  UNITTEST_COMPARE_CONST(SomeCmnd_TEST_NAME "")

  # Turn on tracing
  SET(${PROJECT_NAME}_TRACE_ADD_TEST ON)
  SET(MESSAGE_WRAPPER_UNIT_TEST_MODE TRUE)

  MESSAGE("Check that TRIBITS_ADD_ADVANCED_TEST(...) adds test (with tracing)")
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( SomeCmnd
    TEST_0 CMND someCmnd
    ADDED_TEST_NAME_OUT  SomeCmnd_TEST_NAME
    )
  UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_SomeCmnd: Added test (BASIC, PROCESSORS=1)!")
  UNITTEST_COMPARE_CONST(SomeCmnd_TEST_NAME "${PACKAGE_NAME}_SomeCmnd")
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_CMND_ARRAY_0
    "\"someCmnd\""
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS
    1
    )

  MESSAGE("Check that PackageA_SomeExec_DISABLE=ON disables TRIBITS_ADD_TEST(...)")
  SET(PackageA_SomeExec_DISABLE ON)
  TRIBITS_ADD_TEST( ${EXEN} )
  SET(PackageA_SomeExec_DISABLE OFF)
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKEXEN}: NOT added test because PackageA_SomeExec_DISABLE='ON'!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    ""
    )

  MESSAGE("Check that PackageA_SomeCmnd_DISABLE=ON disables TRIBITS_ADD_ADVANCED_TEST(...)")
  SET(PackageA_SomeCmnd_DISABLE ON)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( SomeCmnd
    TEST_0 CMND someCmnd
    ADDED_TEST_NAME_OUT  SomeCmnd_TEST_NAME
    )
  SET(PackageA_SomeCmnd_DISABLE OFF)
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_SomeCmnd: NOT added test because PackageA_SomeCmnd_DISABLE='ON'!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_CMND_ARRAY_0
    ""
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS
    ""
    )
  UNITTEST_COMPARE_CONST(SomeCmnd_TEST_NAME "")

ENDFUNCTION()


FUNCTION(UNITEST_TRIBITS_ADD_TEST_CATEGORIES)

  MESSAGE("\n***")
  MESSAGE("*** Testing TRIBITS_ADD_TEST( ... CATEGORIES ... )")
  MESSAGE("***\n")

  # Needed by TRIBITS_ADD_TEST(...)
  SET(PACKAGE_NAME PackageA)
  SET(${PACKAGE_NAME}_ENABLE_TESTS ON)

  SET(${PROJECT_NAME}_TEST_CATEGORIES "")

  # Used locally
  SET(EXEN SomeExec)
  SET(PACKEXEN ${PACKAGE_NAME}_${EXEN})

  # Turn on tracing for the rest of the tests!
  SET(${PROJECT_NAME}_TRACE_ADD_TEST ON)
  SET(MESSAGE_WRAPPER_UNIT_TEST_MODE TRUE)

  MESSAGE("Test no category matching NIGHTLY category set by client")
  SET(${PROJECT_NAME}_TEST_CATEGORIES NIGHTLY)
  TRIBITS_ADD_TEST( ${EXEN} )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKEXEN}: Added test (BASIC, PROCESSORS=1)!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe"
    )

  MESSAGE("Test no category matching BASIC category set by client")
  SET(${PROJECT_NAME}_TEST_CATEGORIES BASIC)
  TRIBITS_ADD_TEST( ${EXEN} )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKEXEN}: Added test (BASIC, PROCESSORS=1)!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe"
    )

  MESSAGE("Test NIGHTLY category matching NIGHTLY category set by client")
  SET(${PROJECT_NAME}_TEST_CATEGORIES NIGHTLY)
  TRIBITS_ADD_TEST( ${EXEN} CATEGORIES NIGHTLY )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKEXEN}: Added test (NIGHTLY, PROCESSORS=1)!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe"
    )

  MESSAGE("Test HEAVY category matching HEAVY category set by client")
  SET(${PROJECT_NAME}_TEST_CATEGORIES HEAVY)
  TRIBITS_ADD_TEST( ${EXEN} CATEGORIES HEAVY )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKEXEN}: Added test (HEAVY, PROCESSORS=1)!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe"
    )

  MESSAGE("Test WEEKLY category matching HEAVY category set by client")
  SET(${PROJECT_NAME}_TEST_CATEGORIES HEAVY)
  TRIBITS_ADD_TEST( ${EXEN} CATEGORIES WEEKLY )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "WARNING;Warning: The test category 'WEEKLY' is deprecated; and is replaced with 'HEAVY'.  Please change to use 'HEAVY' instead.;-- PackageA_SomeExec: Added test (HEAVY, PROCESSORS=1)!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe"
    )

  MESSAGE("Test NIGHTLY category *not* matching BASIC category set by client")
  SET(${PROJECT_NAME}_TEST_CATEGORIES BASIC)
  TRIBITS_ADD_TEST( ${EXEN} CATEGORIES NIGHTLY )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKEXEN}: NOT added test because ${PROJECT_NAME}_TEST_CATEGORIES='${${PROJECT_NAME}_TEST_CATEGORIES}' does not match this test's CATEGORIES='NIGHTLY'!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    ""
    )

  MESSAGE("Test BASIC category matching BASIC category set by client")
  SET(${PROJECT_NAME}_TEST_CATEGORIES BASIC)
  TRIBITS_ADD_TEST( ${EXEN} CATEGORIES BASIC )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe"
    )

  MESSAGE("Test no category *not* matching PERFORMANCE category set by client")
  SET(${PROJECT_NAME}_TEST_CATEGORIES PERFORMANCE)
  TRIBITS_ADD_TEST( ${EXEN} )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKEXEN}: NOT added test because ${PROJECT_NAME}_TEST_CATEGORIES='${${PROJECT_NAME}_TEST_CATEGORIES}' does not match this test's CATEGORIES='BASIC'!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    ""
    )

  MESSAGE("Test PERFORMANCE category matching PERFORMANCE category set by client")
  SET(${PROJECT_NAME}_TEST_CATEGORIES PERFORMANCE)
  TRIBITS_ADD_TEST( ${EXEN} CATEGORIES PERFORMANCE )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKEXEN}: Added test (PERFORMANCE, PROCESSORS=1)!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe"
    )

  MESSAGE("Test NIGHTLY, PERFORMANCE category matching PERFORMANCE category set by client")
  SET(${PROJECT_NAME}_TEST_CATEGORIES PERFORMANCE)
  TRIBITS_ADD_TEST( ${EXEN} CATEGORIES NIGHTLY PERFORMANCE )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKEXEN}: Added test (NIGHTLY, PERFORMANCE, PROCESSORS=1)!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe"
    )

  MESSAGE("Test invalid BADCAT category not matching anything and resulting in error")
  SET(${PROJECT_NAME}_TEST_CATEGORIES NIGHTLY)
  SET(MESSAGE_WRAPPER_UNIT_TEST_MODE TRUE)
  GLOBAL_SET(MESSAGE_WRAPPER_INPUT "")
  TRIBITS_ADD_TEST( ${EXEN} CATEGORIES BADCAT )
  SET(MESSAGE_WRAPPER_UNIT_TEST_MODE FALSE)
  UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
    "SEND_ERROR;Error: The categories 'BADCAT' are not; in the list of valid categories '${${PROJECT_NAME}_VALID_CATEGORIES_STR}'!;-- PackageA_SomeExec: NOT added test because ${PROJECT_NAME}_TEST_CATEGORIES='NIGHTLY' does not match this test's CATEGORIES='BADCAT'!")
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "")

ENDFUNCTION()


FUNCTION(UNITEST_TRIBITS_ADD_TEST_COMM)

  MESSAGE("\n***")
  MESSAGE("*** Testing TRIBITS_ADD_TEST( ... COMM ... )")
  MESSAGE("***\n")

  # Needed by TRIBITS_ADD_TEST(...)
  SET(PACKAGE_NAME PackageB)
  SET(${PACKAGE_NAME}_ENABLE_TESTS ON)

  # Doing default serial mode

  # Used locally
  SET(EXEN SomeExec)
  SET(PACKEXEN ${PACKAGE_NAME}_${EXEN})
  SET(MPI_EXEC_MAX_NUMPROCS 5)
  SET(MPI_EXEC_DEFAULT_NUMPROCS 3)
  SET(MPI_EXEC mpiexec)
  SET(MPI_EXEC_PRE_NUMPROCS_FLAGS "--pre-num-procs-flags1;--pre-num-procs-flags2")
  SET(MPI_EXEC_NUMPROCS_FLAG --num-procs)
  SET(MPI_EXEC_POST_NUMPROCS_FLAGS "--post-num-procs-flags1;--post-num-procs-flags2")

  # Turn on tracing for the rest of the tests!
  SET(${PROJECT_NAME}_TRACE_ADD_TEST ON)
  SET(MESSAGE_WRAPPER_UNIT_TEST_MODE TRUE)

  SET(TRIBITS_SET_TEST_PROPERTIES_CAPTURE_INPUT ON)

  MESSAGE("Add a test for serial with no COMM input")
  GLOBAL_SET(TRIBITS_ADD_TEST_ADD_TEST_INPUT)
  TRIBITS_ADD_TEST( ${EXEN} )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKEXEN}: Added test (BASIC, PROCESSORS=3)!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe"
    )

  MESSAGE("Do not add serial with COMM mpi")
  GLOBAL_SET(TRIBITS_ADD_TEST_ADD_TEST_INPUT)
  TRIBITS_ADD_TEST( ${EXEN} COMM mpi )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKEXEN}: NOT added test because TPL_ENABLE_MPI='' and COMM='mpi'!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    ""
    )

  MESSAGE("Add a serial test with NUM_TOTAL_CORES_USED > MPI_EXEC_MAX_NUMPROCS")
  GLOBAL_SET(TRIBITS_ADD_TEST_ADD_TEST_INPUT)
  TRIBITS_ADD_TEST( ${EXEN} NUM_TOTAL_CORES_USED 6 )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKEXEN}: NOT added test because NUM_TOTAL_CORES_USED='6' > MPI_EXEC_MAX_NUMPROCS='5'!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    ""
    )

  # Doing MPI mode
  SET(TPL_ENABLE_MPI ON)

  MESSAGE("Add a test for MPI with no COMM input")
  GLOBAL_SET(TRIBITS_ADD_TEST_ADD_TEST_INPUT)
  TRIBITS_ADD_TEST( ${EXEN} )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKEXEN}_MPI_${MPI_EXEC_DEFAULT_NUMPROCS}: Added test (BASIC, NUM_MPI_PROCS=3, PROCESSORS=3)!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN}_MPI_${MPI_EXEC_DEFAULT_NUMPROCS};${MPI_EXEC};${MPI_EXEC_PRE_NUMPROCS_FLAGS};${MPI_EXEC_NUMPROCS_FLAG};${MPI_EXEC_DEFAULT_NUMPROCS};${MPI_EXEC_POST_NUMPROCS_FLAGS};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe"
    )

  MESSAGE("Add a test for MPI with no COMM input but with some args")
  GLOBAL_SET(TRIBITS_ADD_TEST_ADD_TEST_INPUT)
  TRIBITS_ADD_TEST( ${EXEN} ARGS "arg1 arg2" )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKEXEN}_MPI_${MPI_EXEC_DEFAULT_NUMPROCS}: Added test (BASIC, NUM_MPI_PROCS=3, PROCESSORS=3)!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN}_MPI_${MPI_EXEC_DEFAULT_NUMPROCS};${MPI_EXEC};${MPI_EXEC_PRE_NUMPROCS_FLAGS};${MPI_EXEC_NUMPROCS_FLAG};${MPI_EXEC_DEFAULT_NUMPROCS};${MPI_EXEC_POST_NUMPROCS_FLAGS};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe;arg1;arg2"
    )

  MESSAGE("Add a serial-only in an MPI-only build (adds no test)")
  GLOBAL_SET(TRIBITS_ADD_TEST_ADD_TEST_INPUT)
  TRIBITS_ADD_TEST( ${EXEN} COMM serial )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKEXEN}: NOT added test because TPL_ENABLE_MPI='ON' and COMM='serial'!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    ""
    )

  MESSAGE("Add a test for MPI with 'COMM mpi'")
  GLOBAL_SET(TRIBITS_ADD_TEST_ADD_TEST_INPUT)
  TRIBITS_ADD_TEST( ${EXEN} ARGS "arg1 arg2" COMM mpi )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKEXEN}_MPI_${MPI_EXEC_DEFAULT_NUMPROCS}: Added test (BASIC, NUM_MPI_PROCS=3, PROCESSORS=3)!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN}_MPI_${MPI_EXEC_DEFAULT_NUMPROCS};${MPI_EXEC};${MPI_EXEC_PRE_NUMPROCS_FLAGS};${MPI_EXEC_NUMPROCS_FLAG};${MPI_EXEC_DEFAULT_NUMPROCS};${MPI_EXEC_POST_NUMPROCS_FLAGS};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe;arg1;arg2"
    )

  MESSAGE("Add an MPI test with 2 procs")
  GLOBAL_SET(TRIBITS_ADD_TEST_ADD_TEST_INPUT)
  TRIBITS_ADD_TEST( ${EXEN} ARGS "arg1 arg2" COMM mpi NUM_MPI_PROCS 2 )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN}_MPI_2;${MPI_EXEC};${MPI_EXEC_PRE_NUMPROCS_FLAGS};${MPI_EXEC_NUMPROCS_FLAG};2;${MPI_EXEC_POST_NUMPROCS_FLAGS};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe;arg1;arg2"
    )

  MESSAGE("Add an MPI test with 4 procs (greater than default, less than max)")
  GLOBAL_SET(TRIBITS_ADD_TEST_ADD_TEST_INPUT)
  TRIBITS_ADD_TEST( ${EXEN} ARGS "arg1 arg2" COMM mpi NUM_MPI_PROCS 4 )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN}_MPI_4;${MPI_EXEC};${MPI_EXEC_PRE_NUMPROCS_FLAGS};${MPI_EXEC_NUMPROCS_FLAG};4;${MPI_EXEC_POST_NUMPROCS_FLAGS};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe;arg1;arg2"
    )

  MESSAGE("Add an MPI test with the exact number of max processes")
  GLOBAL_SET(TRIBITS_ADD_TEST_ADD_TEST_INPUT)
  TRIBITS_ADD_TEST( ${EXEN} ARGS "arg1 arg2" COMM mpi NUM_MPI_PROCS 5 )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN}_MPI_5;${MPI_EXEC};${MPI_EXEC_PRE_NUMPROCS_FLAGS};${MPI_EXEC_NUMPROCS_FLAG};5;${MPI_EXEC_POST_NUMPROCS_FLAGS};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe;arg1;arg2"
    )

  MESSAGE("Add an MPI test with one more than the number of allowed processors (will not be added)")
  GLOBAL_SET(TRIBITS_ADD_TEST_ADD_TEST_INPUT)
  TRIBITS_ADD_TEST( ${EXEN} ARGS "arg1 arg2" COMM mpi NUM_MPI_PROCS 6 )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKEXEN}: NOT added test because NUM_MPI_PROCS='6' > MPI_EXEC_MAX_NUMPROCS='5'!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    ""
    )

  MESSAGE("Add an MPI test with NUM_PROCS 1-10 (will be max num procs)")
  GLOBAL_SET(TRIBITS_ADD_TEST_ADD_TEST_INPUT)
  TRIBITS_ADD_TEST( ${EXEN} ARGS "arg1 arg2" COMM mpi NUM_MPI_PROCS 1-10 )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN}_MPI_${MPI_EXEC_MAX_NUMPROCS};${MPI_EXEC};${MPI_EXEC_PRE_NUMPROCS_FLAGS};${MPI_EXEC_NUMPROCS_FLAG};${MPI_EXEC_MAX_NUMPROCS};${MPI_EXEC_POST_NUMPROCS_FLAGS};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe;arg1;arg2"
    )

  MESSAGE("Add an MPI test with NUM_PROCS 3-10 (will be max num procs)")
  GLOBAL_SET(TRIBITS_ADD_TEST_ADD_TEST_INPUT)
  TRIBITS_ADD_TEST( ${EXEN} ARGS "arg1 arg2" COMM mpi NUM_MPI_PROCS 3-10 )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN}_MPI_${MPI_EXEC_MAX_NUMPROCS};${MPI_EXEC};${MPI_EXEC_PRE_NUMPROCS_FLAGS};${MPI_EXEC_NUMPROCS_FLAG};${MPI_EXEC_MAX_NUMPROCS};${MPI_EXEC_POST_NUMPROCS_FLAGS};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe;arg1;arg2"
    )

  MESSAGE("Add an MPI test with NUM_PROCS ${MPI_EXEC_MAX_NUMPROCS}-10 (will be max num procs)")
  GLOBAL_SET(TRIBITS_ADD_TEST_ADD_TEST_INPUT)
  TRIBITS_ADD_TEST( ${EXEN} ARGS "arg1 arg2" COMM mpi NUM_MPI_PROCS ${MPI_EXEC_MAX_NUMPROCS}-10 )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN}_MPI_${MPI_EXEC_MAX_NUMPROCS};${MPI_EXEC};${MPI_EXEC_PRE_NUMPROCS_FLAGS};${MPI_EXEC_NUMPROCS_FLAG};${MPI_EXEC_MAX_NUMPROCS};${MPI_EXEC_POST_NUMPROCS_FLAGS};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe;arg1;arg2"
    )

  MESSAGE("Add an MPI test where the default num processes is same as of max num processes")
  SET(MPI_EXEC_DEFAULT_NUMPROCS 5)
  GLOBAL_SET(TRIBITS_ADD_TEST_ADD_TEST_INPUT)
  TRIBITS_ADD_TEST( ${EXEN} ARGS "arg1 arg2" COMM mpi)
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN}_MPI_5;${MPI_EXEC};${MPI_EXEC_PRE_NUMPROCS_FLAGS};${MPI_EXEC_NUMPROCS_FLAG};5;${MPI_EXEC_POST_NUMPROCS_FLAGS};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe;arg1;arg2"
    )

  MESSAGE("Add an MPI test where the default num processes is one more than of max num processes (will not added test)")
  SET(MPI_EXEC_DEFAULT_NUMPROCS 6)
  GLOBAL_SET(TRIBITS_ADD_TEST_ADD_TEST_INPUT)
  TRIBITS_ADD_TEST( ${EXEN} ARGS "arg1 arg2" COMM mpi)
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKEXEN}: NOT added test because MPI_EXEC_DEFAULT_NUMPROCS='6' > MPI_EXEC_MAX_NUMPROCS='5'!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    ""
    )

  MESSAGE("Add a test with NUM_TOTAL_CORES_USED < MPI_EXEC_MAX_NUMPROCS")
  GLOBAL_SET(TRIBITS_ADD_TEST_ADD_TEST_INPUT)
  TRIBITS_ADD_TEST( ${EXEN} NUM_MPI_PROCS 1 NUM_TOTAL_CORES_USED 4 )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKEXEN}_MPI_1: Added test (BASIC, NUM_MPI_PROCS=1, PROCESSORS=4)!"
    )
  UNITTEST_HAS_SUBSTR_CONST(TRIBITS_SET_TEST_PROPERTIES_INPUT
    "${PACKEXEN}_MPI_1;PROPERTIES;PROCESSORS;4")
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN}_MPI_1;${MPI_EXEC};${MPI_EXEC_PRE_NUMPROCS_FLAGS};${MPI_EXEC_NUMPROCS_FLAG};1;${MPI_EXEC_POST_NUMPROCS_FLAGS};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe"
    )

  MESSAGE("Add a test with NUM_TOTAL_CORES_USED == MPI_EXEC_MAX_NUMPROCS")
  GLOBAL_SET(TRIBITS_ADD_TEST_ADD_TEST_INPUT)
  TRIBITS_ADD_TEST( ${EXEN} NUM_MPI_PROCS 1 NUM_TOTAL_CORES_USED 5 )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKEXEN}_MPI_1: Added test (BASIC, NUM_MPI_PROCS=1, PROCESSORS=5)!"
    )
  UNITTEST_HAS_SUBSTR_CONST(TRIBITS_SET_TEST_PROPERTIES_INPUT
    "${PACKEXEN}_MPI_1;PROPERTIES;PROCESSORS;5")
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN}_MPI_1;${MPI_EXEC};${MPI_EXEC_PRE_NUMPROCS_FLAGS};${MPI_EXEC_NUMPROCS_FLAG};1;${MPI_EXEC_POST_NUMPROCS_FLAGS};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe"
    )

  MESSAGE("Add a test with NUM_TOTAL_CORES_USED > MPI_EXEC_MAX_NUMPROCS")
  GLOBAL_SET(TRIBITS_ADD_TEST_ADD_TEST_INPUT)
  TRIBITS_ADD_TEST( ${EXEN} NUM_MPI_PROCS 1 NUM_TOTAL_CORES_USED 6 )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKEXEN}_MPI_1: NOT added test because NUM_TOTAL_CORES_USED='6' > MPI_EXEC_MAX_NUMPROCS='5'!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    ""
    )

  MESSAGE("Add a test with NUM_MPI_PROCS > NUM_TOTAL_CORES_USED")
  GLOBAL_SET(TRIBITS_ADD_TEST_ADD_TEST_INPUT)
  TRIBITS_ADD_TEST( ${EXEN} NUM_MPI_PROCS 3 NUM_TOTAL_CORES_USED 2 )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "FATAL_ERROR;ERROR: ${PACKEXEN}_MPI_3: NUM_MPI_PROCS='3' > NUM_TOTAL_CORES_USED='2' not allowed!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    ""
    )

  SET(MPI_EXEC_DEFAULT_NUMPROCS 3)

  # Doing serial mode
  SET(TPL_ENABLE_MPI OFF)

  MESSAGE("Add a test for serial mode with 'COMM serial'")
  GLOBAL_SET(TRIBITS_ADD_TEST_ADD_TEST_INPUT)
  TRIBITS_ADD_TEST( ${EXEN} COMM serial ADDED_TESTS_NAMES_OUT ${EXEN}_TEST_NAMES )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe"
    )
  UNITTEST_COMPARE_CONST( ${EXEN}_TEST_NAMES  "${PACKEXEN}" )

  MESSAGE("Add a test for serial mode with 'COMM mpi (adds no test)")
  GLOBAL_SET(TRIBITS_ADD_TEST_ADD_TEST_INPUT)
  TRIBITS_ADD_TEST( ${EXEN} COMM mpi ADDED_TESTS_NAMES_OUT ${EXEN}_TEST_NAMES )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKEXEN}: NOT added test because TPL_ENABLE_MPI='OFF' and COMM='mpi'!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    ""
    )
  UNITTEST_COMPARE_CONST( ${EXEN}_TEST_NAMES  "" )

  MESSAGE("Add a test with MPI and NAME_POSTFIX")
  SET(TPL_ENABLE_MPI ON)
  GLOBAL_SET(TRIBITS_ADD_TEST_ADD_TEST_INPUT)
  TRIBITS_ADD_TEST( ${EXEN} NAME_POSTFIX mypostfix1
    ADDED_TESTS_NAMES_OUT ${EXEN}_TEST_NAMES )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN}_mypostfix1_MPI_${MPI_EXEC_DEFAULT_NUMPROCS};${MPI_EXEC};${MPI_EXEC_PRE_NUMPROCS_FLAGS};${MPI_EXEC_NUMPROCS_FLAG};${MPI_EXEC_DEFAULT_NUMPROCS};${MPI_EXEC_POST_NUMPROCS_FLAGS};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe"
    )
  UNITTEST_COMPARE_CONST( ${EXEN}_TEST_NAMES
    "${PACKEXEN}_mypostfix1_MPI_${MPI_EXEC_DEFAULT_NUMPROCS}" )

  MESSAGE("Add a test with MPI and NAME")
  SET(TPL_ENABLE_MPI ON)
  GLOBAL_SET(TRIBITS_ADD_TEST_ADD_TEST_INPUT)
  TRIBITS_ADD_TEST( ${EXEN} NAME ${EXEN}_mypostfix2
    ADDED_TESTS_NAMES_OUT ${EXEN}_TEST_NAMES )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN}_mypostfix2_MPI_${MPI_EXEC_DEFAULT_NUMPROCS};${MPI_EXEC};${MPI_EXEC_PRE_NUMPROCS_FLAGS};${MPI_EXEC_NUMPROCS_FLAG};${MPI_EXEC_DEFAULT_NUMPROCS};${MPI_EXEC_POST_NUMPROCS_FLAGS};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe"
    )
  UNITTEST_COMPARE_CONST( ${EXEN}_TEST_NAMES
    "${PACKEXEN}_mypostfix2_MPI_${MPI_EXEC_DEFAULT_NUMPROCS}" )

  MESSAGE("Add a test with MPI, two arguments, and NAME_POSTFIX")
  SET(TPL_ENABLE_MPI ON)
  GLOBAL_SET(TRIBITS_ADD_TEST_ADD_TEST_INPUT)
  TRIBITS_ADD_TEST( ${EXEN} NAME_POSTFIX mypostfix3 ARGS "arg1" "arg2"
    ADDED_TESTS_NAMES_OUT ${EXEN}_TEST_NAMES )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN}_mypostfix3_0_MPI_${MPI_EXEC_DEFAULT_NUMPROCS};${MPI_EXEC};${MPI_EXEC_PRE_NUMPROCS_FLAGS};${MPI_EXEC_NUMPROCS_FLAG};${MPI_EXEC_DEFAULT_NUMPROCS};${MPI_EXEC_POST_NUMPROCS_FLAGS};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe;arg1;${PACKEXEN}_mypostfix3_1_MPI_${MPI_EXEC_DEFAULT_NUMPROCS};${MPI_EXEC};${MPI_EXEC_PRE_NUMPROCS_FLAGS};${MPI_EXEC_NUMPROCS_FLAG};${MPI_EXEC_DEFAULT_NUMPROCS};${MPI_EXEC_POST_NUMPROCS_FLAGS};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe;arg2"
    )
  UNITTEST_COMPARE_CONST( ${EXEN}_TEST_NAMES
    "${PACKEXEN}_mypostfix3_0_MPI_${MPI_EXEC_DEFAULT_NUMPROCS};${PACKEXEN}_mypostfix3_1_MPI_${MPI_EXEC_DEFAULT_NUMPROCS}" )

ENDFUNCTION()


FUNCTION(UNITEST_TRIBITS_ADD_TEST_PROPERTIES)

  MESSAGE("\n***")
  MESSAGE("*** Testing the setting of test properties with TRIBITS_ADD_TEST(...)")
  MESSAGE("***\n")

  SET(TRIBITS_SET_TEST_PROPERTIES_CAPTURE_INPUT ON)

  # Needed by TRIBITS_ADD_TEST(...)
  SET(PACKAGE_NAME PackageA)
  SET(${PACKAGE_NAME}_ENABLE_TESTS ON)

  # Used locally
  SET(EXEN SomeExec)
  SET(PACKEXEN ${PACKAGE_NAME}_${EXEN})

  # Turn on tracing for the rest of the tests!
  SET(${PROJECT_NAME}_TRACE_ADD_TEST ON)
  SET(MESSAGE_WRAPPER_UNIT_TEST_MODE TRUE)

  MESSAGE("Test setting of default properties")
  TRIBITS_ADD_TEST(${EXEN})
  UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
    "-- ${PACKEXEN}: Added test (BASIC, PROCESSORS=1)!" )
  UNITTEST_COMPARE_CONST(TRIBITS_ADD_TEST_ADD_TEST_INPUT
    "${PACKEXEN};${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe"
    )
  UNITTEST_COMPARE_CONST(TRIBITS_SET_TEST_PROPERTIES_INPUT
    "PackageA_SomeExec;PROPERTIES;REQUIRED_FILES;${CMAKE_CURRENT_BINARY_DIR}/PackageA_SomeExec.exe;PackageA_SomeExec;PROPERTIES;PROCESSORS;1;PackageA_SomeExec;APPEND;PROPERTY;LABELS"
    )
  UNITTEST_HAS_SUBSTR_CONST(TRIBITS_SET_TEST_PROPERTIES_INPUT
    "PackageA_SomeExec;APPEND;PROPERTY;LABELS")

  MESSAGE("Test setting integer TIMEOUT with no scaling (not even defined)")
  TRIBITS_ADD_TEST(${EXEN} TIMEOUT 200)
  UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
    "-- ${PACKEXEN}: Added test (BASIC, PROCESSORS=1, TIMEOUT=200)!" )
  UNITTEST_HAS_SUBSTR_CONST(TRIBITS_SET_TEST_PROPERTIES_INPUT
    "PackageA_SomeExec;PROPERTIES;TIMEOUT;200")

  MESSAGE("Test setting non-integer TIMEOUT with no scaling (not even defined)")
  TRIBITS_ADD_TEST(${EXEN} TIMEOUT 200.50)
  UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
    "-- ${PACKEXEN}: Added test (BASIC, PROCESSORS=1, TIMEOUT=200.50)!" )
  UNITTEST_HAS_SUBSTR_CONST(TRIBITS_SET_TEST_PROPERTIES_INPUT
    "PackageA_SomeExec;PROPERTIES;TIMEOUT;200.50")
  # NOTE: No truncation in TIMEOUT in this case!

  MESSAGE("Test setting integer TIMEOUT with no scaling (default 1.0)")
  SET(${PROJECT_NAME}_SCALE_TEST_TIMEOUT 1.0)
  TRIBITS_ADD_TEST(${EXEN} TIMEOUT 200)
  UNITTEST_HAS_SUBSTR_CONST(TRIBITS_SET_TEST_PROPERTIES_INPUT
    "PackageA_SomeExec;PROPERTIES;TIMEOUT;200")

  MESSAGE("Test setting non-integer TIMEOUT with no scaling (default 1.0)")
  SET(${PROJECT_NAME}_SCALE_TEST_TIMEOUT 1.0)
  TRIBITS_ADD_TEST(${EXEN} TIMEOUT 200.50)
  UNITTEST_HAS_SUBSTR_CONST(TRIBITS_SET_TEST_PROPERTIES_INPUT
    "PackageA_SomeExec;PROPERTIES;TIMEOUT;200.50")

  MESSAGE("Test setting integer TIMEOUT with no scaling (non-default integral 1")
  SET(${PROJECT_NAME}_SCALE_TEST_TIMEOUT 1)
  TRIBITS_ADD_TEST(${EXEN} TIMEOUT 200)
  UNITTEST_HAS_SUBSTR_CONST(TRIBITS_SET_TEST_PROPERTIES_INPUT
    "PackageA_SomeExec;PROPERTIES;TIMEOUT;200")
  SET(${PROJECT_NAME}_SCALE_TEST_TIMEOUT 1.0)

  MESSAGE("Test setting non-integer TIMEOUT with no scaling (non-default integral 1)")
  SET(${PROJECT_NAME}_SCALE_TEST_TIMEOUT 1)
  TRIBITS_ADD_TEST(${EXEN} TIMEOUT 200.50)
  UNITTEST_HAS_SUBSTR_CONST(TRIBITS_SET_TEST_PROPERTIES_INPUT
    "PackageA_SomeExec;PROPERTIES;TIMEOUT;200")
  SET(${PROJECT_NAME}_SCALE_TEST_TIMEOUT 1.0)
  # NOTE: TIMEOUT is truncated in this case!

  MESSAGE("Test integral scaling 2 of non-integer TIMEOUT")
  SET(${PROJECT_NAME}_SCALE_TEST_TIMEOUT 2)
  TRIBITS_ADD_TEST(${EXEN} TIMEOUT 300.0)
  UNITTEST_HAS_SUBSTR_CONST(TRIBITS_SET_TEST_PROPERTIES_INPUT
    "PackageA_SomeExec;PROPERTIES;TIMEOUT;600")
  SET(${PROJECT_NAME}_SCALE_TEST_TIMEOUT 1.0)

  MESSAGE("Test non-integral scaling 1.5 of non-integer TIMEOUT")
  SET(${PROJECT_NAME}_SCALE_TEST_TIMEOUT 1.5)
  TRIBITS_ADD_TEST(${EXEN} TIMEOUT 300.0)
  UNITTEST_HAS_SUBSTR_CONST(TRIBITS_SET_TEST_PROPERTIES_INPUT
    "PackageA_SomeExec;PROPERTIES;TIMEOUT;450")
  SET(${PROJECT_NAME}_SCALE_TEST_TIMEOUT 1.0)

  MESSAGE("Test non-integral scaling 1.57 of non-integer TIMEOUT")
  SET(${PROJECT_NAME}_SCALE_TEST_TIMEOUT 1.57)
  TRIBITS_ADD_TEST(${EXEN} TIMEOUT 300.0)
  UNITTEST_HAS_SUBSTR_CONST(TRIBITS_SET_TEST_PROPERTIES_INPUT
    "PackageA_SomeExec;PROPERTIES;TIMEOUT;450")
  # NOTE: 1.57 is truncated to 1.5 as part of the scaling algorithm
  SET(${PROJECT_NAME}_SCALE_TEST_TIMEOUT 1.0)

  MESSAGE("Test setting ENVIRONMENT")
  TRIBITS_ADD_TEST(${EXEN} ENVIRONMENT var1=val1 var2=val2 )
  UNITTEST_HAS_SUBSTR_CONST(TRIBITS_SET_TEST_PROPERTIES_INPUT
    "PackageA_SomeExec;PROPERTY;ENVIRONMENT;var1=val1;var2=val2")

  SET(TRIBITS_SET_TEST_PROPERTIES_CAPTURE_INPUT OFF)

ENDFUNCTION()


FUNCTION(UNITEST_TRIBITS_ADD_ADVANCED_TEST_BASIC)

  MESSAGE("\n***")
  MESSAGE("*** Testing basic functionality of TRIBITS_ADD_ADVANCED_TEST(...)")
  MESSAGE("***\n")

  # Needed by TRIBITS_ADD_ADVANCED_TEST(...)
  SET(PACKAGE_NAME PackageA)
  SET(PARENT_PACKAGE_NAME PackageA)
  SET(${PACKAGE_NAME}_ENABLE_TESTS ON)

  # Used locally
  SET(EXEN SomeExec)
  SET(PACKEXEN ${PACKAGE_NAME}_${EXEN}.exe)
  SET(CMNDN ls)

  MESSAGE("***\n*** Add a single basic command with no arguments (and check other parts)\n***")
  SET(${PROJECT_NAME}_SHOW_TEST_START_END_DATE_TIME ON)
  SET(${PROJECT_NAME}_SHOW_MACHINE_LOAD_IN_TEST OFF)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( TAAT_basic_cmnd_1_args_0
    OVERALL_NUM_TOTAL_CORES_USED 4
    TIMEOUT 333.2
    TEST_0 CMND ${CMNDN}
      WORKING_DIRECTORY "someSubdir"
    ADDED_TEST_NAME_OUT  TAAT_basic_cmnd_1_args_0_TEST_NAME
    )
  UNITTEST_COMPARE_CONST(TAAT_basic_cmnd_1_args_0_TEST_NAME
    "${PACKAGE_NAME}_TAAT_basic_cmnd_1_args_0")
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_CMND_ARRAY_0
    "\"${CMNDN}\""
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS
    1
    )
  UNITTEST_FILE_REGEX(
    "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}_TAAT_basic_cmnd_1_args_0.cmake"
    REGEX_STRINGS
      "TEST_0_CMND \"ls\""
      "NUM_CMNDS 1"
      "SET[(]SKIP_CLEAN_OVERALL_WORKING_DIRECTORY .FALSE.[)]"
      "SET[(]SHOW_START_END_DATE_TIME ON[)]"
      "SET[(]SHOW_MACHINE_LOAD OFF[)]"
      "SET[(]CATEGORIES [)]"
      "SET[(]PROCESSORS 4[)]"
      "SET[(]TIMEOUT 333.2[)]"
      "SET[(] TEST_0_WORKING_DIRECTORY .someSubdir. [)]"
      "SET[(] TEST_0_SKIP_CLEAN_WORKING_DIRECTORY FALSE [)]"
    )

  MESSAGE("***\n*** Add a single package executable with no arguments (and check other stuff)\n***")
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  SET(${PROJECT_NAME}_SHOW_TEST_START_END_DATE_TIME OFF) # Above test was ON
  SET(${PROJECT_NAME}_SHOW_MACHINE_LOAD_IN_TEST ON) # Above test was OFF
  TRIBITS_ADD_ADVANCED_TEST( TAAT_basic_exec_1_args_0
    TEST_0 EXEC ${EXEN}
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_CMND_ARRAY_0
    "\"${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}\""
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS
    1
    )
  UNITTEST_FILE_REGEX(
    "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}_TAAT_basic_exec_1_args_0.cmake"
    REGEX_STRINGS
      "TEST_0_CMND \"${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}\""
      "NUM_CMNDS 1"
      "SET[(]SHOW_START_END_DATE_TIME OFF[)]"
      "SET[(]SHOW_MACHINE_LOAD ON[)]"
    )

  MESSAGE("***\n*** Add a single basic command with two arguments\n***")
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  SET(${PROJECT_NAME}_SHOW_TEST_START_END_DATE_TIME OFF)
  TRIBITS_ADD_ADVANCED_TEST( TAAT_basic_cmnd_1_args_2
    OVERALL_WORKING_DIRECTORY  TEST_NAME
    SKIP_CLEAN_OVERALL_WORKING_DIRECTORY
    TEST_0 CMND ${CMNDN} ARGS CMakeLists.txt CMakeFiles
      WORKING_DIRECTORY "someSubdir"
      SKIP_CLEAN_WORKING_DIRECTORY
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_CMND_ARRAY_0
    "\"${CMNDN}\" \"CMakeLists.txt\" \"CMakeFiles\""
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS
    1
    )
  UNITTEST_FILE_REGEX(
    "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}_TAAT_basic_cmnd_1_args_2.cmake"
    REGEX_STRINGS
      "TEST_0_CMND \"ls\" \"CMakeLists.txt\" \"CMakeFiles\""
      "NUM_CMNDS 1"
      "SET[(]OVERALL_WORKING_DIRECTORY .PackageA_TAAT_basic_cmnd_1_args_2.[)]"
      "SET[(]SKIP_CLEAN_OVERALL_WORKING_DIRECTORY .TRUE.[)]"
      "CMAKE_MODULE_PATH"
      "SET[(]SHOW_START_END_DATE_TIME OFF[)]"
      "SET[(] TEST_0_WORKING_DIRECTORY .someSubdir. [)]"
      "SET[(] TEST_0_SKIP_CLEAN_WORKING_DIRECTORY TRUE [)]"
      "DriveAdvancedTest"
      "DRIVE_ADVANCED_TEST"
    )

  MESSAGE("***\n*** Add a single package executable with three arguments\n***")
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( TAAT_basic_exec_1_args_3
    TEST_0 EXEC ${EXEN} ARGS arg1 arg2 arg3
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_CMND_ARRAY_0
    "\"${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}\" \"arg1\" \"arg2\" \"arg3\""
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS
    1
    )
  UNITTEST_FILE_REGEX(
    "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}_TAAT_basic_exec_1_args_3.cmake"
    REGEX_STRINGS
      "TEST_0_CMND \"${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}\" \"arg1\" \"arg2\" \"arg3\""
      "NUM_CMNDS 1"
    )

  MESSAGE("***\n*** Add two basic commands with 1 and two arguments\n***")
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( TAAT_basic_cmnd_2_args_1_2
    TEST_0 CMND echo ARGS "Cats and Dogs"
    TEST_1 CMND ls ARGS Cats
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS
    2
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_CMND_ARRAY_0
    "\"echo\" \"Cats and Dogs\""
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_CMND_ARRAY_1
    "\"ls\" \"Cats\""
    )
  UNITTEST_FILE_REGEX(
    "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}_TAAT_basic_cmnd_2_args_1_2.cmake"
    REGEX_STRINGS
      "TEST_0_CMND \"echo\" \"Cats and Dogs\""
      "TEST_1_CMND \"ls\" \"Cats\""
      "NUM_CMNDS 2"
    )

  MESSAGE("***\n*** Add a single basic command matching HOST\n***")
  SET(${PROJECT_NAME}_HOSTNAME MyHost)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( TAAT_basic_host
    TEST_0 CMND ${CMNDN}
    HOST MyHost
    ADDED_TEST_NAME_OUT  TAAT_basic_host_TEST_NAME
    )
  UNITTEST_COMPARE_CONST(TAAT_basic_host_TEST_NAME
    "${PACKAGE_NAME}_TAAT_basic_host")
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_CMND_ARRAY_0
    "\"${CMNDN}\""
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS
    1
    )
  UNITTEST_FILE_REGEX(
    "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}_TAAT_basic_host.cmake"
    REGEX_STRINGS
      "TEST_0_CMND \"ls\""
      "NUM_CMNDS 1"
    )

  MESSAGE("***\n*** Add a single basic command not matching HOST\n***")
  SET(${PROJECT_NAME}_HOSTNAME MyHost)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( TAAT_basic_host
    TEST_0 CMND ${CMNDN}
    HOST NotMyHost
    ADDED_TEST_NAME_OUT  TAAT_basic_host_TEST_NAME
    )
  UNITTEST_COMPARE_CONST(TAAT_basic_host_TEST_NAME "")
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_CMND_ARRAY_0
    ""
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS
    ""
    )

  # ToDo: Add 6 more tests testing XHOST, HOSTTYPE, and XHOSTTYPE

  MESSAGE("***\n*** Tests not enabled\n***")
  SET(MESSAGE_WRAPPER_UNIT_TEST_MODE TRUE)
  SET(${PROJECT_NAME}_TRACE_ADD_TEST ON)
  SET(${PACKAGE_NAME}_ENABLE_TESTS OFF)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( TAAT_tests_disabled
    TEST_0 CMND ${CMNDN}
    ADDED_TEST_NAME_OUT  TAAT_tests_disabled_TEST_NAME
    )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- PackageA_TAAT_tests_disabled: NOT added test because PackageA_ENABLE_TESTS='OFF'."
    )
  UNITTEST_COMPARE_CONST(TAAT_tests_disabled_TEST_NAME "")
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_CMND_ARRAY_0
    ""
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS
    ""
    )

ENDFUNCTION()


FUNCTION(UNITEST_TRIBITS_ADD_ADVANCED_TEST_CATEGORIES)

  MESSAGE("\n***")
  MESSAGE("*** Testing TRIBITS_ADD_ADVANCED_TEST( ... CATEGORIES ... )")
  MESSAGE("***\n")

  # Needed by TRIBITS_ADD_TEST(...)
  SET(PACKAGE_NAME PackageA)
  SET(${PACKAGE_NAME}_ENABLE_TESTS ON)

  SET(${PROJECT_NAME}_TEST_CATEGORIES "")

  # Used locally
  SET(EXEN SomeExec)
  SET(PACKEXEN ${PACKAGE_NAME}_${EXEN}.exe)

  # Turn on tracing for the rest of the tests!
  SET(${PROJECT_NAME}_TRACE_ADD_TEST ON)
  SET(MESSAGE_WRAPPER_UNIT_TEST_MODE TRUE)

  MESSAGE("\n*** Test empty CATEGORIES matching the BASIC category\n")

  MESSAGE("Test empty CATEGORIES matching CONTINUOUS category set by client")
  SET(TEST_NAME PackageAddAdvancedTestCategory_Empty_Nightly)
  SET(${PROJECT_NAME}_TEST_CATEGORIES CONTINUOUS)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( ${TEST_NAME} TEST_0 EXEC ${EXEN} )
  UNITTEST_FILE_REGEX(
    "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}_${TEST_NAME}.cmake"
    REGEX_STRINGS
      "TEST_0_CMND \"${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}\""
      "NUM_CMNDS 1"
    )

  MESSAGE("Test empty CATEGORIES matching NIGHTLY category set by client")
  SET(TEST_NAME PackageAddAdvancedTestCategory_Empty_Nightly)
  SET(${PROJECT_NAME}_TEST_CATEGORIES NIGHTLY)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( ${TEST_NAME} TEST_0 EXEC ${EXEN} )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_${TEST_NAME}: Added test (BASIC, PROCESSORS=1)!"
    )
  UNITTEST_FILE_REGEX(
    "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}_${TEST_NAME}.cmake"
    REGEX_STRINGS
      "TEST_0_CMND \"${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}\""
      "NUM_CMNDS 1"
    )

  MESSAGE("Test empty CATEGORIES matching HEAVY category set by client")
  SET(TEST_NAME PackageAddAdvancedTestCategory_Empty_Heavy)
  SET(${PROJECT_NAME}_TEST_CATEGORIES HEAVY)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( ${TEST_NAME} TEST_0 EXEC ${EXEN} )
  UNITTEST_FILE_REGEX(
    "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}_${TEST_NAME}.cmake"
    REGEX_STRINGS
      "TEST_0_CMND \"${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}\""
      "NUM_CMNDS 1"
    )

  MESSAGE("Test WEEKLY category becomes HEAVY")
  SET(TEST_NAME PackageAddAdvancedTestCategory_Empty_Weekly)
  SET(${PROJECT_NAME}_TEST_CATEGORIES HEAVY)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( ${TEST_NAME} TEST_0 EXEC ${EXEN} CATEGORIES WEEKLY )
  UNITTEST_FILE_REGEX(
    "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}_${TEST_NAME}.cmake"
    REGEX_STRINGS
      "TEST_0_CMND \"${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}\""
      "NUM_CMNDS 1"
      "SET.CATEGORIES HEAVY."
    )

  MESSAGE("Test empty CATEGORIES *not* matching PERFORMANCE category set by client")
  SET(TEST_NAME PackageAddAdvancedTestCategory_Empty_Performance)
  SET(${PROJECT_NAME}_TEST_CATEGORIES PERFORMANCE)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( ${TEST_NAME} TEST_0 EXEC ${EXEN} )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_${TEST_NAME}: NOT added test because ${PROJECT_NAME}_TEST_CATEGORIES='${${PROJECT_NAME}_TEST_CATEGORIES}' does not match this test's CATEGORIES='BASIC'!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_CMND_ARRAY_0
    ""
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS
    ""
    )

  MESSAGE("\n*** Test CATEGORIES BASIC\n")

  MESSAGE("Test CATEGORIES BASIC matching BASIC category set by client")
  SET(TEST_NAME PackageAddAdvancedTestCategory_BASIC_BASIC)
  SET(${PROJECT_NAME}_TEST_CATEGORIES BASIC)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( ${TEST_NAME} TEST_0 EXEC ${EXEN} CATEGORIES BASIC )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_${TEST_NAME}: Added test (BASIC, PROCESSORS=1)!"
    )
  UNITTEST_FILE_REGEX(
    "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}_${TEST_NAME}.cmake"
    REGEX_STRINGS
      "TEST_0_CMND \"${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}\""
      "NUM_CMNDS 1"
    )

  MESSAGE("Test CATEGORIES BASIC matching CONTINUOUS category set by client")
  SET(TEST_NAME PackageAddAdvancedTestCategory_BASIC_CONTINUOUS)
  SET(${PROJECT_NAME}_TEST_CATEGORIES CONTINUOUS)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( ${TEST_NAME} TEST_0 EXEC ${EXEN} CATEGORIES BASIC )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_${TEST_NAME}: Added test (BASIC, PROCESSORS=1)!"
    )
  UNITTEST_FILE_REGEX(
    "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}_${TEST_NAME}.cmake"
    REGEX_STRINGS
      "TEST_0_CMND \"${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}\""
      "NUM_CMNDS 1"
    )

  MESSAGE("Test CATEGORIES BASIC matching NIGHTLY category set by client")
  SET(TEST_NAME PackageAddAdvancedTestCategory_BASIC_NIGHTLY)
  SET(${PROJECT_NAME}_TEST_CATEGORIES NIGHTLY)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( ${TEST_NAME} TEST_0 EXEC ${EXEN} CATEGORIES BASIC )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_${TEST_NAME}: Added test (BASIC, PROCESSORS=1)!"
    )
  UNITTEST_FILE_REGEX(
    "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}_${TEST_NAME}.cmake"
    REGEX_STRINGS
      "TEST_0_CMND \"${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}\""
      "NUM_CMNDS 1"
    )

  MESSAGE("Test CATEGORIES BASIC matching HEAVY category set by client")
  SET(TEST_NAME PackageAddAdvancedTestCategory_BASIC_HEAVY)
  SET(${PROJECT_NAME}_TEST_CATEGORIES NIGHTLY)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( ${TEST_NAME} TEST_0 EXEC ${EXEN} CATEGORIES BASIC )
  UNITTEST_FILE_REGEX(
    "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}_${TEST_NAME}.cmake"
    REGEX_STRINGS
      "TEST_0_CMND \"${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}\""
      "NUM_CMNDS 1"
    )

  MESSAGE("\n*** Test CATEGORIES CONTINUOUS\n")

  MESSAGE("Test CATEGORIES CONTINUOUS *not* matching BASIC category set by client")
  SET(TEST_NAME PackageAddAdvancedTestCategory_CONTINUOUS_BASIC)
  SET(${PROJECT_NAME}_TEST_CATEGORIES BASIC)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( ${TEST_NAME} TEST_0 EXEC ${EXEN} CATEGORIES CONTINUOUS )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_${TEST_NAME}: NOT added test because ${PROJECT_NAME}_TEST_CATEGORIES='BASIC' does not match this test's CATEGORIES='CONTINUOUS'!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_CMND_ARRAY_0
    ""
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS
    ""
    )

  MESSAGE("Test CATEGORIES CONTINUOUS matching CONTINUOUS category set by client")
  SET(TEST_NAME PackageAddAdvancedTestCategory_CONTINUOUS_CONTINUOUS)
  SET(${PROJECT_NAME}_TEST_CATEGORIES CONTINUOUS)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( ${TEST_NAME} TEST_0 EXEC ${EXEN} CATEGORIES CONTINUOUS )
  UNITTEST_FILE_REGEX(
    "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}_${TEST_NAME}.cmake"
    REGEX_STRINGS
      "TEST_0_CMND \"${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}\""
      "NUM_CMNDS 1"
    )

  MESSAGE("Test CATEGORIES CONTINUOUS matching NIGHTLY category set by client")
  SET(TEST_NAME PackageAddAdvancedTestCategory_CONTINUOUS_NIGHTLY)
  SET(${PROJECT_NAME}_TEST_CATEGORIES NIGHTLY)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( ${TEST_NAME} TEST_0 EXEC ${EXEN} CATEGORIES CONTINUOUS )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_${TEST_NAME}: Added test (CONTINUOUS, PROCESSORS=1)!"
    )
  UNITTEST_FILE_REGEX(
    "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}_${TEST_NAME}.cmake"
    REGEX_STRINGS
      "TEST_0_CMND \"${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}\""
      "NUM_CMNDS 1"
    )

  MESSAGE("\n*** Test CATEGORIES NIGHTLY\n")

  MESSAGE("Test CATEGORIES NIGHTLY *not* matching BASIC category set by client")
  SET(TEST_NAME PackageAddAdvancedTestCategory_NIGHTLY_BASIC)
  SET(${PROJECT_NAME}_TEST_CATEGORIES BASIC)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( ${TEST_NAME} TEST_0 EXEC ${EXEN} CATEGORIES NIGHTLY )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_${TEST_NAME}: NOT added test because ${PROJECT_NAME}_TEST_CATEGORIES='BASIC' does not match this test's CATEGORIES='NIGHTLY'!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_CMND_ARRAY_0
    ""
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS
    ""
    )

  MESSAGE("Test CATEGORIES NIGHTLY *not* matching CONTINUOUS category set by client")
  SET(TEST_NAME PackageAddAdvancedTestCategory_NIGHTLY_CONTINUOUS)
  SET(${PROJECT_NAME}_TEST_CATEGORIES CONTINUOUS)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( ${TEST_NAME} TEST_0 EXEC ${EXEN} CATEGORIES NIGHTLY )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_${TEST_NAME}: NOT added test because ${PROJECT_NAME}_TEST_CATEGORIES='CONTINUOUS' does not match this test's CATEGORIES='NIGHTLY'!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_CMND_ARRAY_0
    ""
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS
    ""
    )

  MESSAGE("Test CATEGORIES NIGHTLY matching NIGHTLY category set by client")
  SET(TEST_NAME PackageAddAdvancedTestCategory_NIGHTLY_NIGHTLY)
  SET(${PROJECT_NAME}_TEST_CATEGORIES NIGHTLY)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( ${TEST_NAME} TEST_0 EXEC ${EXEN} CATEGORIES NIGHTLY )
  UNITTEST_FILE_REGEX(
    "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}_${TEST_NAME}.cmake"
    REGEX_STRINGS
      "TEST_0_CMND \"${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}\""
      "NUM_CMNDS 1"
    )

  MESSAGE("Test CATEGORIES NIGHTLY matching HEAVY category set by client")
  SET(TEST_NAME PackageAddAdvancedTestCategory_NIGHTLY_HEAVY)
  SET(${PROJECT_NAME}_TEST_CATEGORIES HEAVY)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( ${TEST_NAME} TEST_0 EXEC ${EXEN} CATEGORIES NIGHTLY )
  UNITTEST_FILE_REGEX(
    "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}_${TEST_NAME}.cmake"
    REGEX_STRINGS
      "TEST_0_CMND \"${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}\""
      "NUM_CMNDS 1"
    )

  MESSAGE("\n*** Test CATEGORIES HEAVY\n")

  MESSAGE("Test CATEGORIES HEAVY *not* matching BASIC category set by client")
  SET(TEST_NAME PackageAddAdvancedTestCategory_HEAVY_BASIC)
  SET(${PROJECT_NAME}_TEST_CATEGORIES BASIC)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( ${TEST_NAME} TEST_0 EXEC ${EXEN} CATEGORIES HEAVY )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_${TEST_NAME}: NOT added test because ${PROJECT_NAME}_TEST_CATEGORIES='BASIC' does not match this test's CATEGORIES='HEAVY'!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_CMND_ARRAY_0
    ""
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS
    ""
    )

  MESSAGE("Test CATEGORIES HEAVY *not* matching CONTINUOUS category set by client")
  SET(TEST_NAME PackageAddAdvancedTestCategory_HEAVY_CONTINUOUS)
  SET(${PROJECT_NAME}_TEST_CATEGORIES CONTINUOUS)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( ${TEST_NAME} TEST_0 EXEC ${EXEN} CATEGORIES HEAVY )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_${TEST_NAME}: NOT added test because ${PROJECT_NAME}_TEST_CATEGORIES='CONTINUOUS' does not match this test's CATEGORIES='HEAVY'!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_CMND_ARRAY_0
    ""
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS
    ""
    )

  MESSAGE("Test CATEGORIES HEAVY *not* matching NIGHTLY category set by client")
  SET(TEST_NAME PackageAddAdvancedTestCategory_HEAVY_NIGHTLY)
  SET(${PROJECT_NAME}_TEST_CATEGORIES NIGHTLY)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( ${TEST_NAME} TEST_0 EXEC ${EXEN} CATEGORIES HEAVY )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_${TEST_NAME}: NOT added test because ${PROJECT_NAME}_TEST_CATEGORIES='NIGHTLY' does not match this test's CATEGORIES='HEAVY'!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_CMND_ARRAY_0
    ""
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS
    ""
    )

  MESSAGE("Test CATEGORIES HEAVY matching HEAVY category set by client")
  SET(TEST_NAME PackageAddAdvancedTestCategory_HEAVY_HEAVY)
  SET(${PROJECT_NAME}_TEST_CATEGORIES HEAVY)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( ${TEST_NAME} TEST_0 EXEC ${EXEN} CATEGORIES HEAVY )
  UNITTEST_FILE_REGEX(
    "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}_${TEST_NAME}.cmake"
    REGEX_STRINGS
      "TEST_0_CMND \"${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}\""
      "NUM_CMNDS 1"
    )

  MESSAGE("\n*** Test CATEGORIES PERFORMANCE\n")

  MESSAGE("Test CATEGORIES PERFORMANCE *not* matching BASIC category set by client")
  SET(TEST_NAME PackageAddAdvancedTestCategory_Empty_Performance)
  SET(${PROJECT_NAME}_TEST_CATEGORIES BASIC)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( ${TEST_NAME} TEST_0 EXEC ${EXEN} CATEGORIES PERFORMANCE )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_${TEST_NAME}: NOT added test because ${PROJECT_NAME}_TEST_CATEGORIES='BASIC' does not match this test's CATEGORIES='PERFORMANCE'!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_CMND_ARRAY_0
    ""
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS
    ""
    )

  MESSAGE("Test CATEGORIES PERFORMANCE *not* matching CONTINUOUS category set by client")
  SET(TEST_NAME PackageAddAdvancedTestCategory_Empty_Performance)
  SET(${PROJECT_NAME}_TEST_CATEGORIES CONTINUOUS)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( ${TEST_NAME} TEST_0 EXEC ${EXEN} CATEGORIES PERFORMANCE )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_${TEST_NAME}: NOT added test because ${PROJECT_NAME}_TEST_CATEGORIES='CONTINUOUS' does not match this test's CATEGORIES='PERFORMANCE'!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_CMND_ARRAY_0
    ""
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS
    ""
    )

  MESSAGE("Test CATEGORIES PERFORMANCE *not* matching NIGHTLY category set by client")
  SET(TEST_NAME PackageAddAdvancedTestCategory_Empty_Performance)
  SET(${PROJECT_NAME}_TEST_CATEGORIES NIGHTLY)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( ${TEST_NAME} TEST_0 EXEC ${EXEN} CATEGORIES PERFORMANCE )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_${TEST_NAME}: NOT added test because ${PROJECT_NAME}_TEST_CATEGORIES='NIGHTLY' does not match this test's CATEGORIES='PERFORMANCE'!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_CMND_ARRAY_0
    ""
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS
    ""
    )

  MESSAGE("Test PERFORMANCE category matching PERFORMANCE category set by client")
  SET(TEST_NAME PackageAddAdvancedTestCategory_Performance_Performance)
  SET(${PROJECT_NAME}_TEST_CATEGORIES PERFORMANCE)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( ${TEST_NAME} TEST_0 EXEC ${EXEN} CATEGORIES PERFORMANCE )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_${TEST_NAME}: Added test (PERFORMANCE, PROCESSORS=1)!"
    )
  UNITTEST_FILE_REGEX(
    "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}_${TEST_NAME}.cmake"
    REGEX_STRINGS
      "TEST_0_CMND \"${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}\""
      "NUM_CMNDS 1"
    )

  MESSAGE("Test PERFORMANCE category matching HEAVY, PERFORMANCE category set by client")
  SET(TEST_NAME PackageAddAdvancedTestCategory_Performance_Heavy_Performance)
  SET(${PROJECT_NAME}_TEST_CATEGORIES PERFORMANCE)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( ${TEST_NAME} TEST_0 EXEC ${EXEN} CATEGORIES HEAVY PERFORMANCE )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_${TEST_NAME}: Added test (HEAVY, PERFORMANCE, PROCESSORS=1)!"
    )
  UNITTEST_FILE_REGEX(
    "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}_${TEST_NAME}.cmake"
    REGEX_STRINGS
      "TEST_0_CMND \"${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}\""
      "NUM_CMNDS 1"
    )

  MESSAGE("Test HEAVY category matching CONTINUOUS, PERFORMANCE category set by client")
  SET(TEST_NAME PackageAddAdvancedTestCategory_Heavy_Continuous_Performance)
  SET(${PROJECT_NAME}_TEST_CATEGORIES HEAVY)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( ${TEST_NAME} TEST_0 EXEC ${EXEN} CATEGORIES CONTINUOUS PERFORMANCE )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_${TEST_NAME}: Added test (CONTINUOUS, PERFORMANCE, PROCESSORS=1)!"
    )
  UNITTEST_FILE_REGEX(
    "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}_${TEST_NAME}.cmake"
    REGEX_STRINGS
      "TEST_0_CMND \"${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}\""
      "NUM_CMNDS 1"
    )

  MESSAGE("Test CONTINUOUS category *not* matching HEAVY, PERFORMANCE category set by client")
  SET(TEST_NAME PackageAddAdvancedTestCategory_Continuous_Heavy_Performance)
  SET(${PROJECT_NAME}_TEST_CATEGORIES CONTINUOUS)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( ${TEST_NAME} TEST_0 EXEC ${EXEN} CATEGORIES HEAVY PERFORMANCE )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_${TEST_NAME}: NOT added test because ${PROJECT_NAME}_TEST_CATEGORIES='CONTINUOUS' does not match this test's CATEGORIES='HEAVY;PERFORMANCE'!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_CMND_ARRAY_0
    ""
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS
    ""
    )

  # NOTE: The above tests ensure that the CATEGORIES argument is accepted and
  # processed correctly.  The unit tests in
  # UNITTEST_TRIBITS_ADD_TEST_CATEGORIES() test the behavior of the logic for
  # selecting tests based on CATEGORIES.

ENDFUNCTION()


FUNCTION(UNITEST_TRIBITS_ADD_ADVANCED_TEST_COMM)

  MESSAGE("\n***")
  MESSAGE("*** Testing TRIBITS_ADD_ADVANCED_TEST( ... COMM ... )")
  MESSAGE("***\n")

  # Needed by TRIBITS_ADD_ADVANCED_TEST(...)
  SET(PACKAGE_NAME PackageA)
  SET(${PACKAGE_NAME}_ENABLE_TESTS ON)

  # Used locally
  SET(EXEN SomeExec)
  SET(PACKEXEN ${PACKAGE_NAME}_${EXEN})
  SET(MPI_EXEC_MAX_NUMPROCS 5)
  SET(MPI_EXEC_DEFAULT_NUMPROCS 3)
  SET(MPI_EXEC mpiexec)
  SET(MPI_EXEC_PRE_NUMPROCS_FLAGS "--pre-num-procs-flags1;--pre-num-procs-flags2")
  SET(MPI_EXEC_NUMPROCS_FLAG --num-procs)
  SET(MPI_EXEC_POST_NUMPROCS_FLAGS "--post-num-procs-flags1;--post-num-procs-flags1;")
  SET(CMNDN ls)

  # Turn on tracing for the rest of the tests!
  SET(${PROJECT_NAME}_TRACE_ADD_TEST ON)
  SET(MESSAGE_WRAPPER_UNIT_TEST_MODE TRUE)

  SET(TRIBITS_ADD_ADVANCED_TEST_SKIP_SCRIPT TRUE)

  # Default serial mode

  MESSAGE("***\n*** Add a test with no COMM argument\n***")
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( DummyTest
    TEST_0 CMND ${CMNDN}
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_CMND_ARRAY_0
    "\"${CMNDN}\""
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS
    1
    )

  MESSAGE("***\n*** Add a serial test with 'COMM serial'\n***")
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( DummyTest
    TEST_0 CMND ${CMNDN}
    COMM serial
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_CMND_ARRAY_0
    "\"${CMNDN}\""
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS
    1
    )

  # Doing MPI mode
  SET(TPL_ENABLE_MPI ON)

  MESSAGE("***\n*** Add serial-only test with 'COMM mpi' (will not add the test)\n***")
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( DummyTest
    TEST_0 CMND ${CMNDN}
    COMM serial
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_CMND_ARRAY_0
    ""
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS
    ""
    )

  MESSAGE("***\n*** Add an advanced test for MPI with no COMM input but with two args\n***")
  GLOBAL_SET(TRIBITS_ADD_TEST_ADD_TEST_INPUT)
  TRIBITS_ADD_ADVANCED_TEST( TAAT_mpi_exec_1_args_2
    TEST_0 EXEC ${EXEN} ARGS arg1 arg2 )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS
    1
    )
  TRIBITS_JOIN_EXEC_PROCESS_SET_ARGS(TRIBITS_ADD_ADVANCED_TEST_CMND_ARRAY_0_EXPECTED
    ${MPI_EXEC} ${MPI_EXEC_PRE_NUMPROCS_FLAGS} ${MPI_EXEC_NUMPROCS_FLAG}
    ${MPI_EXEC_DEFAULT_NUMPROCS} ${MPI_EXEC_POST_NUMPROCS_FLAGS}
    ${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}.exe arg1 arg2 )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_CMND_ARRAY_0
    ${TRIBITS_ADD_ADVANCED_TEST_CMND_ARRAY_0_EXPECTED} )

ENDFUNCTION()


FUNCTION(UNITEST_TRIBITS_ADD_ADVANCED_TEST_NUM_MPI_PROCS)

  MESSAGE("\n***")
  MESSAGE("*** Testing TRIBITS_ADD_ADVANCED_TEST( ... [OVERALL_]_NUM_MPI_PROCS ... )")
  MESSAGE("***\n")

  # Needed by TRIBITS_ADD_ADVANCED_TEST(...)
  SET(PACKAGE_NAME PackageA)
  SET(${PACKAGE_NAME}_ENABLE_TESTS ON)

  # Used locally
  SET(EXEN SomeExec)
  SET(PACKEXEN ${PACKAGE_NAME}_${EXEN})
  SET(MPI_EXEC_MAX_NUMPROCS 5)
  SET(MPI_EXEC_DEFAULT_NUMPROCS 3)
  SET(MPI_EXEC mpiexec)
  SET(MPI_EXEC_PRE_NUMPROCS_FLAGS "--pre-num-procs-flags1;--pre-num-procs-flags2")
  SET(MPI_EXEC_NUMPROCS_FLAG --num-procs)
  SET(MPI_EXEC_POST_NUMPROCS_FLAGS "--post-num-procs-flags1;--post-num-procs-flags1;")
  SET(CMNDN ls)

  SET(TPL_ENABLE_MPI ON)

  # Turn on tracing for the rest of the tests!
  SET(${PROJECT_NAME}_TRACE_ADD_TEST ON)
  SET(MESSAGE_WRAPPER_UNIT_TEST_MODE TRUE)
  SET(TRIBITS_ADD_ADVANCED_TEST_SKIP_SCRIPT TRUE)
  SET(TRIBITS_SET_TEST_PROPERTIES_CAPTURE_INPUT ON)

  MESSAGE("***\n*** CMND-only test and verify PROCESSORS=1\n***")
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( TAAT_mpi_cmnd_0_cmnd_1
    TEST_0 CMND someCmnd TEST_1 CMND someOtherCmnd )
  UNITTEST_COMPARE_CONST( MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_TAAT_mpi_cmnd_0_cmnd_1: Added test (BASIC, PROCESSORS=1)!" )
  UNITTEST_COMPARE_CONST(TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS "2")
  UNITTEST_HAS_SUBSTR_CONST(TRIBITS_SET_TEST_PROPERTIES_INPUT
    "${PACKAGE_NAME}_TAAT_mpi_cmnd_0_cmnd_1;PROPERTIES;PROCESSORS;1")

  MESSAGE("***\n*** CMND-only test with OVERALL_NUM_MPI_PROCS=2 and verify PROCESSORS=2\n***")
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( TAAT_mpi_cmnd_0_cmnd_1
    OVERALL_NUM_MPI_PROCS 2 TEST_0 CMND someCmnd TEST_1 CMND someOtherCmnd )
  UNITTEST_COMPARE_CONST( MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_TAAT_mpi_cmnd_0_cmnd_1: Added test (BASIC, PROCESSORS=2)!" )
  UNITTEST_COMPARE_CONST(TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS "2")
  UNITTEST_HAS_SUBSTR_CONST(TRIBITS_SET_TEST_PROPERTIES_INPUT
    "${PACKAGE_NAME}_TAAT_mpi_cmnd_0_cmnd_1;PROPERTIES;PROCESSORS;2")

  MESSAGE("***\n*** Mix of EXEC and CMND test cases and verify PROCESSORS\n***")
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( TAAT_mpi_cmnd_0_exec_1
    OVERALL_NUM_MPI_PROCS 2 # Set as the default PROCESSORS
    TEST_0 CMND someCmnd TEST_1 EXEC someExec NUM_MPI_PROCS 4 )
  UNITTEST_COMPARE_CONST( MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_TAAT_mpi_cmnd_0_exec_1: Added test (BASIC, NUM_MPI_PROCS=4, PROCESSORS=4)!" )
  UNITTEST_COMPARE_CONST(TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS "2")
  UNITTEST_HAS_SUBSTR_CONST(TRIBITS_SET_TEST_PROPERTIES_INPUT
    "${PACKAGE_NAME}_TAAT_mpi_cmnd_0_exec_1;PROPERTIES;PROCESSORS;4")

  MESSAGE("***\n*** Two EXEC test cases (first num_procs larger) and verify PROCESSORS\n***")
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( TAAT_mpi_cmnd_0_exec_1
    OVERALL_NUM_MPI_PROCS 2 # Set as the default PROCESSORS
    TEST_0 EXEC someExec0 NUM_MPI_PROCS 4 TEST_1 EXEC someExec1 NUM_MPI_PROCS 3 )
  UNITTEST_COMPARE_CONST( MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_TAAT_mpi_cmnd_0_exec_1: Added test (BASIC, NUM_MPI_PROCS=4, PROCESSORS=4)!" )
  UNITTEST_COMPARE_CONST(TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS "2")
  UNITTEST_HAS_SUBSTR_CONST(TRIBITS_SET_TEST_PROPERTIES_INPUT
    "${PACKAGE_NAME}_TAAT_mpi_cmnd_0_exec_1;PROPERTIES;PROCESSORS;4")

  MESSAGE("***\n*** Two EXEC test cases (second num_procs larger) and verify PROCESSORS\n***")
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( TAAT_mpi_cmnd_0_exec_1
    OVERALL_NUM_MPI_PROCS 2 # Set as the default PROCESSORS
    TEST_0 EXEC someExec0 NUM_MPI_PROCS 3 TEST_1 EXEC someExec1 NUM_MPI_PROCS 4 )
  UNITTEST_COMPARE_CONST( MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_TAAT_mpi_cmnd_0_exec_1: Added test (BASIC, NUM_MPI_PROCS=4, PROCESSORS=4)!" )
  UNITTEST_COMPARE_CONST(TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS "2")
  UNITTEST_HAS_SUBSTR_CONST(TRIBITS_SET_TEST_PROPERTIES_INPUT
    "${PACKAGE_NAME}_TAAT_mpi_cmnd_0_exec_1;PROPERTIES;PROCESSORS;4")

  MESSAGE("***\n*** Two EXEC test cases (overall_num_procs larger) and verify PROCESSORS\n***")
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( TAAT_mpi_cmnd_0_exec_1
    OVERALL_NUM_MPI_PROCS 5 # Set as the default PROCESSORS
    TEST_0 EXEC someExec0 NUM_MPI_PROCS 3 TEST_1 EXEC someExec1 NUM_MPI_PROCS 4 )
  UNITTEST_COMPARE_CONST( MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_TAAT_mpi_cmnd_0_exec_1: Added test (BASIC, NUM_MPI_PROCS=5, PROCESSORS=5)!" )
  UNITTEST_COMPARE_CONST(TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS "2")
  UNITTEST_HAS_SUBSTR_CONST(TRIBITS_SET_TEST_PROPERTIES_INPUT
    "${PACKAGE_NAME}_TAAT_mpi_cmnd_0_exec_1;PROPERTIES;PROCESSORS;5")

  # ToDo: Add EXEC test where OVERALL_NUM_MPI_PROCS < MPI_EXEC_MAX_NUMPROCS

  # ToDo: Add EXEC test where NUM_MPI_PROCS < MPI_EXEC_MAX_NUMPROCS

  # ToDo: Add EXEC test where OVERALL_NUM_MPI_PROCS == MPI_EXEC_MAX_NUMPROCS

  # ToDo: Add EXEC test where NUM_MPI_PROCS == MPI_EXEC_MAX_NUMPROCS

  MESSAGE("***\n*** Add EXEC test where OVERALL_NUM_MPI_PROCS > MPI_EXEC_MAX_NUMPROCS\n***")
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( TAAT_mpi_exec_0_exec_1
    OVERALL_NUM_MPI_PROCS 6 TEST_0 EXEC someExec TEST_1 EXEC someOtherExec )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_TAAT_mpi_exec_0_exec_1: NOT added test because OVERALL_NUM_MPI_PROCS='6' > MPI_EXEC_MAX_NUMPROCS='5'!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS
    ""
    )

  MESSAGE("***\n*** Add EXEC test where NUM_MPI_PROCS > MPI_EXEC_MAX_NUMPROCS\n***")
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( TAAT_mpi_exec_0_exec_1
    OVERALL_NUM_MPI_PROCS 2 TEST_0 EXEC someExec TEST_1 EXEC someOtherExec NUM_MPI_PROCS 7 )
  UNITTEST_COMPARE_CONST(
    MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_TAAT_mpi_exec_0_exec_1: NOT added test because NUM_MPI_PROCS='7' > MPI_EXEC_MAX_NUMPROCS='5'!"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS
    ""
    )

  MESSAGE("***\n*** Add CMND test setting OVERALL_NUM_TOTAL_CORES_USED\n***")
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( TAAT_mpi_cmnd_0
    OVERALL_NUM_TOTAL_CORES_USED 4 TEST_0 CMND someCmnd )
  UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_TAAT_mpi_cmnd_0: Added test (BASIC, PROCESSORS=4)!" )
  UNITTEST_COMPARE_CONST(TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS "1")
  UNITTEST_HAS_SUBSTR_CONST(TRIBITS_SET_TEST_PROPERTIES_INPUT
    "${PACKAGE_NAME}_TAAT_mpi_cmnd_0;PROPERTIES;PROCESSORS;4")

  MESSAGE("***\n*** Add CMND test setting OVERALL_NUM_TOTAL_CORES_USED and NUM_TOTAL_CORES_USED\n***")
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( TAAT_mpi_cmnd_0
    OVERALL_NUM_TOTAL_CORES_USED 2 TEST_0 CMND someCmnd NUM_TOTAL_CORES_USED 3 )
  UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_TAAT_mpi_cmnd_0: Added test (BASIC, PROCESSORS=3)!" )
  UNITTEST_COMPARE_CONST(TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS "1")
  UNITTEST_HAS_SUBSTR_CONST(TRIBITS_SET_TEST_PROPERTIES_INPUT
    "${PACKAGE_NAME}_TAAT_mpi_cmnd_0;PROPERTIES;PROCESSORS;3")

  MESSAGE("***\n*** Add CMDN 2 test setting OVERALL_NUM_TOTAL_CORES_USED and NUM_TOTAL_CORES_USED \n***")
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( TAAT_mpi_cmnd_0
    OVERALL_NUM_TOTAL_CORES_USED 1
       TEST_0 CMND someCmnd1 NUM_TOTAL_CORES_USED 2
       TEST_1 CMND someCmnd2 NUM_TOTAL_CORES_USED 3 )
  UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_TAAT_mpi_cmnd_0: Added test (BASIC, PROCESSORS=3)!" )
  UNITTEST_COMPARE_CONST(TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS "2")
  UNITTEST_HAS_SUBSTR_CONST(TRIBITS_SET_TEST_PROPERTIES_INPUT
    "${PACKAGE_NAME}_TAAT_mpi_cmnd_0;PROPERTIES;PROCESSORS;3")

  MESSAGE("***\n*** Add CMDN 2 test setting OVERALL_NUM_TOTAL_CORES_USED and NUM_TOTAL_CORES_USED \n***")
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( TAAT_mpi_cmnd_0
    OVERALL_NUM_TOTAL_CORES_USED 1
       TEST_0 CMND someCmnd1 NUM_TOTAL_CORES_USED 3
       TEST_1 CMND someCmnd2 NUM_TOTAL_CORES_USED 2 )
  UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_TAAT_mpi_cmnd_0: Added test (BASIC, PROCESSORS=3)!" )
  UNITTEST_COMPARE_CONST(TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS "2")
  UNITTEST_HAS_SUBSTR_CONST(TRIBITS_SET_TEST_PROPERTIES_INPUT
    "${PACKAGE_NAME}_TAAT_mpi_cmnd_0;PROPERTIES;PROCESSORS;3")

  MESSAGE("***\n*** Add CMDN 2 test setting OVERALL_NUM_TOTAL_CORES_USED and NUM_TOTAL_CORES_USED \n***")
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( TAAT_mpi_cmnd_0
    OVERALL_NUM_TOTAL_CORES_USED 3
       TEST_0 CMND someCmnd1 NUM_TOTAL_CORES_USED 1
       TEST_1 CMND someCmnd2 NUM_TOTAL_CORES_USED 2 )
  UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_TAAT_mpi_cmnd_0: Added test (BASIC, PROCESSORS=2)!" )
  UNITTEST_COMPARE_CONST(TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS "2")
  UNITTEST_HAS_SUBSTR_CONST(TRIBITS_SET_TEST_PROPERTIES_INPUT
    "${PACKAGE_NAME}_TAAT_mpi_cmnd_0;PROPERTIES;PROCESSORS;2")

  MESSAGE("***\n*** Add EXEC test setting OVERALL_NUM_TOTAL_CORES_USED > NUM_MPI_PROCS\n***")
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( TAAT_mpi_exec_0
    OVERALL_NUM_TOTAL_CORES_USED 4 TEST_0 EXEC someExec NUM_MPI_PROCS 2 )
  UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_TAAT_mpi_exec_0: Added test (BASIC, PROCESSORS=4)!" )
  UNITTEST_COMPARE_CONST(TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS "1")
  UNITTEST_HAS_SUBSTR_CONST(TRIBITS_SET_TEST_PROPERTIES_INPUT
    "${PACKAGE_NAME}_TAAT_mpi_exec_0;PROPERTIES;PROCESSORS;4")

  MESSAGE("***\n*** Add EXEC test setting OVERALL_NUM_TOTAL_CORES_USED < NUM_MPI_PROCS\n***")
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( TAAT_mpi_exec_0
    OVERALL_NUM_TOTAL_CORES_USED 1 TEST_0 EXEC someExec NUM_MPI_PROCS 2 )
  UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
    "FATAL_ERROR;ERROR: ${PACKAGE_NAME}_TAAT_mpi_exec_0: NUM_MPI_PROCS='2' > OVERALL_NUM_TOTAL_CORES_USED='1' not allowed!" )
  UNITTEST_COMPARE_CONST(TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS "")

  MESSAGE("***\n*** Add EXEC test setting OVERALL_NUM_TOTAL_CORES_USED and NUM_TOTAL_CORES_USED\n***")
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( TAAT_mpi_exec_0
    OVERALL_NUM_TOTAL_CORES_USED 1
       TEST_0 EXEC someExec NUM_MPI_PROCS 2 NUM_TOTAL_CORES_USED 3 )
  UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_TAAT_mpi_exec_0: Added test (BASIC, PROCESSORS=3)!" )
  UNITTEST_COMPARE_CONST(TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS "1")
  UNITTEST_HAS_SUBSTR_CONST(TRIBITS_SET_TEST_PROPERTIES_INPUT
    "${PACKAGE_NAME}_TAAT_mpi_exec_0;PROPERTIES;PROCESSORS;3")

  MESSAGE("***\n*** Add EXEC test setting OVERALL_NUM_MPI_PROCS < NUM_TOTAL_CORES_USED\n***")
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( TAAT_mpi_exec_0
    OVERALL_NUM_TOTAL_CORES_USED 4  OVERALL_NUM_MPI_PROCS 2
       TEST_0 EXEC someExec )
  UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_TAAT_mpi_exec_0: Added test (BASIC, NUM_MPI_PROCS=2, PROCESSORS=4)!" )
  UNITTEST_COMPARE_CONST(TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS "1")
  UNITTEST_HAS_SUBSTR_CONST(TRIBITS_SET_TEST_PROPERTIES_INPUT
    "${PACKAGE_NAME}_TAAT_mpi_exec_0;PROPERTIES;PROCESSORS;4")

  MESSAGE("***\n*** Add EXEC test setting OVERALL_NUM_MPI_PROCS > NUM_TOTAL_CORES_USED\n***")
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( TAAT_mpi_exec_0
    OVERALL_NUM_TOTAL_CORES_USED 2  OVERALL_NUM_MPI_PROCS 3
       TEST_0 EXEC someExec )
  UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
    "FATAL_ERROR;ERROR: ${PACKAGE_NAME}_TAAT_mpi_exec_0: OVERALL_NUM_MPI_PROCS='3' > OVERALL_NUM_TOTAL_CORES_USED='2' not allowed!" )
  UNITTEST_COMPARE_CONST(TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS "")

  MESSAGE("***\n*** Add CMND test setting OVERALL_NUM_MPI_PROCS < NUM_TOTAL_CORES_USED\n***")
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( TAAT_mpi_cmnd_0
    OVERALL_NUM_TOTAL_CORES_USED 4  OVERALL_NUM_MPI_PROCS 2
       TEST_0 CMND someCmnd )
  UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_TAAT_mpi_cmnd_0: Added test (BASIC, PROCESSORS=4)!" )
  UNITTEST_COMPARE_CONST(TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS "1")
  UNITTEST_HAS_SUBSTR_CONST(TRIBITS_SET_TEST_PROPERTIES_INPUT
    "${PACKAGE_NAME}_TAAT_mpi_cmnd_0;PROPERTIES;PROCESSORS;4")

  MESSAGE("***\n*** Add CMDN test setting OVERALL_NUM_MPI_PROCS > OVERALL_NUM_TOTAL_CORES_USED\n***")
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( TAAT_mpi_cmnd_0
    OVERALL_NUM_TOTAL_CORES_USED 2  OVERALL_NUM_MPI_PROCS 3
       TEST_0 CMND someCmnd )
  UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
    "FATAL_ERROR;ERROR: ${PACKAGE_NAME}_TAAT_mpi_cmnd_0: OVERALL_NUM_MPI_PROCS='3' > OVERALL_NUM_TOTAL_CORES_USED='2' not allowed!" )
  UNITTEST_COMPARE_CONST(TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS "")

  MESSAGE("***\n*** Add EXEC test setting OVERALL_NUM_MPI_PROCS > NUM_TOTAL_CORES_USED\n***")
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( TAAT_mpi_exec_0
    OVERALL_NUM_MPI_PROCS 3
       TEST_0 EXEC someExec NUM_TOTAL_CORES_USED 2 )
  UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
    "FATAL_ERROR;ERROR: ${PACKAGE_NAME}_TAAT_mpi_exec_0: OVERALL_NUM_MPI_PROCS='3' > NUM_TOTAL_CORES_USED='2' not allowed!" )
  UNITTEST_COMPARE_CONST(TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS "")

  MESSAGE("***\n*** Add EXEC test setting NUM_MPI_PROCS > NUM_TOTAL_CORES_USED\n***")
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( TAAT_mpi_exec_0
       TEST_0 EXEC someExec NUM_MPI_PROCS 3 NUM_TOTAL_CORES_USED 2 )
  UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
    "FATAL_ERROR;ERROR: ${PACKAGE_NAME}_TAAT_mpi_exec_0: NUM_MPI_PROCS='3' > NUM_TOTAL_CORES_USED='2' not allowed!" )
  UNITTEST_COMPARE_CONST(TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS "")

  MESSAGE("***\n*** Add EXEC test setting NUM_MPI_PROCS > OVERALL_NUM_TOTAL_CORES_USED\n***")
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( TAAT_mpi_exec_0
       OVERALL_NUM_TOTAL_CORES_USED 2
       TEST_0 EXEC someExec NUM_MPI_PROCS 3 )
  UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
    "FATAL_ERROR;ERROR: ${PACKAGE_NAME}_TAAT_mpi_exec_0: NUM_MPI_PROCS='3' > OVERALL_NUM_TOTAL_CORES_USED='2' not allowed!" )
  UNITTEST_COMPARE_CONST(TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS "")

ENDFUNCTION()


FUNCTION(UNITEST_TRIBITS_ADD_ADVANCED_TEST_DIRECTROY)

  MESSAGE("\n***")
  MESSAGE("*** Testing TRIBITS_ADD_ADVANCED_TEST( ... DIRECTORY ... )")
  MESSAGE("***\n")


  # Needed by TRIBITS_ADD_TEST(...)
  SET(PACKAGE_NAME PackageA)
  SET(${PACKAGE_NAME}_ENABLE_TESTS ON)

  SET(TRIBITS_ADD_ADVANCED_TEST_SKIP_SCRIPT FALSE)

  # Used locally
  SET(EXEN SomeExec)
  SET(PACKEXEN ${PACKAGE_NAME}_${EXEN}.exe)

  MESSAGE("\n*** Two tests with no DIRECTORY argument \n")
  SET(TEST_NAME PackageAddAdvancedTestDirectory_None)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( ${TEST_NAME} TEST_0 EXEC ${EXEN} TEST_1 EXEC ${EXEN} )
  UNITTEST_FILE_REGEX(
    "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}_${TEST_NAME}.cmake"
    REGEX_STRINGS
      "TEST_0_CMND \"${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}\""
      "TEST_1_CMND \"${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}\""
      "NUM_CMNDS 2"
    )

  MESSAGE("\n*** Two tests, first test with DIRECTORY argument \n")
  SET(TEST_NAME PackageAddAdvancedTestDirectory_None)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( ${TEST_NAME} TEST_0 EXEC ${EXEN} DIRECTORY ../dir1 TEST_1 EXEC ${EXEN} )
  UNITTEST_FILE_REGEX(
    "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}_${TEST_NAME}.cmake"
    REGEX_STRINGS
      "TEST_0_CMND \"${CMAKE_CURRENT_BINARY_DIR}/../dir1/${PACKEXEN}\""
      "TEST_1_CMND \"${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}\""
      "NUM_CMNDS 2"
    )

  MESSAGE("\n*** Two tests, second test with relative DIRECTORY argument \n")
  SET(TEST_NAME PackageAddAdvancedTestDirectory_None)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( ${TEST_NAME} TEST_0 EXEC ${EXEN} TEST_1 EXEC ${EXEN} DIRECTORY ../dir2 )
  UNITTEST_FILE_REGEX(
    "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}_${TEST_NAME}.cmake"
    REGEX_STRINGS
      "TEST_0_CMND \"${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}\""
      "TEST_1_CMND \"${CMAKE_CURRENT_BINARY_DIR}/../dir2/${PACKEXEN}\""
      "NUM_CMNDS 2"
    )


  MESSAGE("\n*** Two tests, second test with absolute DIRECTORY argument \n")
  SET(TEST_NAME PackageAddAdvancedTestDirectory_None)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( ${TEST_NAME} TEST_0 EXEC ${EXEN} TEST_1 EXEC ${EXEN} DIRECTORY /some/abs/path )
  UNITTEST_FILE_REGEX(
    "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}_${TEST_NAME}.cmake"
    REGEX_STRINGS
      "TEST_0_CMND \"${CMAKE_CURRENT_BINARY_DIR}/${PACKEXEN}\""
      "TEST_1_CMND \"/some/abs/path/${PACKEXEN}\""
      "NUM_CMNDS 2"
    )

  MESSAGE("\n*** Two tests, both tests with DIRECTORY argument \n")
  SET(TEST_NAME PackageAddAdvancedTestDirectory_None)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( ${TEST_NAME} TEST_0 EXEC ${EXEN} DIRECTORY ../dir1 TEST_1 EXEC ${EXEN} DIRECTORY ../dir2 )
  UNITTEST_FILE_REGEX(
    "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}_${TEST_NAME}.cmake"
    REGEX_STRINGS
      "TEST_0_CMND \"${CMAKE_CURRENT_BINARY_DIR}/../dir1/${PACKEXEN}\""
      "TEST_1_CMND \"${CMAKE_CURRENT_BINARY_DIR}/../dir2/${PACKEXEN}\""
      "NUM_CMNDS 2"
    )

ENDFUNCTION()


FUNCTION(UNITEST_TRIBITS_ADD_ADVANCED_TEST_PROPERTIES)

  MESSAGE("\n***")
  MESSAGE("*** Testing the setting of test properties with TRIBITS_ADD_ADVANCED_TEST(...)")
  MESSAGE("***\n")

  SET(TRIBITS_SET_TEST_PROPERTIES_CAPTURE_INPUT ON)
  SET(TRIBITS_ADD_ADVANCED_TEST_SKIP_SCRIPT TRUE)

  # Needed by TRIBITS_ADD_ADVANCED_TEST(...)
  SET(PACKAGE_NAME PackageA)
  SET(${PACKAGE_NAME}_ENABLE_TESTS ON)

  # Used locally
  SET(EXEN SomeExec)
  SET(PACKEXEN ${PACKAGE_NAME}_${EXEN}.exe)
  SET(CMNDN someCmnd)

  # Turn on tracing for the rest of the tests!
  SET(${PROJECT_NAME}_TRACE_ADD_TEST ON)
  SET(MESSAGE_WRAPPER_UNIT_TEST_MODE TRUE)

  MESSAGE("Test setting default properites")
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( TAAT_basic_cmnd_1_args_0
    TEST_0 CMND ${CMNDN}
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_SET_TEST_PROPERTIES_INPUT
    "PackageA_TAAT_basic_cmnd_1_args_0;PROPERTY;REQUIRED_FILES;someCmnd;PackageA_TAAT_basic_cmnd_1_args_0;APPEND;PROPERTY;LABELS;PackageA_TAAT_basic_cmnd_1_args_0;PROPERTIES;PROCESSORS;1;PackageA_TAAT_basic_cmnd_1_args_0;PROPERTIES;PASS_REGULAR_EXPRESSION;OVERALL FINAL RESULT: TEST PASSED .PackageA_TAAT_basic_cmnd_1_args_0."
    )
  # NOTE: Above, in unit test mode, TRIBITS_ADD_ADVANCED_TEST() changes is
  # final pass expression so as to not match the outer run of
  # TRIBITS_ADD_ADVANCED_TEST() that looks for it.  Otherwise, the outer
  # TRIBITS_ADD_ADVANCED_TEST() always thinks these unit tests pass!

  MESSAGE("Test setting non-integer TIMEOUT with no scaling (not even defined)")
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( TAAT_basic_cmnd_1_args_0
    TEST_0 CMND ${CMNDN} TIMEOUT 333.0 )
  UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
    "-- PackageA_TAAT_basic_cmnd_1_args_0: Added test (BASIC, PROCESSORS=1, TIMEOUT=333.0)!" )
  UNITTEST_HAS_SUBSTR_CONST(TRIBITS_SET_TEST_PROPERTIES_INPUT
    "PackageA_TAAT_basic_cmnd_1_args_0;PROPERTIES;TIMEOUT;333.0")

  MESSAGE("Test non-integral scaling 1.5 of non-integer TIMEOUT")
  SET(${PROJECT_NAME}_SCALE_TEST_TIMEOUT 1.5)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( TAAT_basic_cmnd_1_args_0
    TEST_0 CMND ${CMNDN} TIMEOUT 200.0 )
  UNITTEST_HAS_SUBSTR_CONST(TRIBITS_SET_TEST_PROPERTIES_INPUT
    "PackageA_TAAT_basic_cmnd_1_args_0;PROPERTIES;TIMEOUT;300")
  SET(${PROJECT_NAME}_SCALE_TEST_TIMEOUT 1.0)

  MESSAGE("Test setting ENVIRONMENT")
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( TAAT_basic_cmnd_1_args_0
    TEST_0 CMND ${CMNDN} ENVIRONMENT var1=val1 var2=val2 )
  UNITTEST_HAS_SUBSTR_CONST(TRIBITS_SET_TEST_PROPERTIES_INPUT
    "PackageA_TAAT_basic_cmnd_1_args_0;PROPERTY;ENVIRONMENT;var1=val1;var2=val2")

  SET(TRIBITS_SET_TEST_PROPERTIES_CAPTURE_INPUT OFF)
  SET(TRIBITS_ADD_ADVANCED_TEST_SKIP_SCRIPT OFF)

ENDFUNCTION()


FUNCTION(UNITEST_TRIBITS_ADD_ADVANCED_TEST_EXCLUDES)

  MESSAGE("\n***")
  MESSAGE("*** Testing excluding TRIBITS_ADD_ADVANCED_TEST(...) based on different criteria")
  MESSAGE("***\n")

  # Needed by TRIBITS_ADD_TEST(...)
  SET(PACKAGE_NAME PackageA)
  SET(${PACKAGE_NAME}_ENABLE_TESTS ON)

  # Turn on tracing for the rest of the tests!
  SET(${PROJECT_NAME}_TRACE_ADD_TEST ON)
  SET(MESSAGE_WRAPPER_UNIT_TEST_MODE TRUE)
  SET(TRIBITS_ADD_ADVANCED_TEST_SKIP_SCRIPT TRUE)
  SET(TRIBITS_SET_TEST_PROPERTIES_CAPTURE_INPUT ON)

  # Used locally
  SET(EXEN SomeExec)
  SET(PACKEXEN ${PACKAGE_NAME}_${EXEN}.exe)

  MESSAGE("***\n*** EXCLUDE_IF_NOT_TRUE <true>\n***")
  SET(VAR_THAT_IS_TRUE TRUE)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( TAAT_mpi_cmnd_0_cmnd_1
     EXCLUDE_IF_NOT_TRUE  VAR_THAT_IS_TRUE
    TEST_0 CMND someCmnd TEST_1 CMND someOtherCmnd )
  UNITTEST_COMPARE_CONST( MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_TAAT_mpi_cmnd_0_cmnd_1: Added test (BASIC, PROCESSORS=1)!" )
  UNITTEST_COMPARE_CONST(TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS "2")
  UNITTEST_HAS_SUBSTR_CONST(TRIBITS_SET_TEST_PROPERTIES_INPUT
    "${PACKAGE_NAME}_TAAT_mpi_cmnd_0_cmnd_1;PROPERTIES;PROCESSORS;1")

  MESSAGE("***\n*** EXCLUDE_IF_NOT_TRUE <true> <true>\n***")
  SET(VAR_THAT_IS_TRUE1 TRUE)
  SET(VAR_THAT_IS_TRUE2 TRUE)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( TAAT_mpi_cmnd_0_cmnd_1
     EXCLUDE_IF_NOT_TRUE VAR_THAT_IS_TRUE1 VAR_THAT_IS_TRUE2
    TEST_0 CMND someCmnd TEST_1 CMND someOtherCmnd )
  UNITTEST_COMPARE_CONST( MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_TAAT_mpi_cmnd_0_cmnd_1: Added test (BASIC, PROCESSORS=1)!" )
  UNITTEST_COMPARE_CONST(TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS "2")
  UNITTEST_HAS_SUBSTR_CONST(TRIBITS_SET_TEST_PROPERTIES_INPUT
    "${PACKAGE_NAME}_TAAT_mpi_cmnd_0_cmnd_1;PROPERTIES;PROCESSORS;1")

  MESSAGE("***\n*** EXCLUDE_IF_NOT_TRUE <false>\n***")
  SET(VAR_THAT_IS_FALSE FALSE)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( TAAT_mpi_cmnd_0_cmnd_1
    EXCLUDE_IF_NOT_TRUE  VAR_THAT_IS_FALSE
    TEST_0 CMND someCmnd TEST_1 CMND someOtherCmnd )
  UNITTEST_COMPARE_CONST( MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_TAAT_mpi_cmnd_0_cmnd_1: NOT added test because EXCLUDE_IF_NOT_TRUE VAR_THAT_IS_FALSE='FALSE'!" )
  UNITTEST_COMPARE_CONST(TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS "")
  UNITTEST_HAS_SUBSTR_CONST(TRIBITS_SET_TEST_PROPERTIES_INPUT
    "")

  MESSAGE("***\n*** EXCLUDE_IF_NOT_TRUE <true> <false>\n***")
  SET(VAR_THAT_IS_TRUE TRUE)
  SET(VAR_THAT_IS_FALSE FALSE)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( TAAT_mpi_cmnd_0_cmnd_1
    EXCLUDE_IF_NOT_TRUE  VAR_THAT_IS_TRUE  VAR_THAT_IS_FALSE
    TEST_0 CMND someCmnd TEST_1 CMND someOtherCmnd )
  UNITTEST_COMPARE_CONST( MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_TAAT_mpi_cmnd_0_cmnd_1: NOT added test because EXCLUDE_IF_NOT_TRUE VAR_THAT_IS_FALSE='FALSE'!" )
  UNITTEST_COMPARE_CONST(TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS "")
  UNITTEST_HAS_SUBSTR_CONST(TRIBITS_SET_TEST_PROPERTIES_INPUT
    "")

  MESSAGE("***\n*** EXCLUDE_IF_NOT_TRUE <false> <true>\n***")
  SET(VAR_THAT_IS_TRUE TRUE)
  SET(VAR_THAT_IS_FALSE FALSE)
  TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
  TRIBITS_ADD_ADVANCED_TEST( TAAT_mpi_cmnd_0_cmnd_1
    EXCLUDE_IF_NOT_TRUE  VAR_THAT_IS_FALSE  VAR_THAT_IS_TRUE
    TEST_0 CMND someCmnd TEST_1 CMND someOtherCmnd )
  UNITTEST_COMPARE_CONST( MESSAGE_WRAPPER_INPUT
    "-- ${PACKAGE_NAME}_TAAT_mpi_cmnd_0_cmnd_1: NOT added test because EXCLUDE_IF_NOT_TRUE VAR_THAT_IS_FALSE='FALSE'!" )
  UNITTEST_COMPARE_CONST(TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS "")
  UNITTEST_HAS_SUBSTR_CONST(TRIBITS_SET_TEST_PROPERTIES_INPUT
    "")

ENDFUNCTION()


FUNCTION(UNITEST_TRIBITS_ADD_EXECUTABLE_AND_TEST)

  SET(TRIBITS_ADD_EXECUTABLE_AND_TEST_TEST_MODE ON)

  MESSAGE("\n***")
  MESSAGE("*** Test passing basic arguments to TRIBITS_ADD_EXECUTABLE_AND_TEST( ... )")
  MESSAGE("***\n")

  SET(PACKAGE_NAME PackageA)
  SET(${PACKAGE_NAME}_ENABLE_TESTS ON)

  TRIBITS_ADD_EXECUTABLE_AND_TEST(
    execName
    SOURCES src1 src2
    NAME testName
    NAME_POSTFIX testNamePostfix
    CATEGORIES category1 category2
    HOST host1 host2
    DEPLIBS lib1 lib2  # Deprecated
    XHOST host1 host2
    HOSTTYPE hosttype1 hosttype2
    XHOSTTYPE hosttype1 hosttype2
    EXCLUDE_IF_NOT_TRUE var1 var2
    NOEXEPREFIX
    NOEXESUFFIX
    IMPORTEDLIBS ilib1 ilib2
    TESTONLYLIBS tolib1 tolib2
    DIRECTORY dir
    COMM serial mpi
    NUM_MPI_PROCS numProcs
    LINKER_LANGUAGE C
    ADD_DIR_TO_NAME
    TARGET_DEFINES -DSOMEDEFINE1
    DEFINES -DSOMEDEFINE2
    KEYWORDS keyword1 keyword2
    STANDARD_PASS_OUTPUT
    PASS_REGULAR_EXPRESSION "regex1;regex2"
    FAIL_REGULAR_EXPRESSION "regex1;regex2"
    ENVIRONMENT env1=envval1 env2=envval2
    WILL_FAIL
    TIMEOUT 11.5
    ADDED_EXE_TARGET_NAME_OUT execName_TARGET_NAME
    ADDED_TESTS_NAMES_OUT execName_TEST_NAME
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_EXECUTABLE_CAPTURE_ARGS
    "execName;COMM;serial;mpi;CATEGORIES;category1;category2;HOST;host1;host2;XHOST;host1;host2;HOSTTYPE;hosttype1;hosttype2;XHOSTTYPE;hosttype1;hosttype2;EXCLUDE_IF_NOT_TRUE;var1;var2;NOEXEPREFIX;NOEXESUFFIX;SOURCES;src1;src2;DEPLIBS;lib1;lib2;TESTONLYLIBS;tolib1;tolib2;IMPORTEDLIBS;ilib1;ilib2;DIRECTORY;dir;ADD_DIR_TO_NAME;LINKER_LANGUAGE;C;TARGET_DEFINES;-DSOMEDEFINE1;DEFINES;-DSOMEDEFINE2;ADDED_EXE_TARGET_NAME_OUT;ADDED_EXE_TARGET_NAME"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_CAPTURE_ARGS
    "execName;COMM;serial;mpi;CATEGORIES;category1;category2;HOST;host1;host2;XHOST;host1;host2;HOSTTYPE;hosttype1;hosttype2;XHOSTTYPE;hosttype1;hosttype2;EXCLUDE_IF_NOT_TRUE;var1;var2;NOEXEPREFIX;NOEXESUFFIX;NAME;testName;NAME_POSTFIX;testNamePostfix;DIRECTORY;dir;KEYWORDS;keyword1;keyword2;NUM_MPI_PROCS;numProcs;PASS_REGULAR_EXPRESSION;regex1;regex2;FAIL_REGULAR_EXPRESSION;regex1;regex2;ENVIRONMENT;env1=envval1;env2=envval2;STANDARD_PASS_OUTPUT;WILL_FAIL;TIMEOUT;11.5;ADD_DIR_TO_NAME;ADDED_TESTS_NAMES_OUT;ADDED_TESTS_NAMES_OUT;ADDED_TESTS_NAMES"
    )

  MESSAGE("\n***")
  MESSAGE("*** Test passing in XHOST_TEST and XHOSTTYPE_TEST into TRIBITS_ADD_EXECUTABLE_AND_TEST(...)")
  MESSAGE("***\n")

  TRIBITS_ADD_EXECUTABLE_AND_TEST(
    execName
    SOURCES src1 src2
    XHOST_TEST host1 host2
    XHOSTTYPE_TEST hosttype1 hosttype2
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_EXECUTABLE_CAPTURE_ARGS
    "execName;SOURCES;src1;src2"
    )
  UNITTEST_COMPARE_CONST(
    TRIBITS_ADD_TEST_CAPTURE_ARGS
    "execName;XHOST;host1;host2;XHOSTTYPE;hosttype1;hosttype2"
    )

ENDFUNCTION()


FUNCTION(UNITTEST_TRIBITS_ETI_TYPE_EXPANSION)

  MESSAGE("*** Test passing invalid arguments to TRIBITS_ETI_TYPE_EXPANSION( ... )\n")

  SET(result "This is left over from other module!")  # See #199

  UNSET(expansion)
  TRIBITS_ETI_TYPE_EXPANSION(expansion "badformat")
  UNITTEST_COMPARE_CONST(
    expansion
    "TRIBITS_ETI_BAD_ARGUMENTS"
    )

  MESSAGE("*** Test passing valid arguments to TRIBITS_ETI_TYPE_EXPANSION( ... )\n")

  # test rank-one
  UNSET(expansion)
  TRIBITS_ETI_TYPE_EXPANSION(expansion "f1=ta|tb")
  UNITTEST_COMPARE_CONST(
    expansion
    "f1={ta};f1={tb}"
    )

  # test accumulation into ${expansion}
  TRIBITS_ETI_TYPE_EXPANSION(expansion "f2=tc|td|te")
  UNITTEST_COMPARE_CONST(
    expansion
    "f1={ta};f1={tb};f2={tc};f2={td};f2={te}"
    )

  # test rank-two
  UNSET(expansion)
  TRIBITS_ETI_TYPE_EXPANSION(expansion "f1=ta|tb" "f2=tc")
  UNITTEST_COMPARE_CONST(
    expansion
    "f1={ta} f2={tc};f1={tb} f2={tc}"
    )

  # test rank-three
  UNSET(expansion)
  TRIBITS_ETI_TYPE_EXPANSION(expansion "f1=ta|tb" "f2=tc" "f3=td|te")
  UNITTEST_COMPARE_CONST(
    expansion
    "f1={ta} f2={tc} f3={td};f1={ta} f2={tc} f3={te};f1={tb} f2={tc} f3={td};f1={tb} f2={tc} f3={te}"
    )

ENDFUNCTION()


FUNCTION(UNITTEST_TRIBITS_ETI_CHECK_EXCLUSION)

  MESSAGE("*** Test passing valid arguments to TRIBITS_ETI_CHECK_EXCLUSION( ... )\n")

  message("empty exclusion list...")
  TRIBITS_ETI_CHECK_EXCLUSION("" "ta|tb|tc" result)
  UNITTEST_COMPARE_CONST(
    result
    OFF
  )

  message("inst not excluded (no match)...")
  TRIBITS_ETI_CHECK_EXCLUSION("td|te|tf" "ta|tb|tc" result)
  UNITTEST_COMPARE_CONST(
    result
    OFF
  )

  message("matches only on present types...")
  TRIBITS_ETI_CHECK_EXCLUSION("ta|ta|tb" "ta|TYPE-MISSING|tb" result)
  UNITTEST_COMPARE_CONST(
    result
    ON
  )

  message("no match: exclusion has the wrong rank (not an error)...")
  TRIBITS_ETI_CHECK_EXCLUSION("ta|ta" "ta|tb|tc" result)
  UNITTEST_COMPARE_CONST(
    result
    OFF
  )

  message("inst not excluded (partial match)...")
  TRIBITS_ETI_CHECK_EXCLUSION("ta|tb|ta;tb|tb|tc;ta|ta|tc" "ta|tb|tc" result)
  UNITTEST_COMPARE_CONST(
    result
    OFF
  )

  message("inst exluded (full explicit)...")
  TRIBITS_ETI_CHECK_EXCLUSION("abcdf;ta|tb|tc" "ta|tb|tc" result)
  UNITTEST_COMPARE_CONST(
    result
    ON
  )

  message("inst exluded (full regex)...")
  TRIBITS_ETI_CHECK_EXCLUSION("abcdf;.*|.*|.*" "ta|tb|tc" result)
  UNITTEST_COMPARE_CONST(
    result
    ON
  )

ENDFUNCTION()


FUNCTION(UNITTEST_TRIBITS_ETI_INDEX_MACRO_FIELDS)

  MESSAGE("*** Test passing valid arguments to TRIBITS_ETI_INDEX_MACRO_FIELDS( ... )\n")

  # check simple
  TRIBITS_ETI_INDEX_MACRO_FIELDS("F1;F2;F3" "F3" var)
  UNITTEST_COMPARE_CONST(
    var
    "2"
    )

  # check complex
  TRIBITS_ETI_INDEX_MACRO_FIELDS("F1;F2;F3" "F3;F2;F1" var)
  UNITTEST_COMPARE_CONST(
    var
    "2;1;0"
    )

  # check complex with spaces
  TRIBITS_ETI_INDEX_MACRO_FIELDS("F1;F2;F3" " F2 ;   F2 ; F2 " var)
  UNITTEST_COMPARE_CONST(
    var
    "1;1;1"
    )

ENDFUNCTION()


FUNCTION(UNITTEST_TRIBITS_ADD_ETI_INSTANTIATIONS_INITIAL)

  MESSAGE("*** Testing TRIBITS_ADD_ETI_INSTANTIATIONS... )\n")

  SET(package ${PROJECT_NAME}Framework)
  GLOBAL_NULL_SET(${package}_ETI_LIBRARYSET)
  TRIBITS_ADD_ETI_INSTANTIATIONS(${package} "someinst")
  UNITTEST_COMPARE_CONST(
    ${package}_ETI_LIBRARYSET
    "someinst"
    )

ENDFUNCTION()

FUNCTION(UNITTEST_TRIBITS_ADD_ETI_INSTANTIATIONS_CUMULATIVE)

  SET(package ${PROJECT_NAME}Framework)
  TRIBITS_ADD_ETI_INSTANTIATIONS(${package} "anotherinst")
  UNITTEST_COMPARE_CONST(
    ${package}_ETI_LIBRARYSET
    "someinst;anotherinst"
    )

ENDFUNCTION()


FUNCTION(UNITTEST_TRIBITS_ETI_EXPLODE)

  MESSAGE("*** Test passing valid arguments to TRIBITS_ETI_EXPLODE( ... )\n")

  # no fields -> no results
  SET(FIELDS "")
  TRIBITS_ETI_EXPLODE("${FIELDS}" "F1=type1 F2=type2 F3=type3" parsed)
  UNITTEST_COMPARE_CONST(
    parsed
    ""
    )

  # order doesn't matter; also, results should be bracketed
  SET(FIELDS F FF G)
  TRIBITS_ETI_EXPLODE("${FIELDS}" "F=type1 FF=type2 G={type3}" parsed)
  UNITTEST_COMPARE_CONST(
    parsed
    "type1|type2|type3"
    )
  TRIBITS_ETI_EXPLODE("${FIELDS}" "FF=type2 F={type1} G=type3" parsed)
  UNITTEST_COMPARE_CONST(
    parsed
    "type1|type2|type3"
    )
  TRIBITS_ETI_EXPLODE("${FIELDS}" "G=type3 FF=type2 F={type1}" parsed)
  UNITTEST_COMPARE_CONST(
    parsed
    "type1|type2|type3"
    )

  # empty for missing fields

  # missing field handled properly, extra fields ignored
  SET(FIELDS F FF G)
  TRIBITS_ETI_EXPLODE("${FIELDS}" "F=type1 G=type3 H=type4" parsed)
  UNITTEST_COMPARE_CONST(
    parsed
    "type1|TYPE-MISSING|type3"
    )

  # bad bracketing doesn't work
  TRIBITS_ETI_EXPLODE("F" "F=typea}" parsed)
  UNITTEST_COMPARE_CONST(
    parsed
    "TRIBITS_ETI_BAD_PARSE"
    )
  TRIBITS_ETI_EXPLODE("F" "F={typea" parsed)
  UNITTEST_COMPARE_CONST(
    parsed
    "TRIBITS_ETI_BAD_PARSE"
    )
  TRIBITS_ETI_EXPLODE("F" "F={typea}}" parsed)
  UNITTEST_COMPARE_CONST(
    parsed
    "TRIBITS_ETI_BAD_PARSE"
    )
  TRIBITS_ETI_EXPLODE("F" "F={{typea}" parsed)
  UNITTEST_COMPARE_CONST(
    parsed
    "TRIBITS_ETI_BAD_PARSE"
    )
  TRIBITS_ETI_EXPLODE("F" "F=typeaG=typeb" parsed)
  UNITTEST_COMPARE_CONST(
    parsed
    "TRIBITS_ETI_BAD_PARSE"
    )

ENDFUNCTION()

FUNCTION(UNITTEST_TRIBITS_ETI_MANGLE_SYMBOL)

  MESSAGE("*** Testing ETI Mangling ***")

  # this one is ugly...
  TRIBITS_ETI_MANGLE_SYMBOL(mangled "std::pair< std::complex< double > , std::complex< float > >")
  UNITTEST_COMPARE_CONST(
    mangled
    "std_pair2std_complex1double1_std_complex0float02")

  # test that POD isn't mangled, and that the method accumulates into the typedef list
  SET(defs_orig "do not delete")
  SET(defs "${defs_orig}")
  SET(symbol "double")
  SET(mangling_list "")
  TRIBITS_ETI_MANGLE_SYMBOL_AUGMENT_MACRO(defs symbol mangling_list)
  UNITTEST_COMPARE_CONST(
    symbol
    "double")
  UNITTEST_COMPARE_CONST(
    defs
    "${defs_orig}")
  UNITTEST_COMPARE_CONST(
    mangling_list
    "")

  # this is more like what we expect
  SET(defs "")
  SET(mangling_list "")
  #
  SET(symbol "std::complex<float>")
  TRIBITS_ETI_MANGLE_SYMBOL_AUGMENT_MACRO(defs symbol mangling_list)
  UNITTEST_COMPARE_CONST(
    symbol
    "std_complex0float0")
  #
  SET(symbol "std::pair<float,float>")
  TRIBITS_ETI_MANGLE_SYMBOL_AUGMENT_MACRO(defs symbol mangling_list)
  UNITTEST_COMPARE_CONST(
    symbol
    "std_pair0float_float0")
  #
  UNITTEST_COMPARE_CONST(
    mangling_list
    "std_complex0float0;std_pair0float_float0")
  UNITTEST_COMPARE_CONST(
    defs
    "typedef std::complex<float> std_complex0float0;typedef std::pair<float,float> std_pair0float_float0")

ENDFUNCTION()


FUNCTION(UNITTEST_TRIBITS_ETI_GENERATE_MACROS)

  MESSAGE("*** Test TRIBITS_ETI_GENERATE_MACROS( ... )\n")

  TRIBITS_ETI_TYPE_EXPANSION(
    etiset
    "F1=Teuchos::ArrayRCP<Teuchos::ArrayRCP<double> > | double"
    "F2=int | long"
    "F3=float"
  )
  TRIBITS_ETI_TYPE_EXPANSION(
    exclset
    "F1=.*"
    "F2=long"
    "F3=.*"
  )
  TRIBITS_ETI_GENERATE_MACROS(
    "F1|F2|F3"
    "${etiset}"
    "${exclset}"
    mangling_list     typedef_list
    "F1(F1)"          macro_f1_var
    "F312(F3,F1,F2)"  macro_f312_var
  )
  UNITTEST_COMPARE_CONST(
    macro_f1_var
"#define F1(INSTMACRO)\\
\tINSTMACRO( Teuchos_ArrayRCP1Teuchos_ArrayRCP0double01 )\\
\tINSTMACRO( double )
"
    )
  UNITTEST_COMPARE_CONST(
    macro_f312_var
"#define F312(INSTMACRO)\\
\tINSTMACRO( float , Teuchos_ArrayRCP1Teuchos_ArrayRCP0double01 , int )\\
\tINSTMACRO( float , double , int )
"
    )
  UNITTEST_COMPARE_CONST(
    typedef_list
    "typedef Teuchos::ArrayRCP<Teuchos::ArrayRCP<double> > Teuchos_ArrayRCP1Teuchos_ArrayRCP0double01")
  UNITTEST_COMPARE_CONST(
    mangling_list
    "Teuchos_ArrayRCP1Teuchos_ArrayRCP0double01")

  SET(mangling_list "")
  SET(typedef_list  "")
  TRIBITS_ETI_GENERATE_MACROS(
    "F1|F2"
    "F1=a F2=b;F2=c;G1=d G2=e;G3=f"
    ""
    mangling_list     typedef_list
    "F2(F2)"          macro_f2_var
    "F12(F1,F2)"      macro_f12_var
  )
  UNITTEST_COMPARE_CONST( typedef_list "")
  UNITTEST_COMPARE_CONST( mangling_list "")
  UNITTEST_COMPARE_CONST(
    macro_f2_var
"#define F2(INSTMACRO)\\
\tINSTMACRO( b )\\
\tINSTMACRO( c )
")
  UNITTEST_COMPARE_CONST(
    macro_f12_var
"#define F12(INSTMACRO)\\
\tINSTMACRO( a , b )
")

ENDFUNCTION()

#
# Execute the unit tests
#

# Set up some global environment stuff
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)

# Set up the TRIBITS_ADD_TEST(...) and TRIBITS_ADD_ADVANCED_TEST() functions
# for unit test mode.
SET( TRIBITS_ADD_TEST_ADD_TEST_UNITTEST TRUE )

# Capture the ADD_TEST() arguments for TRIBITS_ADD_TEST().
SET( TRIBITS_ADD_TEST_ADD_TEST_CAPTURE TRUE )

MESSAGE("\n***")
MESSAGE("*** Running little bits of tests")
MESSAGE("***\n")

UNITTEST_APPEND_STRING_VAR()
UNITTEST_TRIBITS_FIND_PYTHON_INTERP()
UNITEST_TRIBITS_MISC()
UNITTEST_TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE()

# Set the default test categories
SET(${PROJECT_NAME}_TEST_CATEGORIES NIGHTLY)

MESSAGE("\n***")
MESSAGE("*** Testing TRIBITS_ADD_TEST(...)")
MESSAGE("***\n")

UNITEST_TRIBITS_ADD_TEST_BASIC()
UNITEST_TRIBITS_ADD_TEST_CATEGORIES()
UNITEST_TRIBITS_ADD_TEST_COMM()
UNITEST_TRIBITS_ADD_TEST_PROPERTIES()
UNITEST_TRIBITS_ADD_ADVANCED_TEST_EXCLUDES()

MESSAGE("\n***")
MESSAGE("*** Testing TRIBITS_ADD_ADVANCED_TEST(...)")
MESSAGE("***\n")

UNITEST_TRIBITS_ADD_ADVANCED_TEST_BASIC()
UNITEST_TRIBITS_ADD_ADVANCED_TEST_CATEGORIES()
UNITEST_TRIBITS_ADD_ADVANCED_TEST_COMM()
UNITEST_TRIBITS_ADD_ADVANCED_TEST_NUM_MPI_PROCS()
UNITEST_TRIBITS_ADD_ADVANCED_TEST_DIRECTROY()
UNITEST_TRIBITS_ADD_ADVANCED_TEST_PROPERTIES()

UNITEST_TRIBITS_ADD_TEST_DISABLE()

MESSAGE("\n***")
MESSAGE("*** Testing TRIBITS_ADD_EXECUTABLE_AND_TEST(...)")
MESSAGE("***\n")

UNITEST_TRIBITS_ADD_EXECUTABLE_AND_TEST()

MESSAGE("\n***")
MESSAGE("*** Testing Explicit Template Instantiation functionality")
MESSAGE("***\n")

UNITTEST_TRIBITS_ETI_EXPLODE()
UNITTEST_TRIBITS_ETI_TYPE_EXPANSION()
UNITTEST_TRIBITS_ETI_CHECK_EXCLUSION()
UNITTEST_TRIBITS_ETI_INDEX_MACRO_FIELDS()
UNITTEST_TRIBITS_ADD_ETI_INSTANTIATIONS_INITIAL()
UNITTEST_TRIBITS_ADD_ETI_INSTANTIATIONS_CUMULATIVE()
UNITTEST_TRIBITS_ETI_MANGLE_SYMBOL()
UNITTEST_TRIBITS_ETI_GENERATE_MACROS()

MESSAGE("\n***")
MESSAGE("*** Determine final result of all unit tests")
MESSAGE("***\n")

# Pass in the number of expected tests that must pass!
UNITTEST_FINAL_RESULT(499)
