# @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"
  )

INCLUDE(TribitsCMakePolicies)
INCLUDE(TribitsProcessExtraRepositoriesList)
INCLUDE(UnitTestHelpers)
INCLUDE(GlobalSet)


#####################################################################
#
# Unit tests for code in TribitsProcessExtraRepositoriesList.cmake
#
#####################################################################


FUNCTION(UNITTEST_TRIBITS_PARSE_EXTRAREPO_PACKSTAT)

  MESSAGE("\n*** Test TRIBITS_PARSE_EXTRAREPO_PACKSTAT(), PACKSTAT=''\n")
  TRIBITS_PARSE_EXTRAREPO_PACKSTAT(""  HASPKGS  PREPOST)
  UNITTEST_COMPARE_CONST( HASPKGS "HASPACKAGES")
  UNITTEST_COMPARE_CONST( PREPOST "POST")

  MESSAGE("\n*** Test TRIBITS_PARSE_EXTRAREPO_PACKSTAT(), PACKSTAT='NOPACKAGES'\n")
  TRIBITS_PARSE_EXTRAREPO_PACKSTAT("NOPACKAGES"  HASPKGS  PREPOST)
  UNITTEST_COMPARE_CONST( HASPKGS "NOPACKAGES")
  UNITTEST_COMPARE_CONST( PREPOST "POST")

  MESSAGE("\n*** Test TRIBITS_PARSE_EXTRAREPO_PACKSTAT(), PACKSTAT='POST'\n")
  TRIBITS_PARSE_EXTRAREPO_PACKSTAT("POST"  HASPKGS  PREPOST)
  UNITTEST_COMPARE_CONST( HASPKGS "HASPACKAGES")
  UNITTEST_COMPARE_CONST( PREPOST "POST")

  MESSAGE("\n*** Test TRIBITS_PARSE_EXTRAREPO_PACKSTAT(), PACKSTAT='HASPACKAGES'\n")
  TRIBITS_PARSE_EXTRAREPO_PACKSTAT("HASPACKAGES"  HASPKGS  PREPOST)
  UNITTEST_COMPARE_CONST( HASPKGS "HASPACKAGES")
  UNITTEST_COMPARE_CONST( PREPOST "POST")

  MESSAGE("\n*** Test TRIBITS_PARSE_EXTRAREPO_PACKSTAT(), PACKSTAT='HASPACKAGES,POST'\n")
  TRIBITS_PARSE_EXTRAREPO_PACKSTAT("HASPACKAGES,POST"  HASPKGS  PREPOST)
  UNITTEST_COMPARE_CONST( HASPKGS "HASPACKAGES")
  UNITTEST_COMPARE_CONST( PREPOST "POST")

  MESSAGE("\n*** Test TRIBITS_PARSE_EXTRAREPO_PACKSTAT(), PACKSTAT=',POST'\n")
  TRIBITS_PARSE_EXTRAREPO_PACKSTAT(",POST"  HASPKGS  PREPOST)
  UNITTEST_COMPARE_CONST( HASPKGS "HASPACKAGES")
  UNITTEST_COMPARE_CONST( PREPOST "POST")

  MESSAGE("\n*** Test TRIBITS_PARSE_EXTRAREPO_PACKSTAT(), PACKSTAT='POST,HASPACKAGES'\n")
  TRIBITS_PARSE_EXTRAREPO_PACKSTAT("POST,HASPACKAGES"  HASPKGS  PREPOST)
  UNITTEST_COMPARE_CONST( HASPKGS "HASPACKAGES")
  UNITTEST_COMPARE_CONST( PREPOST "POST")

  MESSAGE("\n*** Test TRIBITS_PARSE_EXTRAREPO_PACKSTAT(), PACKSTAT='HASPACKAGES, POST'\n")
  TRIBITS_PARSE_EXTRAREPO_PACKSTAT("HASPACKAGES, POST"  HASPKGS  PREPOST)
  UNITTEST_COMPARE_CONST( HASPKGS "HASPACKAGES")
  UNITTEST_COMPARE_CONST( PREPOST "POST")

  MESSAGE("\n*** Test TRIBITS_PARSE_EXTRAREPO_PACKSTAT(), PACKSTAT='PRE'\n")
  TRIBITS_PARSE_EXTRAREPO_PACKSTAT("PRE"  HASPKGS  PREPOST)
  UNITTEST_COMPARE_CONST( HASPKGS "HASPACKAGES")
  UNITTEST_COMPARE_CONST( PREPOST "PRE")

  MESSAGE("\n*** Test TRIBITS_PARSE_EXTRAREPO_PACKSTAT(), PACKSTAT='PRE,NOPACKAGES'\n")
  TRIBITS_PARSE_EXTRAREPO_PACKSTAT("PRE,NOPACKAGES"  HASPKGS  PREPOST)
  UNITTEST_COMPARE_CONST( HASPKGS "NOPACKAGES")
  UNITTEST_COMPARE_CONST( PREPOST "PRE")

  MESSAGE("\n*** Test TRIBITS_PARSE_EXTRAREPO_PACKSTAT(), PACKSTAT='NOPACKAGES,PRE'\n")
  TRIBITS_PARSE_EXTRAREPO_PACKSTAT("NOPACKAGES,PRE"  HASPKGS  PREPOST)
  UNITTEST_COMPARE_CONST( HASPKGS "NOPACKAGES")
  UNITTEST_COMPARE_CONST( PREPOST "PRE")

  MESSAGE("\n*** Test TRIBITS_PARSE_EXTRAREPO_PACKSTAT(), PACKSTAT='BAD'\n")
  SET(MESSAGE_WRAPPER_UNIT_TEST_MODE  TRUE)
  GLOBAL_SET(MESSAGE_WRAPPER_INPUT)
  TRIBITS_PARSE_EXTRAREPO_PACKSTAT("BAD"  HASPKGS  PREPOST)
  UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
    "FATAL_ERROR;Error, the value of 'PACKSTAT' element; 'BAD' is not valid!  Valid choices are '' (empty),; 'HASPACKAGES', 'NOPACKAGES', 'PRE', and 'POST'.  The defaults if all; fields are empty are 'HASPACKAGES' and 'POST'")
  UNITTEST_COMPARE_CONST( HASPKGS "HASPACKAGES")
  UNITTEST_COMPARE_CONST( PREPOST "POST")

