VerifyResult.cmake 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. cmake_minimum_required(VERSION ${CMAKE_VERSION} FATAL_ERROR)
  2. include("${config_file}")
  3. include("${src_dir}/${GENERATOR_TYPE}/Helpers.cmake")
  4. file(READ "${bin_dir}/test_output.txt" output)
  5. file(READ "${bin_dir}/test_error.txt" error)
  6. file(READ "${config_file}" config_file_content)
  7. set(output_error_message
  8. "\nCPack output: '${output}'\nCPack error: '${error}';\nconfig file: '${config_file_content}'")
  9. # check that expected generated files exist and contain expected content
  10. include("${src_dir}/${GENERATOR_TYPE}/${RunCMake_TEST}-ExpectedFiles.cmake")
  11. if(NOT EXPECTED_FILES_COUNT EQUAL 0)
  12. foreach(file_no_ RANGE 1 ${EXPECTED_FILES_COUNT})
  13. file(GLOB FOUND_FILE_${file_no_} RELATIVE "${bin_dir}" "${EXPECTED_FILE_${file_no_}}")
  14. string(APPEND foundFiles_ ";${FOUND_FILE_${file_no_}}")
  15. list(LENGTH FOUND_FILE_${file_no_} foundFilesCount_)
  16. if(foundFilesCount_ EQUAL 1)
  17. unset(PACKAGE_CONTENT)
  18. getPackageContent("${bin_dir}/${FOUND_FILE_${file_no_}}" "PACKAGE_CONTENT")
  19. string(REGEX MATCH "${EXPECTED_FILE_CONTENT_${file_no_}}"
  20. expected_content_list "${PACKAGE_CONTENT}")
  21. if(NOT expected_content_list)
  22. message(FATAL_ERROR
  23. "Unexpected file content for file No. '${file_no_}'!\n"
  24. " Content: '${PACKAGE_CONTENT}'\n\n"
  25. " Expected: '${EXPECTED_FILE_CONTENT_${file_no_}}'"
  26. "${output_error_message}")
  27. endif()
  28. else()
  29. message(FATAL_ERROR
  30. "Found more than one file for file No. '${file_no_}'!"
  31. " Found files count '${foundFilesCount_}'."
  32. " Files: '${FOUND_FILE_${file_no_}}'"
  33. "${output_error_message}")
  34. endif()
  35. endforeach()
  36. # check that there were no extra files generated
  37. foreach(all_files_glob_ IN LISTS ALL_FILES_GLOB)
  38. file(GLOB foundAll_ RELATIVE "${bin_dir}" "${all_files_glob_}")
  39. string(APPEND allFoundFiles_ ";${foundAll_}")
  40. endforeach()
  41. list(LENGTH foundFiles_ foundFilesCount_)
  42. list(LENGTH allFoundFiles_ allFoundFilesCount_)
  43. if(NOT foundFilesCount_ EQUAL allFoundFilesCount_)
  44. message(FATAL_ERROR
  45. "Found more files than expected! Found files: '${allFoundFiles_}'"
  46. "${output_error_message}")
  47. endif()
  48. # sanity check that we didn't accidentally list wrong files with our regular
  49. # expressions
  50. foreach(expected_ IN LISTS allFoundFiles_)
  51. list(FIND foundFiles_ "${expected_}" found_)
  52. if(found_ EQUAL -1)
  53. message(FATAL_ERROR
  54. "Expected files don't match found files! Found files:"
  55. " '${allFoundFiles_}'"
  56. "${output_error_message}")
  57. endif()
  58. endforeach()
  59. else()
  60. # there should be no generated files present
  61. foreach(missing_file_glob_ IN LISTS ALL_FILES_GLOB)
  62. file(GLOB checkMissingFiles_ RELATIVE "${bin_dir}" "${missing_file_glob_}")
  63. if(checkMissingFiles_)
  64. message(FATAL_ERROR "Unexpected files found: '${checkMissingFiles_}'"
  65. "${output_error_message}")
  66. endif()
  67. endforeach()
  68. endif()
  69. # handle additional result verifications
  70. if(EXISTS "${src_dir}/${GENERATOR_TYPE}/${RunCMake_TEST}-VerifyResult.cmake")
  71. include("${src_dir}/${GENERATOR_TYPE}/${RunCMake_TEST}-VerifyResult.cmake")
  72. else()
  73. # by default only print out output and error so that they can be compared by
  74. # regex
  75. message(STATUS "${output}")
  76. message("${error}")
  77. endif()