Skip to content

Commit

Permalink
ENH: Add infrastructure to test GenerateCLP install rules. See #44
Browse files Browse the repository at this point in the history
* Introduced "GenerateCLP-Install.cmake" script that is deleting
the directory associated with CMAKE_INSTALL_PREFIX, and re-installing
the files building the "install" target.

* Introduced variable TEST_TREETYPE set to either "BuildTree"
or "InstallTree". This variable allows to conditionally update the
testing context in Configure, Build or Test steps associated with
each examples.

* For the "BuildTree" case, GenerateCLP_DIR is hardcoded in
GenerateCLPTestPrerequisites whereas it is passed as test argument
for the "InstallTree" case.

Co-authored-by: Nicole Aucoin <[email protected]>
  • Loading branch information
jcfr and Nicole Aucoin committed Apr 12, 2016
1 parent cf430eb commit fccd779
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 12 deletions.
47 changes: 47 additions & 0 deletions GenerateCLP/Testing/CMake/GenerateCLP-Install.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

# --------------------------------------------------------------------------
# Sanity checks

foreach(varname TEST_CMAKE_DIR TEST_BINARY_DIR TEST_INSTALL_DIR)
if(NOT DEFINED ${varname})
message(FATAL_ERROR "Variable ${varname} is not DEFINED")
endif()
endforeach()

include(${TEST_CMAKE_DIR}/GenerateCLPTestMacros.cmake)

# --------------------------------------------------------------------------
# Delete install directory if it exists
execute_process(
COMMAND ${CMAKE_COMMAND} -E remove_directory ${TEST_INSTALL_DIR}
)

# --------------------------------------------------------------------------
# Create install directory
execute_process(
COMMAND ${CMAKE_COMMAND} -E make_directory ${TEST_INSTALL_DIR}
)

# --------------------------------------------------------------------------
# Debug flags - Set to True to display the command as string
set(PRINT_COMMAND 0)

# --------------------------------------------------------------------------
# Install
set(install_target install)
if(WIN32)
set(install_target INSTALL)
endif()
set(command ${CMAKE_COMMAND} --build ${TEST_BINARY_DIR} --config Release --target ${install_target})
execute_process(
COMMAND ${command}
WORKING_DIRECTORY ${TEST_BINARY_DIR}
OUTPUT_VARIABLE ov
RESULT_VARIABLE rv
)

print_command_as_string("${command}")

if(rv)
message(FATAL_ERROR "Failed to install Test:\n${ov}")
endif()
7 changes: 6 additions & 1 deletion GenerateCLP/Testing/CMake/GenerateCLPTest-Configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ execute_process(
# Debug flags - Set to True to display the command as string
set(PRINT_COMMAND 0)

# --------------------------------------------------------------------------
if(TEST_TREETYPE STREQUAL "BuildTree")
set(GenerateCLP_DIR ${GenerateCLP_BINARY_DIR})
endif()

# --------------------------------------------------------------------------
# Configure
set(command ${CMAKE_COMMAND}
-DCMAKE_BUILD_TYPE:STRING=${generateclp_build_type}
-DGenerateCLP_DIR:PATH=${GenerateCLP_BINARY_DIR}
-DGenerateCLP_DIR:PATH=${GenerateCLP_DIR}
-DJsonCpp_CMAKE_MODULE_PATH:PATH=${JsonCpp_CMAKE_MODULE_PATH}
-G ${generateclp_cmake_generator} ${TEST_SOURCE_DIR})
if(GenerateCLP_USE_JSONCPP)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ if(NOT EXISTS ${GenerateCLP_BINARY_DIR})
"GenerateCLP_BINARY_DIR [${GenerateCLP_BINARY_DIR}]")
endif()

if(NOT ("${TEST_TREETYPE}" STREQUAL "BuildTree" OR "${TEST_TREETYPE}" STREQUAL "InstallTree"))
message(FATAL_ERROR "Variable TEST_TREETYPE is expected to be set to either 'BuildTree' or 'InstallTree'.
Current value is '${TEST_TREETYPE}'")
endif()


# --------------------------------------------------------------------------
# Attempt to guess GenerateCLP build type
Expand Down
54 changes: 43 additions & 11 deletions GenerateCLP/Testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,55 @@ configure_file(
@ONLY
)

#
# Add test installing GenerateCLP
#
add_test(NAME GenerateCLP-Install
COMMAND ${CMAKE_COMMAND}
-DTEST_CMAKE_DIR:PATH=${GenerateCLP_SOURCE_DIR}/Testing/CMake
-DTEST_BINARY_DIR:PATH=${GenerateCLP_BINARY_DIR}
-DTEST_INSTALL_DIR:PATH=${CMAKE_INSTALL_PREFIX}
-P ${CMAKE_CURRENT_SOURCE_DIR}/CMake/GenerateCLP-Install.cmake)
set_property(TEST GenerateCLP-Install PROPERTY LABELS ${PROJECT_NAME})

#
# Helper macro
#
set(_previous_test "NODEPENDS")
macro(generateclp_add_test cliname stepname)
set(testname GenerateCLPTest-${cliname}-${stepname})
add_test(NAME ${testname}
COMMAND ${CMAKE_COMMAND}
-DTEST_SOURCE_DIR:PATH=${CMAKE_CURRENT_SOURCE_DIR}/${cliname}
-DTEST_BINARY_DIR:PATH=${CMAKE_CURRENT_BINARY_DIR}/${cliname}
-DTEST_CONFIGURATION:STRING=$<CONFIGURATION>
-P ${CMAKE_CURRENT_SOURCE_DIR}/CMake/GenerateCLPTest-${stepname}.cmake)
if(NOT ${_previous_test} STREQUAL "NODEPENDS")
set_tests_properties(${testname} PROPERTIES DEPENDS ${_previous_test})

macro(_generateclp_add_tree_test treetype)
set(testname GenerateCLPTest-${treetype}-${cliname}-${stepname})
set(_test_args
-DTEST_TREETYPE:STRING=${treetype}
-DTEST_SOURCE_DIR:PATH=${CMAKE_CURRENT_SOURCE_DIR}/${cliname}
-DTEST_BINARY_DIR:PATH=${CMAKE_CURRENT_BINARY_DIR}/${treetype}-${cliname}
-DTEST_CONFIGURATION:STRING=$<CONFIGURATION>
)
if("${treetype}" STREQUAL "InstallTree" AND "${stepname}" STREQUAL "Configure")
list(APPEND _test_args
-DGenerateCLP_DIR:PATH=${CMAKE_INSTALL_PREFIX}/lib/GenerateCLP/
)
endif()

add_test(NAME ${testname}
COMMAND ${CMAKE_COMMAND} ${_test_args}
-P ${CMAKE_CURRENT_SOURCE_DIR}/CMake/GenerateCLPTest-${stepname}.cmake)
if(NOT ${_previous_test} STREQUAL "NODEPENDS")
set_tests_properties(${testname} PROPERTIES DEPENDS ${_previous_test})
endif()
set(_previous_test ${testname})
set_property(TEST ${testname} PROPERTY LABELS ${PROJECT_NAME})
endmacro()

# Build and install cases
_generateclp_add_tree_test(BuildTree)
_generateclp_add_tree_test(InstallTree)
if(stepname STREQUAL "Configure")
# Install case required GenerareCLP install tree
set_tests_properties(${testname} PROPERTIES DEPENDS GenerateCLP-Install)
endif()
set(_previous_test ${testname})
set_property(TEST ${testname} PROPERTY LABELS ${PROJECT_NAME})

endmacro()

#
Expand Down

0 comments on commit fccd779

Please sign in to comment.