ENDFUNCTION()


FUNCTION(UNITTEST_TRIBITS_PROCESS_EXTRAREPOS_LISTS)

  MESSAGE("\n***")
  MESSAGE("*** Test TRIBITS_PROCESS_EXTRAREPOS_LISTS() getting Nightly")
  MESSAGE("***\n")

  #SET(TRIBITS_PROCESS_EXTRAREPOS_LISTS_DEBUG  TRUE)

  SET(${PROJECT_NAME}_ENABLE_KNOWN_EXTERNAL_REPOS_TYPE  Nightly)

  TRIBITS_PROJECT_DEFINE_EXTRA_REPOSITORIES(
     repo0_name  ""              GIT   "git@url0.com:repo0"  ""           Continuous
     repo1_name  "some/sub/dir"  SVN   "git@url1.com:repo1"  NOPACKAGES   Nightly
     )
  
  TRIBITS_PROCESS_EXTRAREPOS_LISTS()

  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_DEFAULT
    "repo0_name;repo1_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_DIRS
    "repo0_name;some/sub/dir")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_VCTYPES
    "GIT;SVN")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_REPOURLS
    "git@url0.com:repo0;git@url1.com:repo1")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_HASPKGS
    "HASPACKAGES;NOPACKAGES")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_PREPOSTS
    "POST;POST")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_CATEGORIES
    "Continuous;Nightly")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_PRE_REPOSITORIES_DEFAULT
    "")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_EXTRA_REPOSITORIES_DEFAULT
    "repo0_name;repo1_name")

  MESSAGE("\n***")
  MESSAGE("*** Test TRIBITS_PROCESS_EXTRAREPOS_LISTS() getting Continuous")
  MESSAGE("***\n")

  #SET(TRIBITS_PROCESS_EXTRAREPOS_LISTS_DEBUG  TRUE)

  SET(${PROJECT_NAME}_ENABLE_KNOWN_EXTERNAL_REPOS_TYPE  Continuous)

  TRIBITS_PROJECT_DEFINE_EXTRA_REPOSITORIES(
     repo0_name  ""              GIT   "git@url0.com:repo0"  ""           Continuous
     repo1_name  "some/sub/dir"  SVN   "git@url1.com:repo1"  NOPACKAGES   Nightly
     )
  
  TRIBITS_PROCESS_EXTRAREPOS_LISTS()

  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_DEFAULT
    "repo0_name;repo1_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_DIRS
    "repo0_name;some/sub/dir")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_VCTYPES
    "GIT;SVN")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_REPOURLS
    "git@url0.com:repo0;git@url1.com:repo1")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_HASPKGS
    "HASPACKAGES;NOPACKAGES")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_PREPOSTS
    "POST;POST")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_CATEGORIES
    "Continuous;Nightly")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_PRE_REPOSITORIES_DEFAULT
    "")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_EXTRA_REPOSITORIES_DEFAULT
    "repo0_name;repo1_name")

  MESSAGE("\n***")
  MESSAGE("*** Test TRIBITS_PROCESS_EXTRAREPOS_LISTS() PACKSTAT='PRE,HASPACKAGES'")
  MESSAGE("***\n")

  #SET(TRIBITS_PROCESS_EXTRAREPOS_LISTS_DEBUG  TRUE)

  SET(${PROJECT_NAME}_ENABLE_KNOWN_EXTERNAL_REPOS_TYPE  Continuous)

  TRIBITS_PROJECT_DEFINE_EXTRA_REPOSITORIES(
     repo0_name  ""              GIT   "git@url0.com:repo0"  "PRE,HASPACKAGES"           Continuous
     )
  
  TRIBITS_PROCESS_EXTRAREPOS_LISTS()

  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_DEFAULT
    "repo0_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_DIRS
    "repo0_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_VCTYPES
    "GIT")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_REPOURLS
    "git@url0.com:repo0")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_HASPKGS
    "HASPACKAGES")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_PREPOSTS
    "PRE")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_CATEGORIES
    "Continuous")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_PRE_REPOSITORIES_DEFAULT
    "repo0_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_EXTRA_REPOSITORIES_DEFAULT
    "")

  MESSAGE("\n***")
  MESSAGE("*** Test TRIBITS_PROCESS_EXTRAREPOS_LISTS() empty VC type and URL")
  MESSAGE("***\n")

  #SET(TRIBITS_PROCESS_EXTRAREPOS_LISTS_DEBUG  TRUE)

  SET(${PROJECT_NAME}_ENABLE_KNOWN_EXTERNAL_REPOS_TYPE  Continuous)

  TRIBITS_PROJECT_DEFINE_EXTRA_REPOSITORIES(
     repo0_name  ""              ""   ""  ""           Continuous
     )
  
  TRIBITS_PROCESS_EXTRAREPOS_LISTS()

  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_DEFAULT
    "repo0_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_DIRS
    "repo0_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_VCTYPES
    "")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_REPOURLS
    "")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_HASPKGS
    "HASPACKAGES")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_PREPOSTS
    "POST")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_CATEGORIES
    "Continuous")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_PRE_REPOSITORIES_DEFAULT
    "")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_EXTRA_REPOSITORIES_DEFAULT
    "repo0_name")

  # ToDo: Test error when setting non-empty REPOURL when REPOTYPE is empty

  # ToDo: Test error when invalid VC type is given

  MESSAGE("\n***")
  MESSAGE("*** Test TRIBITS_PROCESS_EXTRAREPOS_LISTS() POST before PRE")
  MESSAGE("***\n")

  SET(${PROJECT_NAME}_ENABLE_KNOWN_EXTERNAL_REPOS_TYPE  Nightly)
  SET(MESSAGE_WRAPPER_UNIT_TEST_MODE  TRUE)
  GLOBAL_SET(MESSAGE_WRAPPER_INPUT)

  TRIBITS_PROJECT_DEFINE_EXTRA_REPOSITORIES(
     repo0_name  ""              GIT   "git@url0.com:repo0"  POST  Continuous
     repo1_name  "some/sub/dir"  SVN   "git@url1.com:repo1"  PRE   Nightly
     )
  
  TRIBITS_PROCESS_EXTRAREPOS_LISTS()

  UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
    "FATAL_ERROR;Error, the 'PRE' extra repo 'repo1_name'; specified in the PACKSTAT field 'PRE' came directly after; a 'POST' extra repo!  All 'PRE' extra repos must be listed before all; 'POST' extra repos!")

  # ToDo: Test that all PRE repos come before all POST repos

