cmake/Tests/RunCMake/CPack/VerifyResult.cmake

153 lines
5.7 KiB
CMake
Raw Normal View History

2015-11-17 17:22:37 +01:00
cmake_minimum_required(VERSION ${CMAKE_VERSION} FATAL_ERROR)
2017-07-20 19:35:53 +02:00
function(findExpectedFile FILE_NO RESULT_VAR GLOBING_EXPR_VAR)
2017-04-14 19:02:05 +02:00
if(NOT DEFINED EXPECTED_FILE_${FILE_NO}) # explicit file name regex was not provided - construct one from other data
# set defaults if parameters are not provided
if(NOT DEFINED EXPECTED_FILE_${FILE_NO}_NAME)
string(TOLOWER "${RunCMake_TEST_FILE_PREFIX}" EXPECTED_FILE_${FILE_NO}_NAME)
endif()
if(NOT DEFINED EXPECTED_FILE_${FILE_NO}_VERSION)
set(EXPECTED_FILE_${FILE_NO}_VERSION "0.1.1")
2018-01-26 17:06:56 +01:00
set(EXPECTED_FILE_${FILE_NO}_VERSION "0.1.1" PARENT_SCOPE)
2017-04-14 19:02:05 +02:00
endif()
getPackageNameGlobexpr("${EXPECTED_FILE_${FILE_NO}_NAME}"
"${EXPECTED_FILE_${FILE_NO}_COMPONENT}" "${EXPECTED_FILE_${FILE_NO}_VERSION}"
"${EXPECTED_FILE_${FILE_NO}_REVISION}" "${FILE_NO}" "EXPECTED_FILE_${FILE_NO}")
endif()
file(GLOB found_file_ RELATIVE "${bin_dir}" "${EXPECTED_FILE_${FILE_NO}}")
set(${RESULT_VAR} "${found_file_}" PARENT_SCOPE)
2017-07-20 19:35:53 +02:00
set(${GLOBING_EXPR_VAR} "${EXPECTED_FILE_${FILE_NO}}" PARENT_SCOPE)
2017-04-14 19:02:05 +02:00
endfunction()
2015-11-17 17:22:37 +01:00
include("${config_file}")
include("${src_dir}/${GENERATOR_TYPE}/Helpers.cmake")
file(READ "${bin_dir}/test_output.txt" output)
file(READ "${bin_dir}/test_error.txt" error)
file(READ "${config_file}" config_file_content)
2021-09-14 00:13:48 +02:00
string(REPLACE "\n" "\n cpack-out> " cpack_out "\n${output}")
string(REPLACE "\n" "\n cpack-err> " cpack_err "\n${error}")
string(REPLACE "\n" "\n cpack-res> " cpack_res "\n${PACKAGING_RESULT}")
string(REPLACE "\n" "\n cpack-cfg> " cpack_cfg "\n${config_file_content}")
string(CONCAT output_error_message
"CPack output:${cpack_out}\n"
"CPack error:${cpack_err}\n"
"CPack result:${cpack_res}\n"
"CPack config file:${cpack_cfg}"
)
2015-11-17 17:22:37 +01:00
2017-04-14 19:02:05 +02:00
# generate default expected files data
include("${src_dir}/tests/${RunCMake_TEST_FILE_PREFIX}/ExpectedFiles.cmake")
2015-11-17 17:22:37 +01:00
2017-04-14 19:02:05 +02:00
# check that expected generated files exist and contain expected content
2015-11-17 17:22:37 +01:00
if(NOT EXPECTED_FILES_COUNT EQUAL 0)
foreach(file_no_ RANGE 1 ${EXPECTED_FILES_COUNT})
2017-07-20 19:35:53 +02:00
findExpectedFile("${file_no_}" "FOUND_FILE_${file_no_}"
"EXPECTED_FILE_${file_no_}")
2016-10-30 18:24:19 +01:00
list(APPEND foundFiles_ "${FOUND_FILE_${file_no_}}")
2015-11-17 17:22:37 +01:00
list(LENGTH FOUND_FILE_${file_no_} foundFilesCount_)
if(foundFilesCount_ EQUAL 1)
unset(PACKAGE_CONTENT)
2017-04-14 19:02:05 +02:00
if(DEFINED EXPECTED_FILE_CONTENT_${file_no_})
getPackageContent("${bin_dir}/${FOUND_FILE_${file_no_}}" "PACKAGE_CONTENT")
string(REGEX MATCH "${EXPECTED_FILE_CONTENT_${file_no_}}"
expected_content_list "${PACKAGE_CONTENT}")
else() # use content list
getPackageContentList("${bin_dir}/${FOUND_FILE_${file_no_}}" "PACKAGE_CONTENT")
set(EXPECTED_FILE_CONTENT_${file_no_} "${EXPECTED_FILE_CONTENT_${file_no_}_LIST}")
toExpectedContentList("${file_no_}" "EXPECTED_FILE_CONTENT_${file_no_}")
2018-10-28 12:09:07 +01:00
if(NOT PACKAGE_CONTENT STREQUAL "")
list(SORT PACKAGE_CONTENT)
endif()
if(NOT EXPECTED_FILE_CONTENT_${file_no_} STREQUAL "")
list(SORT EXPECTED_FILE_CONTENT_${file_no_})
endif()
2017-04-14 19:02:05 +02:00
if(PACKAGE_CONTENT STREQUAL EXPECTED_FILE_CONTENT_${file_no_})
set(expected_content_list TRUE)
else()
set(expected_content_list FALSE)
endif()
endif()
2015-11-17 17:22:37 +01:00
if(NOT expected_content_list)
2017-04-14 19:02:05 +02:00
string(REPLACE "\n" "\n actual> " msg_actual "\n${PACKAGE_CONTENT}")
string(REPLACE "\n" "\n expect> " msg_expected "\n${EXPECTED_FILE_CONTENT_${file_no_}}")
2015-11-17 17:22:37 +01:00
message(FATAL_ERROR
2021-09-14 00:13:48 +02:00
"Unexpected file content for file ${file_no_}!\n"
2017-04-14 19:02:05 +02:00
"The content was:${msg_actual}\n"
"which does not match:${msg_expected}\n"
2015-11-17 17:22:37 +01:00
"${output_error_message}")
endif()
2021-09-14 00:13:48 +02:00
elseif(foundFilesCount_ EQUAL 0)
message(FATAL_ERROR
"Found no files for file ${file_no_}!\n"
"Globbing expression:\n '${EXPECTED_FILE_${file_no_}}'\n"
"${output_error_message}")
2015-11-17 17:22:37 +01:00
else()
message(FATAL_ERROR
2021-09-14 00:13:48 +02:00
"Found more than one file for file ${file_no_}!\n"
"Found files count '${foundFilesCount_}'.\n"
"Files:\n '${FOUND_FILE_${file_no_}}'\n"
"Globbing expression:\n '${EXPECTED_FILE_${file_no_}}'\n"
2015-11-17 17:22:37 +01:00
"${output_error_message}")
endif()
endforeach()
# check that there were no extra files generated
foreach(all_files_glob_ IN LISTS ALL_FILES_GLOB)
file(GLOB foundAll_ RELATIVE "${bin_dir}" "${all_files_glob_}")
2018-10-28 12:09:07 +01:00
list(APPEND allFoundFiles_ ${foundAll_})
2015-11-17 17:22:37 +01:00
endforeach()
list(LENGTH foundFiles_ foundFilesCount_)
list(LENGTH allFoundFiles_ allFoundFilesCount_)
if(NOT foundFilesCount_ EQUAL allFoundFilesCount_)
message(FATAL_ERROR
2021-09-14 00:13:48 +02:00
"Found more files than expected!\n"
"Found files:\n '${allFoundFiles_}'\n"
2015-11-17 17:22:37 +01:00
"${output_error_message}")
endif()
# sanity check that we didn't accidentally list wrong files with our regular
# expressions
foreach(expected_ IN LISTS allFoundFiles_)
list(FIND foundFiles_ "${expected_}" found_)
if(found_ EQUAL -1)
message(FATAL_ERROR
2021-09-14 00:13:48 +02:00
"Expected files don't match found files!\n"
"Found files:\n"
" '${allFoundFiles_}'\n"
2015-11-17 17:22:37 +01:00
"${output_error_message}")
endif()
endforeach()
else()
# there should be no generated files present
foreach(missing_file_glob_ IN LISTS ALL_FILES_GLOB)
file(GLOB checkMissingFiles_ RELATIVE "${bin_dir}" "${missing_file_glob_}")
if(checkMissingFiles_)
2021-09-14 00:13:48 +02:00
message(FATAL_ERROR "Unexpected files found:\n '${checkMissingFiles_}'\n"
2015-11-17 17:22:37 +01:00
"${output_error_message}")
endif()
endforeach()
endif()
# handle additional result verifications
2017-04-14 19:02:05 +02:00
if(EXISTS "${src_dir}/tests/${RunCMake_TEST_FILE_PREFIX}/VerifyResult.cmake")
include("${src_dir}/tests/${RunCMake_TEST_FILE_PREFIX}/VerifyResult.cmake")
2015-11-17 17:22:37 +01:00
endif()
2017-04-14 19:02:05 +02:00
message(STATUS "${output}")
message("${error}")