README.txt 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. RunCMake.CPack is a test module that is intended for testing of package
  2. generators that can be validated from command line.
  3. -------------
  4. Adding a test
  5. -------------
  6. CPack test root directory: 'Tests/RunCMake/CPack/tests'.
  7. All phases are executed separately for each generator that is bound to a test.
  8. Tests for each generator are subtests of test 'RunCMake.CPack_<generator_name>'.
  9. Each test must also be added to 'RunCMakeTest.cmake' script located in CPack
  10. test root directory.
  11. Line that adds a test is:
  12. run_cpack_test(<test_name> "<generator_name_list>" <compile_stage>
  13. "<packaging_type_list>")
  14. <generator_name_list> may be one generator e.g. "RPM" or multiple e.g. "RPM;DEB"
  15. and will be run for all listed generators. In test and verification scripts
  16. current generator can be accessed through GENERATOR_TYPE variable.
  17. <compile_stage> is a boolean variable that enables or disables compile stage -
  18. most tests don't require compilation as a non binary file can be used for
  19. package content but sometimes an executable or a library has to be created
  20. before the packaging stage.
  21. <packaging_type_list> can be a list of one or more packaging types: MONOLITHIC,
  22. COMPONENT or GROUP - each type sets per generator default variables which can
  23. be overwritten in the test if needed
  24. (see <generator_type>/packaging_<packaging_type>_default.cmake for the variables
  25. that are set by default for each packaging type).
  26. Alternatively CUSTOM value can be set which means that default values will not
  27. be set and that values will be set manually in the test itself.
  28. Alternatively a test with subtests can be added:
  29. run_cpack_test_subtests(<test_name> "<subtests_list>" "<generator_name_list>"
  30. <compile_stage> "<packaging_type_list>")
  31. <subtests_list> is the only new parameter and it is a list of names that will
  32. be used for subtests. In test and verification scripts subtest name can be
  33. accessed through RunCMake_SUBTEST_SUFFIX variable.
  34. Also source package tests can be added:
  35. run_cpack_source_test(<test_name> "<generator_name_list>" true)
  36. Test consists of
  37. - test prerequirements phase (optional)
  38. - CMake execution phase
  39. - build phase (optional and not available for source package tests)
  40. - CPack execution phase
  41. - verification of generated files
  42. The phases are executed once per specified generator, packaging type and subtest
  43. combinatiion.
  44. test prerequirements phase (optional):
  45. --------------------------------------
  46. In some cases individual tests for certain generator need additional
  47. prerequirements met.
  48. In such cases '<test_name>/<generator_name>-Prerequirements.cmake' file
  49. containing 'function(get_test_prerequirements found_var config_file)' should be
  50. created. Function should return true in found_var if all prerequirements are
  51. met. config_file variable contains the location of config file generated by the
  52. generator so that this function can check if prerequired variable is set in the
  53. file.
  54. NOTE: All required programs should be searched for in generator prerequirements
  55. function and only checked for the variable in configure file in per test
  56. function.
  57. If prerequirements are not met test will be skipped outputting
  58. '<test_name> - SKIPPED' string. Note that this doesn't fail the entire test
  59. group.
  60. TODO: skipped tests should provide expected error string so test should fail
  61. if error string is not found in the output of run test (this would add
  62. 'EXPECTED FAIL' string on success and 'ERROR' on failure).
  63. CMake execution phase:
  64. ----------------------
  65. To add a new CPack test we first create a '<test_name>/test.cmake' script that
  66. contains CMake commands that should be used as a preparation script for
  67. generation of different types of packages. This script is placed into CPack
  68. test root directory.
  69. If test will be used for multiple generators but some of them require some
  70. generator specific commands then those commands should be added to 'test.cmake'
  71. script wrapped with 'if(GENERATOR_TYPE STREQUAL <name_of_the_generator>)'.
  72. NOTE: In some cases (for example when testing CPackComponent.cmake functions)
  73. the test has to run some functions after CPack.cmake is included. In such cases
  74. a function run_after_include_cpack can be declared in test.cmake file and that
  75. function will run after the inclusion of CPack.cmake.
  76. NOTE: During CMake configure stage developer warnings may be expected. In such
  77. cases an expected output regular expression can be provided by creating
  78. '<test_name>/configure-stdout.txt' and/or '<test_name>/configure-stderr.txt'
  79. file. There are also more specialized versions of the file available:
  80. - configure-${PACKAGING_TYPE}-${SUBTEST_SUFFIX}-std${o}.txt
  81. - configure-${SUBTEST_SUFFIX}-std${o}.txt
  82. - configure-${PACKAGING_TYPE}-std${o}.txt
  83. build phase (optional and not available for source package tests)
  84. -----------------------------------------------------------------
  85. This phase only runs make command.
  86. NOTE: By default all tests have CMAKE_BUILD_TYPE variable set to Debug.
  87. CPack execution phase:
  88. ----------------------
  89. Only executes CPack for content that was generated during CMake execution
  90. phase.
  91. NOTE: By default CPACK_PACKAGE_NAME variable is set to lower case test name.
  92. Verification of generated files:
  93. --------------------------------
  94. Verification of generated files consists of two phases
  95. - mandatory verification phase
  96. - optional verification phase
  97. Mandatory verification phase checks that expected files were generated and
  98. contain expected files.
  99. Mandatory verification phase also checks that no other unexpected package files
  100. were generated (this is executed even if EXPECTED_FILES_COUNT contains 0 in
  101. order to verify that no files were generated).
  102. CMake script '<test_name>/ExpectedFiles.cmake' is required by
  103. this step and must contain
  104. - EXPECTED_FILES_COUNT variable that contains the number of expected files that
  105. will be generated (0 or more)
  106. - EXPECTED_FILE_<file_number_starting_with_1> that contains globing expression
  107. that uniquely defines expected file name (will be used to find expected file)
  108. and should be present once for each expected file.
  109. NOTE: This variable should be used only as last resort as it sets generator
  110. specific globbing expression. Each generator can recreate file name from
  111. parts that are already populated by default but can always be
  112. overwritten if needed:
  113. - EXPECTED_FILE_<file_number_starting_with_1>_NAME is the name component of
  114. the file (by default it is set to package name that is same as test name
  115. in lowercase)
  116. - EXPECTED_FILE_<file_number_starting_with_1>_VERSION is the version of the
  117. package (by default it is set to '0.1.1')
  118. - EXPECTED_FILE_<file_number_starting_with_1>_REVISION is the revision of the
  119. package (by default it is set to '1')
  120. - EXPECTED_FILE_CONTENT_<file_number_starting_with_1> that contains regular
  121. expression of files that should be present in generated file and should be
  122. present once for each expected file
  123. NOTE: This variable should be used only as last resort as it sets generator
  124. specific regular expression.
  125. EXPECTED_FILE_CONTENT_<file_number_starting_with_1>_LIST should be
  126. preferred as it requires a list of expected files and directories that
  127. is later changed automatically depending on the generator so expected
  128. package content can be written only once per test for all generators.
  129. - EXPECTED_FILE_PACKAGING_PREFIX and
  130. EXPECTED_FILE_<file_number_starting_with_1>_PACKAGING_PREFIX variables can be
  131. set to explicitly specified CPACK_PACKAGING_PREFIX value. By default this
  132. variable does not need to be set as it is implicitly set to package generator
  133. specific prefix.
  134. Optional verification phase is generator specific and is optionally executed.
  135. This phase is executed if '<test_name>/VerifyResult.cmake' script exists.
  136. VerifyResult.cmake script also automatically prints out standard output and
  137. standard error from CPack execution phase that is compared with
  138. '<test_name>/<generator_name>-stdout.txt' regular expression and
  139. '<test_name>/<generator_name>-stderr.txt' regular expresson respectively.
  140. NOTE: For subtests generator name can also be suffixed with subtest name and/or
  141. packaging type (MONOLITHIC, COMPONENT, GROUP) and in such cases the
  142. preferences of which file will be used are as follows:
  143. - generator name + packaging type + subtest name
  144. - generator name + packaging type
  145. - generator name + subtest name
  146. - generator name
  147. - subtest name
  148. - default generator
  149. File name format: '<generator_name>-<packaging_type>-<subtest_name>-std<type>.txt'
  150. where <type> can either be 'out' or 'err'.
  151. File name format: '<generator_name>-<packaging_type>-std<type>.txt'
  152. where <type> can either be 'out' or 'err'.
  153. File name format: '<generator_name>-<subtest_name>-std<type>.txt' where
  154. <type> can either be 'out' or 'err'.
  155. NOTE: If none of the comparison files are present then the default generator
  156. file is used if present.
  157. ----------------------
  158. Adding a new generator
  159. ----------------------
  160. To add a new generator we must
  161. - add new generator directory (e.g. RPM for RPM generator) to CPack test root
  162. directory that contains 'Helpers.cmake' script.
  163. - In this script some functions must exist:
  164. - getPackageContent: This function should list files that are contained in
  165. a package.
  166. Function parameters:
  167. + FILE variable that will contain path to file for which the content
  168. should be listed
  169. + RESULT_VAR that will tell the function which variable in parent scope
  170. should contain the result (list of files inside package file)
  171. - getPackageNameGlobexpr: This function should generate package name
  172. globbing expression.
  173. Function parameters:
  174. + NAME that will contain the expected package name
  175. + COMPONENT that will contain the expected package component
  176. + VERSION that will contain the expected package version
  177. + REVISION that will contain the expected package revision number
  178. + FILE_NO that will contain the file number for which the globbing
  179. expression is generated
  180. + RESULT_VAR that will tell the function which variable in parent scope
  181. should contain the result (file name globbing expression)
  182. - getPackageContentList: This function should return a list of files and
  183. directories that are in the provided package.
  184. Function parameters:
  185. + FILE that will contain the package file for which the package content
  186. should be returned.
  187. + RESULT_VAR that will tell the function which variable in parent scope
  188. should contain the result (list of package content)
  189. - toExpectedContentList: This function should convert an expected package
  190. content list into one that is expected for the
  191. generator (e.g. rpm packages have install/relocate
  192. path prefixes which aren't part of the package so
  193. those paths have to be removed from the expected
  194. content list).
  195. Function parameters:
  196. + FILE_NO that will contain the file number for which the conversion
  197. should be performed
  198. + CONTENT_VAR that will contain the input list and is also the variable
  199. in parent scope which should contain the result (converted content list)
  200. - add 'Prerequirements.cmake' script to generator directory. In this script a
  201. function named 'get_test_prerequirements' must exist. This function should
  202. set a variable in parent scope (name of the variable is the first parameter)
  203. that tells if prerequirements for test execution are met (certain programs,
  204. OS specifics, ...) and create a config file (name of the variable which
  205. contains file name and path is provided with the second parameter) that
  206. should contain 'set' commands for variables that will later be used in tests
  207. (e.g. location of dpkg program for DEB packages)
  208. - add tests the same way as described above
  209. - add generator to 'add_RunCMake_test_group' function call that is located in
  210. RunCMake CMakeLists.txt file
  211. - if needed add 'packaging_<packaging_type>_default.cmake' scripts that define
  212. default variables that will be set for each packaging type (MONOLITHIC,
  213. COMPONENT and GROUP)
  214. - if needed add 'default_expected_std<type>.txt' files where <type> is either
  215. 'out' or 'err' which will contain default expected output of package
  216. generation regular expression.
  217. - add generator to list of other CPack generators in RunCMake/CMakeLists.txt