Skip to content

Commit a55a41c

Browse files
jcfrNicole Aucoin
and
Nicole Aucoin
committed
ENH: Add infrastructure to test GenerateCLP install rules. See Slicer#44
* 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]>
1 parent 429e9a8 commit a55a41c

File tree

4 files changed

+106
-12
lines changed

4 files changed

+106
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
# --------------------------------------------------------------------------
3+
# Sanity checks
4+
5+
foreach(varname TEST_CMAKE_DIR TEST_BINARY_DIR TEST_INSTALL_DIR)
6+
if(NOT DEFINED ${varname})
7+
message(FATAL_ERROR "Variable ${varname} is not DEFINED")
8+
endif()
9+
endforeach()
10+
11+
include(${TEST_CMAKE_DIR}/GenerateCLPTestMacros.cmake)
12+
13+
# --------------------------------------------------------------------------
14+
# Delete install directory if it exists
15+
execute_process(
16+
COMMAND ${CMAKE_COMMAND} -E remove_directory ${TEST_INSTALL_DIR}
17+
)
18+
19+
# --------------------------------------------------------------------------
20+
# Create install directory
21+
execute_process(
22+
COMMAND ${CMAKE_COMMAND} -E make_directory ${TEST_INSTALL_DIR}
23+
)
24+
25+
# --------------------------------------------------------------------------
26+
# Debug flags - Set to True to display the command as string
27+
set(PRINT_COMMAND 0)
28+
29+
# --------------------------------------------------------------------------
30+
# Install
31+
set(install_target install)
32+
if(WIN32)
33+
set(install_target INSTALL)
34+
endif()
35+
set(command ${CMAKE_COMMAND} --build ${TEST_BINARY_DIR} --config Release --target ${install_target})
36+
execute_process(
37+
COMMAND ${command}
38+
WORKING_DIRECTORY ${TEST_BINARY_DIR}
39+
OUTPUT_VARIABLE ov
40+
RESULT_VARIABLE rv
41+
)
42+
43+
print_command_as_string("${command}")
44+
45+
if(rv)
46+
message(FATAL_ERROR "Failed to install Test:\n${ov}")
47+
endif()

GenerateCLP/Testing/CMake/GenerateCLPTest-Configure.cmake