ENDFUNCTION()


FUNCTION(UNITTEST_TRIBITS_PROCESS_EXTRAREPOS_LISTS_OLD_REPOTYPE)

  MESSAGE("\n***")
  MESSAGE("*** Test TRIBITS_PROCESS_EXTRAREPOS_LISTS() with old REPOTYPE var name")
  MESSAGE("***\n")

  #SET(TRIBITS_PROCESS_EXTRAREPOS_LISTS_DEBUG  TRUE)

  SET(${PROJECT_NAME}_ENABLE_KNOWN_EXTERNAL_REPOS_TYPE  Continuous)

  SET( ${PROJECT_NAME}_EXTRAREPOS_DIR_REPOTYPE_REPOURL_PACKSTAT_CATEGORY
     repo0_name  ""              GIT   "git@url0.com:repo0"  ""           Continuous
     )
  
  TRIBITS_PROCESS_EXTRAREPOS_LISTS()

  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_DEFAULT
    "repo0_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_DIRS
    "repo0_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_VCTYPES
    "GIT")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_REPOURLS
    "git@url0.com:repo0")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_HASPKGS
    "HASPACKAGES")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_PREPOSTS
    "POST")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_CATEGORIES
    "Continuous")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_PRE_REPOSITORIES_DEFAULT
    "")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_EXTRA_REPOSITORIES_DEFAULT
    "repo0_name")

