Skip to content

Commit

Permalink
Set up skeleton for unit tests and more (SQUASH ME) (TriBITS TriBITSP…
Browse files Browse the repository at this point in the history
…ub#73)

* Set up first first unit tests for directly calling
  TRIBITS_PROJECT_DEFINE_EXTRA_REPOSITORIES().

* Allowed the "REPOTYPE" field to be empty and therefore not have a VC type.

* Added variable ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_PREPOSTS and tested
  for POST only.
  • Loading branch information
Roscoe A. Bartlett committed Jun 1, 2015
1 parent 3938115 commit 07a5b47
Show file tree
Hide file tree
Showing 3 changed files with 227 additions and 13 deletions.
13 changes: 13 additions & 0 deletions test/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ TRIBITS_ADD_ADVANCED_TEST( TribitsProcessPackagesAndDirsLists_UnitTests
)


TRIBITS_ADD_ADVANCED_TEST( TribitsProcessExtraRepositoriesList_UnitTests
OVERALL_WORKING_DIRECTORY TEST_NAME
TEST_0 CMND ${CMAKE_COMMAND}
ARGS
-DPROJECT_NAME=${PROJECT_NAME}
-D${PROJECT_NAME}_TRIBITS_DIR=${${PROJECT_NAME}_TRIBITS_DIR}
-P "${CMAKE_CURRENT_SOURCE_DIR}/TribitsProcessExtraRepositoriesList_UnitTests.cmake"
PASS_REGULAR_EXPRESSION_ALL
"Final UnitTests Result: num_run = 27"
"Final UnitTests Result: PASSED"
)


TRIBITS_ADD_ADVANCED_TEST( TribitsAdjustPackageEnables_UnitTests
OVERALL_WORKING_DIRECTORY TEST_NAME
TEST_0 CMND ${CMAKE_COMMAND}
Expand Down
191 changes: 191 additions & 0 deletions test/core/TribitsProcessExtraRepositoriesList_UnitTests.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
# @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_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 "[email protected]:repo0" "" Continuous
repo1_name "some/sub/dir" SVN "[email protected]: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_REPOTYPES
"GIT;SVN")
UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_REPOURLS
"[email protected]:repo0;[email protected]:repo1")
UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_PACKSTATS
"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 "[email protected]:repo0" "" Continuous
repo1_name "some/sub/dir" SVN "[email protected]:repo1" NOPACKAGES Nightly
)

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_REPOTYPES
"GIT")
UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_REPOURLS
"[email protected]:repo0")
UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_PACKSTATS
"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")


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_REPOTYPES
"")
UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_REPOURLS
"")
UNITTEST_COMPARE_CONST( ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_PACKSTATS
"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

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_PROCESS_EXTRAREPOS_LISTS()

# Pass in the number of expected tests that must pass!
UNITTEST_FINAL_RESULT(27)
36 changes: 23 additions & 13 deletions tribits/core/package_arch/TribitsProcessExtraRepositoriesList.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,12 @@ INCLUDE(TribitsSortListAccordingToMasterList)
# package name!
#
# 2. **REPO_TYPE** (``<repoi_type>``): The version control (VC) type of the
# repo. Value choices include ``GIT`` and ``SVN`` (i.e. Subversion).
# *WARNING:* Only VC repos of type ``GIT`` can fully participate in the
# TriBITS development tool workflows. The other VC types are supported for
# basic cloning and updating using `TRIBITS_CTEST_DRIVER()`_ script.
# repo. Value choices include ``GIT`` and ``SVN`` (i.e. Subversion). A
# valid choice is also empty "". In that case, ``<repoi_url>`` must be
# empty as well. *WARNING:* Only VC repos of type ``GIT`` can fully
# participate in the TriBITS development tool workflows. The other VC
# types are only supported for basic cloning and updating using
# `TRIBITS_CTEST_DRIVER()`_ script.
#
# 3. **REPO_URL** (``<repoi_url>``): The URL of the VC repo. This info is
# used to initially obtain the repo source code using the VC tool listed in
Expand All @@ -102,16 +104,20 @@ INCLUDE(TribitsSortListAccordingToMasterList)
# This command is used to put together one or more VC and/or TriBITS
# repositories to construct a composite `TriBITS Project`_. The option
# `<Project>_EXTRAREPOS_FILE`_ is used to point to files that call this macro.
#
# Repositories with ``<repoi_packstat>=NOPACKAGES`` are **not** TriBITS
# Repositories and are technically not considered at all during the basic
# configuration of the a TriBITS project. They are only listed in this file
# so that they can be used in the version control logic for tools that perform
# version control with the repositories (such as cloning, updating, looking
# for changed files, etc.). For example, a non-TriBITS repo can be used to
# grab a set of directories and files that fill in the definition of a package
# in an upstream repository (see `How to insert a package into an upstream
# repo`_). Also, non-TriBITS repos can be used to provide extra test data for
# a given package or a set of packages so that extra tests can be run.
# version control with the repositories (such as getting git versions,
# cloning, updating, looking for changed files, etc.). For example, a
# non-TriBITS repo can be used to grab a set of directories and files that
# fill in the definition of a package in an upstream repository (see `How to
# insert a package into an upstream repo`_). Also, non-TriBITS repos can be
# used to provide extra test data for a given package or a set of packages so
# that extra tests can be run.
#
# Repositories with ``<repoi_repotype>=''`` are not VC repos.
#
# It is also allowed for a repository to have ``<repoi_url>=""`` and
# ``<repoi_packstat>=""`` which means that the given repository directory
Expand Down Expand Up @@ -186,6 +192,7 @@ ENDFUNCTION()
# ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_REPOTYPES
# ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_REPOURLS
# ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_PACKSTATS
# ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_PREPOSTS
# ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_CATEGORIES
#
# The macro responds to ${PROJECT_NAME}_ENABLE_KNOWN_EXTERNAL_REPOS_TYPE
Expand Down Expand Up @@ -218,6 +225,7 @@ MACRO(TRIBITS_PROCESS_EXTRAREPOS_LISTS)
SET(${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_REPOTYPES)
SET(${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_REPOURLS)
SET(${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_PACKSTATS)
SET(${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_PREPOSTS)
SET(${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_CATEGORIES)
SET(${PROJECT_NAME}_PRE_REPOSITORIES_DEFAULT)
SET(${PROJECT_NAME}_EXTRA_REPOSITORIES_DEFAULT)
Expand Down Expand Up @@ -268,9 +276,11 @@ MACRO(TRIBITS_PROCESS_EXTRAREPOS_LISTS)
OR EXTRAREPO_REPOTYPE STREQUAL SVN
)
# Okay
ELSEIF(EXTRAREPO_REPOTYPE STREQUAL HG)
ELSEIF (EXTRAREPO_REPOTYPE STREQUAL HG)
# not quite okay
MESSAGE(WARNING "Warning: the repo ${EXTRAREPO_NAME} is a Mercurial repo: these are tolerated, but not fully supported.")
ELSEIF (EXTRAREPO_REPOTYPE STREQUAL "")
# We are okay with no VC type
ELSE()
MESSAGE(FATAL_ERROR "Error, the repo type of '${EXTRAREPO_REPOTYPE}' for"
" extra repo ${EXTRAREPO_NAME} is *not* valid. Valid choices are 'GIT', 'HG' and 'SVN'!")
Expand All @@ -291,7 +301,7 @@ MACRO(TRIBITS_PROCESS_EXTRAREPOS_LISTS)
PRINT_VAR(EXTRAREPO_REPOURL)
ENDIF()

# PACKSTAT
# PACKSTAT (PACKSTAT and PREPOST)
MATH(EXPR EXTRAREPO_PACKSTAT_IDX
"${EXTRAREPO_IDX}*${ERP_NUM_FIELDS_PER_REPO}+${ERP_REPO_PACKSTAT_OFFSET}")
LIST(GET ${PROJECT_NAME}_EXTRAREPOS_DIR_REPOTYPE_REPOURL_PACKSTAT_CATEGORY
Expand Down Expand Up @@ -345,7 +355,6 @@ MACRO(TRIBITS_PROCESS_EXTRAREPOS_LISTS)
PRINT_VAR(ADD_EXTRAREPO)
ENDIF()


# B.3) Add the extrarepo to the list if the classification matches

IF (ADD_EXTRAREPO)
Expand All @@ -354,6 +363,7 @@ MACRO(TRIBITS_PROCESS_EXTRAREPOS_LISTS)
LIST(APPEND ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_REPOTYPES ${EXTRAREPO_REPOTYPE})
LIST(APPEND ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_REPOURLS ${EXTRAREPO_REPOURL})
LIST(APPEND ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_PACKSTATS ${EXTRAREPO_PACKSTAT})
LIST(APPEND ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_PREPOSTS ${EXTRAREPO_PREPOST})
LIST(APPEND ${PROJECT_NAME}_ALL_EXTRA_REPOSITORIES_CATEGORIES
${EXTRAREPO_CLASSIFICATION})
IF (EXTRAREPO_PREPOST STREQUAL "PRE")
Expand Down

0 comments on commit 07a5b47

Please sign in to comment.