+11-1
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,24 @@ execute_process(
2323
# Debug flags - Set to True to display the command as string
2424
set(PRINT_COMMAND 0)
2525

26+
# --------------------------------------------------------------------------
27+
if(TEST_TREETYPE STREQUAL "BuildTree")
28+
set(GenerateCLP_DIR ${GenerateCLP_BINARY_DIR})
29+
endif()
30+
2631
# --------------------------------------------------------------------------
2732
# Configure
2833
set(command ${CMAKE_COMMAND}
2934
-DCMAKE_BUILD_TYPE:STRING=${generateclp_build_type}
30-
-DGenerateCLP_DIR:PATH=${GenerateCLP_BINARY_DIR}
35+
-DGenerateCLP_DIR:PATH=${GenerateCLP_DIR}
3136
-DGenerateCLP_USE_JSONCPP:BOOL=${GenerateCLP_USE_JSONCPP}
3237
-DJsonCpp_CMAKE_MODULE_PATH:PATH=${JsonCpp_CMAKE_MODULE_PATH}
3338
-G ${generateclp_cmake_generator} ${TEST_SOURCE_DIR})
39+
if(GenerateCLP_USE_JSONCPP)
40+
list(APPEND command
41+
-DJsonCpp_DIR:PATH=${JsonCpp_DIR}
42+
)
43+
endif()
3444
execute_process(
3545
COMMAND ${command}
3646
WORKING_DIRECTORY ${TEST_BINARY_DIR}

GenerateCLP/Testing/CMake/GenerateCLPTestPrerequisites.cmake.in

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ if(NOT EXISTS ${GenerateCLP_BINARY_DIR})
2121
"GenerateCLP_BINARY_DIR [${GenerateCLP_BINARY_DIR}]")
2222
endif()
2323

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

2530
# --------------------------------------------------------------------------
2631
# Attempt to guess GenerateCLP build type

GenerateCLP/Testing/CMakeLists.txt

+43-11
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,55 @@ configure_file(
88
@ONLY
99
)
1010

11+
#
12+
# Add test installing GenerateCLP
13+
#
14+
add_test(NAME GenerateCLP-Install
15+
COMMAND ${CMAKE_COMMAND}
16+
-DTEST_CMAKE_DIR:PATH=${GenerateCLP_SOURCE_DIR}/Testing/CMake
17+
-DTEST_BINARY_DIR:PATH=${GenerateCLP_BINARY_DIR}
18+
-DTEST_INSTALL_DIR:PATH=${CMAKE_INSTALL_PREFIX}
19+
-P ${CMAKE_CURRENT_SOURCE_DIR}/CMake/GenerateCLP-Install.cmake)
20+
set_property(TEST GenerateCLP-Install PROPERTY LABELS ${PROJECT_NAME})
21+
1122
#
1223
# Helper macro
1324
#
1425
set(_previous_test "NODEPENDS")
1526
macro(generateclp_add_test cliname stepname)
16-
set(testname GenerateCLPTest-${cliname}-${stepname})
17-
add_test(NAME ${testname}
18-
COMMAND ${CMAKE_COMMAND}
19-
-DTEST_SOURCE_DIR:PATH=${CMAKE_CURRENT_SOURCE_DIR}/${cliname}
20-
-DTEST_BINARY_DIR:PATH=${CMAKE_CURRENT_BINARY_DIR}/${cliname}
21-
-DTEST_CONFIGURATION:STRING=$<CONFIGURATION>
22-
-P ${CMAKE_CURRENT_SOURCE_DIR}/CMake/GenerateCLPTest-${stepname}.cmake)
23-
if(NOT ${_previous_test} STREQUAL "NODEPENDS")
24-
set_tests_properties(${testname} PROPERTIES DEPENDS ${_previous_test})
27+
28+
macro(_generateclp_add_tree_test treetype)
29+
set(testname GenerateCLPTest-${treetype}-${cliname}-${stepname})
30+
set(_test_args
31+
-DTEST_TREETYPE:STRING=${treetype}
32+
-DTEST_SOURCE_DIR:PATH=${CMAKE_CURRENT_SOURCE_DIR}/${cliname}
33+
-DTEST_BINARY_DIR:PATH=${CMAKE_CURRENT_BINARY_DIR}/${treetype}-${cliname}
34+
-DTEST_CONFIGURATION:STRING=$<CONFIGURATION>
35+
)
36+
if("${treetype}" STREQUAL "InstallTree" AND "${stepname}" STREQUAL "Configure")
37+
list(APPEND _test_args
38+
-DGenerateCLP_DIR:PATH=${CMAKE_INSTALL_PREFIX}/lib/GenerateCLP/
39+
)
40+
endif()
41+
42+
add_test(NAME ${testname}
43+
COMMAND ${CMAKE_COMMAND} ${_test_args}
44+
-P ${CMAKE_CURRENT_SOURCE_DIR}/CMake/GenerateCLPTest-${stepname}.cmake)
45+
if(NOT ${_previous_test} STREQUAL "NODEPENDS")
46+
set_tests_properties(${testname} PROPERTIES DEPENDS ${_previous_test})
47+
endif()
48+
set(_previous_test ${testname})
49+
set_property(TEST ${testname} PROPERTY LABELS ${PROJECT_NAME})
50+
endmacro()
51+
52+
# Build and install cases
53+
_generateclp_add_tree_test(BuildTree)
54+
_generateclp_add_tree_test(InstallTree)
55+
if(stepname STREQUAL "Configure")
56+
# Install case required GenerareCLP install tree
57+
set_tests_properties(${testname} PROPERTIES DEPENDS GenerateCLP-Install)
2558
endif()
26-
set(_previous_test ${testname})
27-
set_property(TEST ${testname} PROPERTY LABELS ${PROJECT_NAME})
59+
2860
endmacro()
2961

3062
#

0 commit comments

Comments
 (0)