Tests: Add subtest support to RunCMake/CPack infrastructure

This commit is contained in:
Domen Vrankar 2016-09-13 23:32:48 +02:00 committed by Brad King
parent 5c87b92b1b
commit 4682b42bdb
3 changed files with 40 additions and 12 deletions

View File

@ -1,11 +1,11 @@
cmake_minimum_required(VERSION 3.1 FATAL_ERROR) cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
project(${RunCMake_TEST} CXX) project(${RunCMake_TEST} CXX)
include(${RunCMake_TEST}.cmake) include(${RunCMake_TEST_FILE_PREFIX}.cmake)
# include test generator specifics # include test generator specifics
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${GENERATOR_TYPE}/${RunCMake_TEST}-specifics.cmake") if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${GENERATOR_TYPE}/${RunCMake_TEST_FILE_PREFIX}-specifics.cmake")
include("${GENERATOR_TYPE}/${RunCMake_TEST}-specifics.cmake") include("${GENERATOR_TYPE}/${RunCMake_TEST_FILE_PREFIX}-specifics.cmake")
endif() endif()
set(CPACK_GENERATOR "${GENERATOR_TYPE}") set(CPACK_GENERATOR "${GENERATOR_TYPE}")

View File

@ -1,9 +1,15 @@
cmake_policy(SET CMP0057 NEW) cmake_policy(SET CMP0057 NEW)
function(run_cpack_test TEST_NAME types build) function(run_cpack_test_common_ TEST_NAME types build SUBTEST_SUFFIX)
if(TEST_TYPE IN_LIST types) if(TEST_TYPE IN_LIST types)
set(RunCMake_TEST_NO_CLEAN TRUE) set(RunCMake_TEST_NO_CLEAN TRUE)
set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/${TEST_NAME}-build") set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/${TEST_NAME}-build")
set(full_test_name_ "${TEST_NAME}")
if(SUBTEST_SUFFIX)
set(RunCMake_TEST_BINARY_DIR "${RunCMake_TEST_BINARY_DIR}-${SUBTEST_SUFFIX}-subtest")
set(full_test_name_ "${full_test_name_}-${SUBTEST_SUFFIX}-subtest")
endif()
# TODO this should be executed only once per ctest run (not per generator) # TODO this should be executed only once per ctest run (not per generator)
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
@ -24,12 +30,14 @@ function(run_cpack_test TEST_NAME types build)
endif() endif()
# execute cmake # execute cmake
set(RunCMake_TEST_OPTIONS "-DGENERATOR_TYPE=${TEST_TYPE}") set(RunCMake_TEST_OPTIONS "-DGENERATOR_TYPE=${TEST_TYPE}"
run_cmake(${TEST_NAME}) "-DRunCMake_TEST_FILE_PREFIX=${TEST_NAME}"
"-DRunCMake_SUBTEST_SUFFIX=${SUBTEST_SUFFIX}")
run_cmake(${full_test_name_})
# execute optional build step # execute optional build step
if(build) if(build)
run_cmake_command(${TEST_NAME}-Build "${CMAKE_COMMAND}" --build "${RunCMake_TEST_BINARY_DIR}") run_cmake_command(${full_test_name_}-Build "${CMAKE_COMMAND}" --build "${RunCMake_TEST_BINARY_DIR}")
endif() endif()
# execute cpack # execute cpack
@ -40,11 +48,21 @@ function(run_cpack_test TEST_NAME types build)
ERROR_FILE "${RunCMake_TEST_BINARY_DIR}/test_error.txt" ERROR_FILE "${RunCMake_TEST_BINARY_DIR}/test_error.txt"
) )
foreach(o out err)
if(SUBTEST_SUFFIX AND EXISTS ${RunCMake_SOURCE_DIR}/${TEST_TYPE}/${TEST_NAME}-${SUBTEST_SUFFIX}-std${o}.txt)
set(RunCMake-std${o}-file "${TEST_TYPE}/${TEST_NAME}-${SUBTEST_SUFFIX}-std${o}.txt")
elseif(EXISTS ${RunCMake_SOURCE_DIR}/${TEST_TYPE}/${TEST_NAME}-std${o}.txt)
set(RunCMake-std${o}-file "${TEST_TYPE}/${TEST_NAME}-std${o}.txt")
endif()
endforeach()
# verify result # verify result
run_cmake_command( run_cmake_command(
${TEST_TYPE}/${TEST_NAME} ${TEST_TYPE}/${full_test_name_}
"${CMAKE_COMMAND}" "${CMAKE_COMMAND}"
-DRunCMake_TEST=${TEST_NAME} -DRunCMake_TEST=${full_test_name_}
-DRunCMake_TEST_FILE_PREFIX=${TEST_NAME}
-DRunCMake_SUBTEST_SUFFIX=${SUBTEST_SUFFIX}
-DGENERATOR_TYPE=${TEST_TYPE} -DGENERATOR_TYPE=${TEST_TYPE}
"-Dsrc_dir=${RunCMake_SOURCE_DIR}" "-Dsrc_dir=${RunCMake_SOURCE_DIR}"
"-Dbin_dir=${RunCMake_TEST_BINARY_DIR}" "-Dbin_dir=${RunCMake_TEST_BINARY_DIR}"
@ -53,3 +71,13 @@ function(run_cpack_test TEST_NAME types build)
) )
endif() endif()
endfunction() endfunction()
function(run_cpack_test TEST_NAME types build)
run_cpack_test_common_("${TEST_NAME}" "${types}" "${build}" "")
endfunction()
function(run_cpack_test_subtests TEST_NAME SUBTEST_SUFFIXES types build)
foreach(suffix_ IN LISTS SUBTEST_SUFFIXES)
run_cpack_test_common_("${TEST_NAME}" "${types}" "${build}" "${suffix_}")
endforeach()
endfunction()

View File

@ -11,7 +11,7 @@ set(output_error_message
"\nCPack output: '${output}'\nCPack error: '${error}';\nconfig file: '${config_file_content}'") "\nCPack output: '${output}'\nCPack error: '${error}';\nconfig file: '${config_file_content}'")
# check that expected generated files exist and contain expected content # check that expected generated files exist and contain expected content
include("${src_dir}/${GENERATOR_TYPE}/${RunCMake_TEST}-ExpectedFiles.cmake") include("${src_dir}/${GENERATOR_TYPE}/${RunCMake_TEST_FILE_PREFIX}-ExpectedFiles.cmake")
if(NOT EXPECTED_FILES_COUNT EQUAL 0) if(NOT EXPECTED_FILES_COUNT EQUAL 0)
foreach(file_no_ RANGE 1 ${EXPECTED_FILES_COUNT}) foreach(file_no_ RANGE 1 ${EXPECTED_FILES_COUNT})
@ -82,8 +82,8 @@ else()
endif() endif()
# handle additional result verifications # handle additional result verifications
if(EXISTS "${src_dir}/${GENERATOR_TYPE}/${RunCMake_TEST}-VerifyResult.cmake") if(EXISTS "${src_dir}/${GENERATOR_TYPE}/${RunCMake_TEST_FILE_PREFIX}-VerifyResult.cmake")
include("${src_dir}/${GENERATOR_TYPE}/${RunCMake_TEST}-VerifyResult.cmake") include("${src_dir}/${GENERATOR_TYPE}/${RunCMake_TEST_FILE_PREFIX}-VerifyResult.cmake")
else() else()
# by default only print out output and error so that they can be compared by # by default only print out output and error so that they can be compared by
# regex # regex