ENDFUNCTION()


FUNCTION(UNITTEST_TRIBITS_GET_AND_PROCESS_EXTRA_REPOSITORIES_LISTS)

  SET(${PROJECT_NAME}_EXTRAREPOS_FILE  "${CMAKE_CURRENT_LIST_DIR}/emptyFile.cmake")

  TRIBITS_PROJECT_DEFINE_EXTRA_REPOSITORIES(
     repo0_name  ""              GIT   "git@url0.com:repo0"  PRE               Continuous
     repo1_name  ""              SVN   "git@url1.com:repo1"  PRE,HASPACKAGES   Continuous
     repo2_name  "some/sub/dir"  SVN   "git@url2.com:repo2"  NOPACKAGES        Nightly
     repo3_name  ""              GIT   "git@url3.com:repo3"  POST              Nightly
     )

  MESSAGE("\n***")
  MESSAGE("*** Test TRIBITS_GET_AND_PROCESS_EXTRA_REPOSITORIES_LISTS() empty PRE_REPOSITORIES and EXTRA_REPOSITORIES ")
  MESSAGE("***\n")

  #SET(TRIBITS_PROCESS_EXTRAREPOS_LISTS_DEBUG  TRUE)

  SET(${PROJECT_NAME}_ENABLE_KNOWN_EXTERNAL_REPOS_TYPE  Nightly)
  SET(${PROJECT_NAME}_PRE_REPOSITORIES "")
  SET(${PROJECT_NAME}_EXTRA_REPOSITORIES  "")
  
  TRIBITS_GET_AND_PROCESS_EXTRA_REPOSITORIES_LISTS()

  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_PRE_REPOSITORIES_DEFAULT
    "repo0_name;repo1_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_EXTRA_REPOSITORIES_DEFAULT
    "repo2_name;repo3_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_DEFAULT
    "repo0_name;repo1_name;repo2_name;repo3_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_PRE_REPOSITORIES
    "repo0_name;repo1_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_EXTRA_REPOSITORIES
    "repo2_name;repo3_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES
    "repo0_name;repo1_name;repo2_name;repo3_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_DIRS
    "repo0_name;repo1_name;some/sub/dir;repo3_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_VCTYPES
    "GIT;SVN;SVN;GIT")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_REPOURLS
    "git@url0.com:repo0;git@url1.com:repo1;git@url2.com:repo2;git@url3.com:repo3")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_HASPKGS
    "HASPACKAGES;HASPACKAGES;NOPACKAGES;HASPACKAGES")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_PREPOSTS
    "PRE;PRE;POST;POST")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_CATEGORIES
    "Continuous;Continuous;Nightly;Nightly")

  MESSAGE("\n***")
  MESSAGE("*** Test TRIBITS_GET_AND_PROCESS_EXTRA_REPOSITORIES_LISTS(), EXTRA_REPOSITORIES=repo2_name")
  MESSAGE("***\n")

  #SET(TRIBITS_PROCESS_EXTRAREPOS_LISTS_DEBUG  TRUE)

  SET(${PROJECT_NAME}_ENABLE_KNOWN_EXTERNAL_REPOS_TYPE  Nightly)
  SET(${PROJECT_NAME}_PRE_REPOSITORIES "")
  SET(${PROJECT_NAME}_EXTRA_REPOSITORIES  repo2_name)
  
  TRIBITS_GET_AND_PROCESS_EXTRA_REPOSITORIES_LISTS()

  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_PRE_REPOSITORIES_DEFAULT
    "repo0_name;repo1_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_EXTRA_REPOSITORIES_DEFAULT
    "repo2_name;repo3_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_DEFAULT
    "repo0_name;repo1_name;repo2_name;repo3_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_PRE_REPOSITORIES
    "repo0_name;repo1_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_EXTRA_REPOSITORIES
    "repo2_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES
    "repo0_name;repo1_name;repo2_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_DIRS
    "repo0_name;repo1_name;some/sub/dir")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_VCTYPES
    "GIT;SVN;SVN")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_REPOURLS
    "git@url0.com:repo0;git@url1.com:repo1;git@url2.com:repo2")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_HASPKGS
    "HASPACKAGES;HASPACKAGES;NOPACKAGES")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_PREPOSTS
    "PRE;PRE;POST")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_CATEGORIES
    "Continuous;Continuous;Nightly")

  MESSAGE("\n***")
  MESSAGE("*** Test TRIBITS_GET_AND_PROCESS_EXTRA_REPOSITORIES_LISTS(), EXTRA_REPOSITORIES=repo3_name")
  MESSAGE("***\n")

  #SET(TRIBITS_PROCESS_EXTRAREPOS_LISTS_DEBUG  TRUE)

  SET(${PROJECT_NAME}_ENABLE_KNOWN_EXTERNAL_REPOS_TYPE  Nightly)
  SET(${PROJECT_NAME}_PRE_REPOSITORIES "")
  SET(${PROJECT_NAME}_EXTRA_REPOSITORIES  repo3_name)
  
  TRIBITS_GET_AND_PROCESS_EXTRA_REPOSITORIES_LISTS()

  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_PRE_REPOSITORIES_DEFAULT
    "repo0_name;repo1_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_EXTRA_REPOSITORIES_DEFAULT
    "repo2_name;repo3_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_DEFAULT
    "repo0_name;repo1_name;repo2_name;repo3_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_PRE_REPOSITORIES
    "repo0_name;repo1_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_EXTRA_REPOSITORIES
    "repo3_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES
    "repo0_name;repo1_name;repo3_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_DIRS
    "repo0_name;repo1_name;repo3_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_VCTYPES
    "GIT;SVN;GIT")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_REPOURLS
    "git@url0.com:repo0;git@url1.com:repo1;git@url3.com:repo3")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_HASPKGS
    "HASPACKAGES;HASPACKAGES;HASPACKAGES")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_PREPOSTS
    "PRE;PRE;POST")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_CATEGORIES
    "Continuous;Continuous;Nightly")

  MESSAGE("\n***")
  MESSAGE("*** Test TRIBITS_GET_AND_PROCESS_EXTRA_REPOSITORIES_LISTS(), PRE_REPOSITORIES=repo0_name")
  MESSAGE("***\n")

  #SET(TRIBITS_PROCESS_EXTRAREPOS_LISTS_DEBUG  TRUE)

  SET(${PROJECT_NAME}_ENABLE_KNOWN_EXTERNAL_REPOS_TYPE  Nightly)
  SET(${PROJECT_NAME}_PRE_REPOSITORIES repo0_name)
  SET(${PROJECT_NAME}_EXTRA_REPOSITORIES  "")
  
  TRIBITS_GET_AND_PROCESS_EXTRA_REPOSITORIES_LISTS()

  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_PRE_REPOSITORIES_DEFAULT
    "repo0_name;repo1_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_EXTRA_REPOSITORIES_DEFAULT
    "repo2_name;repo3_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_DEFAULT
    "repo0_name;repo1_name;repo2_name;repo3_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_PRE_REPOSITORIES
    "repo0_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_EXTRA_REPOSITORIES
    "repo2_name;repo3_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES
    "repo0_name;repo2_name;repo3_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_DIRS
    "repo0_name;some/sub/dir;repo3_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_VCTYPES
    "GIT;SVN;GIT")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_REPOURLS
    "git@url0.com:repo0;git@url2.com:repo2;git@url3.com:repo3")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_HASPKGS
    "HASPACKAGES;NOPACKAGES;HASPACKAGES")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_PREPOSTS
    "PRE;POST;POST")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_CATEGORIES
    "Continuous;Nightly;Nightly")

  MESSAGE("\n***")
  MESSAGE("*** Test TRIBITS_GET_AND_PROCESS_EXTRA_REPOSITORIES_LISTS(), PRE_REPOSITORIES=repo1_name")
  MESSAGE("***\n")

  #SET(TRIBITS_PROCESS_EXTRAREPOS_LISTS_DEBUG  TRUE)

  SET(${PROJECT_NAME}_ENABLE_KNOWN_EXTERNAL_REPOS_TYPE  Nightly)
  SET(${PROJECT_NAME}_PRE_REPOSITORIES repo1_name)
  SET(${PROJECT_NAME}_EXTRA_REPOSITORIES  "")
  
  TRIBITS_GET_AND_PROCESS_EXTRA_REPOSITORIES_LISTS()

  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_PRE_REPOSITORIES_DEFAULT
    "repo0_name;repo1_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_EXTRA_REPOSITORIES_DEFAULT
    "repo2_name;repo3_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_DEFAULT
    "repo0_name;repo1_name;repo2_name;repo3_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_PRE_REPOSITORIES
    "repo1_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_EXTRA_REPOSITORIES
    "repo2_name;repo3_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES
    "repo1_name;repo2_name;repo3_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_DIRS
    "repo1_name;some/sub/dir;repo3_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_VCTYPES
    "SVN;SVN;GIT")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_REPOURLS
    "git@url1.com:repo1;git@url2.com:repo2;git@url3.com:repo3")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_HASPKGS
    "HASPACKAGES;NOPACKAGES;HASPACKAGES")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_PREPOSTS
    "PRE;POST;POST")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_CATEGORIES
    "Continuous;Nightly;Nightly")

  MESSAGE("\n***")
  MESSAGE("*** Test TRIBITS_GET_AND_PROCESS_EXTRA_REPOSITORIES_LISTS(), PRE_REPOSITORIES=repo0_name, EXTRA_REPOSITORIES=repo3_name")
  MESSAGE("***\n")

  SET(${PROJECT_NAME}_ENABLE_KNOWN_EXTERNAL_REPOS_TYPE  Nightly)
  SET(${PROJECT_NAME}_PRE_REPOSITORIES repo0_name)
  SET(${PROJECT_NAME}_EXTRA_REPOSITORIES  repo3_name)
  
  TRIBITS_GET_AND_PROCESS_EXTRA_REPOSITORIES_LISTS()

  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_PRE_REPOSITORIES_DEFAULT
    "repo0_name;repo1_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_EXTRA_REPOSITORIES_DEFAULT
    "repo2_name;repo3_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_DEFAULT
    "repo0_name;repo1_name;repo2_name;repo3_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_PRE_REPOSITORIES
    "repo0_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_EXTRA_REPOSITORIES
    "repo3_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES
    "repo0_name;repo3_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_DIRS
    "repo0_name;repo3_name")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_VCTYPES
    "GIT;GIT")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_REPOURLS
    "git@url0.com:repo0;git@url3.com:repo3")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_HASPKGS
    "HASPACKAGES;HASPACKAGES")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_PREPOSTS
    "PRE;POST")
  UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_CATEGORIES
    "Continuous;Nightly")

ENDFUNCTION()


#####################################################################
#
# Execute the unit tests
#
#####################################################################

# Assume that all unit tests will pass by default
GLOBAL_SET(UNITTEST_OVERALL_PASS TRUE)
GLOBAL_SET(UNITTEST_OVERALL_NUMPASSED 0)
GLOBAL_SET(UNITTEST_OVERALL_NUMRUN 0)

# Set common/base options
SET(PROJECT_NAME "DummyProject")
SET(PROJECT_SOURCE_DIR "/home/me/DummyProject")

UNITTEST_TRIBITS_PARSE_EXTRAREPO_PACKSTAT()

UNITTEST_TRIBITS_PROCESS_EXTRAREPOS_LISTS()
UNITTEST_TRIBITS_PROCESS_EXTRAREPOS_LISTS_OLD_REPOTYPE()

UNITTEST_TRIBITS_GET_AND_PROCESS_EXTRA_REPOSITORIES_LISTS()

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