From e1458ae4ab97a4ac668fd9153c6624e9e0e526b5 Mon Sep 17 00:00:00 2001 From: David Cole Date: Tue, 20 Oct 2009 14:31:10 -0400 Subject: [PATCH] Add test of all available CPack generators. Add this test with the goal of increasing coverage of the cpack source code, even/especially when the underlying packager tool is not installed. The test does not fail if there is a cpack problem with a certain generator. I expect some generators will fail on every machine running a CMake dashboard. --- CMakeLists.txt | 3 +- Tests/CMakeLists.txt | 34 +++++++++++++ Tests/CPackTestAllGenerators/CMakeLists.txt | 5 ++ Tests/CPackTestAllGenerators/RunCPack.cmake | 55 +++++++++++++++++++++ 4 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 Tests/CPackTestAllGenerators/CMakeLists.txt create mode 100644 Tests/CPackTestAllGenerators/RunCPack.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index e8c213b4b..7223c90bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -141,12 +141,13 @@ MACRO(CMAKE_SETUP_TESTING) # cmake. SET(CMAKE_CTEST_COMMAND "${EXECUTABLE_OUTPUT_PATH}/ctest") SET(CMAKE_CMAKE_COMMAND "${EXECUTABLE_OUTPUT_PATH}/cmake") + SET(CMAKE_CPACK_COMMAND "${EXECUTABLE_OUTPUT_PATH}/cpack") ENDIF(BUILD_TESTING) # configure some files for testing CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/Templates/CTestScript.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/CTestScript.cmake" - @ONLY) + @ONLY) CONFIGURE_FILE(${CMake_SOURCE_DIR}/Tests/.NoDartCoverage ${CMake_BINARY_DIR}/Tests/.NoDartCoverage) CONFIGURE_FILE(${CMake_SOURCE_DIR}/Tests/.NoDartCoverage diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 6ab5cd170..638932506 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -456,6 +456,40 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=CVS -P ${CMake_SOURCE_DIR}/Utilities/Rel LIST(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/CPackComponents") ENDIF(CTEST_RUN_CPackComponents) + # By default, turn this test off (because it takes a long time...) + # + if(NOT DEFINED CTEST_RUN_CPackTestAllGenerators) + set(CTEST_RUN_CPackTestAllGenerators OFF) + + # ...but: if it appears to be a coverage dashboard, or long tests are + # on, then set it to the generic CTEST_TEST_CPACK setting. + # + if(CMAKE_CXX_FLAGS MATCHES "-ftest-coverage" OR + NOT "$ENV{COVFILE}" STREQUAL "" OR + CMAKE_RUN_LONG_TESTS) + set(CTEST_RUN_CPackTestAllGenerators ${CTEST_TEST_CPACK}) + endif(CMAKE_CXX_FLAGS MATCHES "-ftest-coverage" OR + NOT "$ENV{COVFILE}" STREQUAL "" OR + CMAKE_RUN_LONG_TESTS) + endif(NOT DEFINED CTEST_RUN_CPackTestAllGenerators) + + IF(CTEST_RUN_CPackTestAllGenerators) + ADD_TEST(CPackTestAllGenerators ${CMAKE_CTEST_COMMAND} + --build-and-test + "${CMake_SOURCE_DIR}/Tests/CPackTestAllGenerators" + "${CMake_BINARY_DIR}/Tests/CPackTestAllGenerators" + --build-generator ${CMAKE_TEST_GENERATOR} + --build-project CPackTestAllGenerators + --build-makeprogram ${CMAKE_TEST_MAKEPROGRAM} + --test-command + ${CMAKE_CMAKE_COMMAND} + -D dir=${CMake_BINARY_DIR}/Tests/CPackTestAllGenerators + -D cpack=${CMAKE_CPACK_COMMAND} + -P ${CMake_SOURCE_DIR}/Tests/CPackTestAllGenerators/RunCPack.cmake + ) + LIST(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/CPackTestAllGenerators") + ENDIF(CTEST_RUN_CPackTestAllGenerators) + IF(CTEST_package_X11_TEST) SET(X11_build_target_arg --build-target package) ELSE(CTEST_package_X11_TEST) diff --git a/Tests/CPackTestAllGenerators/CMakeLists.txt b/Tests/CPackTestAllGenerators/CMakeLists.txt new file mode 100644 index 000000000..5eeb7e90b --- /dev/null +++ b/Tests/CPackTestAllGenerators/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 2.8) +project(CPackTestAllGenerators) +add_subdirectory(../CTestTest/SmallAndFast SmallAndFast) +install(FILES RunCPack.cmake DESTINATION .) +include(CPack) diff --git a/Tests/CPackTestAllGenerators/RunCPack.cmake b/Tests/CPackTestAllGenerators/RunCPack.cmake new file mode 100644 index 000000000..eb33ff408 --- /dev/null +++ b/Tests/CPackTestAllGenerators/RunCPack.cmake @@ -0,0 +1,55 @@ +if(NOT DEFINED cpack) + message(FATAL_ERROR "cpack not defined") +endif() + +if(NOT DEFINED dir) + message(FATAL_ERROR "dir not defined") +endif() + +# Analyze 'cpack --help' output for list of available generators: +# +execute_process(COMMAND ${cpack} --help + RESULT_VARIABLE result + OUTPUT_VARIABLE stdout + ERROR_VARIABLE stderr + WORKING_DIRECTORY ${dir}) + +string(REPLACE ";" "\\;" stdout ${stdout}) +string(REPLACE "\n" "E;" stdout ${stdout}) + +set(collecting 0) +set(generators) +foreach(eline ${stdout}) + string(REGEX REPLACE "^(.*)E$" "\\1" line ${eline}) + if(collecting AND NOT line STREQUAL "") + string(REGEX REPLACE "^ ([^ ]+) += (.*)$" "\\1" gen "${line}") + string(REGEX REPLACE "^ ([^ ]+) += (.*)$" "\\2" doc "${line}") + set(generators ${generators} ${gen}) + endif() + if(line STREQUAL "Generators") + set(collecting 1) + endif() +endforeach() + +# Call cpack with -G on each available generator. We do not care if this +# succeeds or not. We expect it *not* to succeed if the underlying packaging +# tools are not installed on the system... This test is here simply to add +# coverage for the various cpack generators, even/especially to test ones +# where the tools are not installed. +# +message(STATUS "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)") + +message(STATUS "CPack generators='${generators}'") + +foreach(g ${generators}) + message(STATUS "Calling cpack -G ${g}...") + execute_process(COMMAND ${cpack} -G ${g} + RESULT_VARIABLE result + OUTPUT_VARIABLE stdout + ERROR_VARIABLE stderr + WORKING_DIRECTORY ${dir}) + message(STATUS "result='${result}'") + message(STATUS "stdout='${stdout}'") + message(STATUS "stderr='${stderr}'") + message(STATUS "") +endforeach()