test_unit_filtering.qbk 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. [/
  2. / Copyright (c) 2003 Boost.Test contributors
  3. /
  4. / Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. /]
  7. [section:test_unit_filtering Test unit filtering]
  8. The __UTF__ offers a number of ways to run only a subset of all test cases registered in the test tree.
  9. [#ref_default_run_status][h3 Default run status]
  10. Each test unit (either test case or test suite) has an associated ['default run status]. It can assume one of the three values:
  11. # ['true] -- this means that, unless some runtime parameters specify otherwise, the test unit is designated to be run.
  12. # ['false] -- this means that, unless some runtime parameters specify otherwise, the test unit is designated ['not] to be run.
  13. # ['inherit] -- this means that the test unit's default run status is the same as that of its immediate parent test unit. This is applied recursively.
  14. Initially, the master test suite has default run status set to ['true]. All other test units have default run status set to ['inherit].
  15. This implies that, unless any additional configuration is applied, all tests are designated to be run.
  16. You can set a different default run status in any test unit by using [link boost_test.tests_organization.decorators decorators]:
  17. __decorator_disabled__, __decorator_enabled__ and __decorator_enable_if__. The default run status is set once, upon testing program
  18. initialization, and cannot be changed. The disabled tests are not executed by default, but are still present in the test tree,
  19. and are listed along with other tests when you use command-line argument
  20. [link boost_test.utf_reference.rt_param_reference.list_content `list_content`].
  21. [bt_example decorator_20..default run status..run-fail]
  22. [#ref_dynamic_test_dependency][h3 Dynamic test dependencies]
  23. Additionally, it is possible to statically associate a test unit with a condition. This associated condition is evaluated immediately
  24. before executing the test unit. If the condition is met, the test unit is executed. Otherwise, the test unit is ['skipped].
  25. It is possible to add two dependencies:
  26. # Upon another test unit. In this case the decorated test case is skipped if the test unit specified in the dependency is either
  27. failed or skipped or disabled. This can be declared with decorator __decorator_depends_on__.
  28. # Upon an arbitrary predicate. This can be declared with decorator __decorator_precondition__.
  29. [#ref_command_line_control][h3 Command-line control]
  30. Static configuration of the test-case filtering is used by default, unless command-line filtering is applied. With command-line argument
  31. __param_run_test__ it is possible to alter the static pre-set in a number of ways:
  32. # Ignore the static configuration and manually specify test cases to be run.
  33. # Augment the statically defined set by enabling the disabled test cases.
  34. # Shrink the statically defined set by disabling some of the enabled test cases.
  35. [#ref_command_line_control_absolute][h4 Absolute specification]
  36. Term 'absolute' in this context means that the default run status of the test units, which has been statically set up,
  37. is completely ignored and the tests to be run are specified manually from scratch. First, in order to learn what test
  38. units are registered in the test tree the user needs to use command-line argument
  39. [link boost_test.utf_reference.rt_param_reference.list_content `list_content`].
  40. Next, in order to specify a set of test cases, the user needs to use command-line argument
  41. __param_run_test__ with absolute value:
  42. ```
  43. > test_program --__param_run_test__=<test_set>
  44. ```
  45. The format of `<test_set>` value can assume a number of forms. Given the following program:
  46. ```
  47. #define __BOOST_TEST_MODULE__ example
  48. #include <boost/test/included/unit_test.hpp>
  49. using boost::unit_test::__decorator_label__;
  50. __BOOST_AUTO_TEST_CASE__(test_1, *label("L1")) {}
  51. BOOST_AUTO_TEST_CASE(test_2, *label("L1")) {}
  52. __BOOST_AUTO_TEST_SUITE__(suite_1)
  53. BOOST_AUTO_TEST_SUITE(suite_1)
  54. BOOST_AUTO_TEST_CASE(test_1) {}
  55. BOOST_AUTO_TEST_CASE(test_2) {}
  56. BOOST_AUTO_TEST_SUITE_END()
  57. BOOST_AUTO_TEST_SUITE(suite_2)
  58. BOOST_AUTO_TEST_CASE(test_1, *label("L2")) {}
  59. BOOST_AUTO_TEST_CASE(test_2, *label("L2")) {}
  60. BOOST_AUTO_TEST_SUITE_END()
  61. BOOST_AUTO_TEST_CASE(test_1, *label("L1")) {}
  62. BOOST_AUTO_TEST_CASE(test_2) {}
  63. BOOST_AUTO_TEST_CASE(test_2A) {}
  64. BOOST_AUTO_TEST_SUITE_END()
  65. ```
  66. The following table illustrates how different values of `<test_set>` control which test cases ware run.
  67. [table
  68. [
  69. [Description]
  70. [Parameter value]
  71. [Test cases run]
  72. ]
  73. [
  74. [Run single top-level test case by name]
  75. [[pre __param_run_test__=test_1]]
  76. [
  77. [pre
  78. test_1
  79. ]
  80. ]
  81. ]
  82. [
  83. [Run single nested test case by name]
  84. [[pre __param_run_test__=suite_1/suite_1/test_1]]
  85. [
  86. [pre
  87. suite_1/suite_1/test_1
  88. ]
  89. ]
  90. ]
  91. [
  92. [Run single test suite by name]
  93. [
  94. [pre __param_run_test__=suite_1/suite_2
  95. __param_run_test__=suite_1/suite_2/*
  96. ]
  97. ]
  98. [
  99. [pre
  100. suite_1/suite_2/test_1
  101. suite_1/suite_2/test_2
  102. ]
  103. ]
  104. ]
  105. [
  106. [Run multiple test units that are *siblings* of the same test suite]
  107. [[pre __param_run_test__=suite_1/test_1,suite_2]]
  108. [
  109. [pre
  110. suite_1/suite_2/test_1
  111. suite_1/suite_2/test_2
  112. suite_1/test_1
  113. ]
  114. ]
  115. ]
  116. [
  117. [Run multiple test units that are not necessarily siblings]
  118. [[pre __param_run_test__=suite_1/test_1:test_1]]
  119. [
  120. [pre
  121. suite_1/test_1
  122. test_1
  123. ]
  124. ]
  125. ]
  126. [
  127. [Run all tests matching to a given label]
  128. [[pre __param_run_test__=@L1]]
  129. [
  130. [pre
  131. test_1
  132. test_2
  133. suite_1/test_1
  134. ]
  135. ]
  136. ]
  137. [
  138. [Run every test case in the test tree. Note that this will also enable all disabled tests.]
  139. [[pre __param_run_test__=*]]
  140. [
  141. [pre
  142. test_1
  143. test_2
  144. suite_1/suite_1/test_1
  145. suite_1/suite_1/test_2
  146. suite_1/suite_2/test_1
  147. suite_1/suite_2/test_2
  148. suite_1/test_1
  149. suite_1/test_2
  150. suite_1/test_2A
  151. ]
  152. ]
  153. ]
  154. [
  155. [Run every test unit in a given suite with a given prefix]
  156. [[pre __param_run_test__=suite_1/test*]]
  157. [
  158. [pre
  159. suite_1/test_1
  160. suite_1/test_2
  161. suite_1/test_2A
  162. ]
  163. ]
  164. ]
  165. [
  166. [Run every test unit in a given suite with a given suffix]
  167. [[pre __param_run_test__=suite_1/*_1]]
  168. [
  169. [pre
  170. suite_1/suite_1/test_1
  171. suite_1/suite_1/test_2
  172. suite_1/test_1
  173. ]
  174. ]
  175. ]
  176. [
  177. [Run every test unit in a given suite with a given infix]
  178. [[pre __param_run_test__=suite_1/\*_2\*]]
  179. [
  180. [pre
  181. suite_1/suite_2/test_1
  182. suite_1/suite_2/test_2
  183. suite_1/test_2
  184. suite_1/test_2A
  185. ]
  186. ]
  187. ]
  188. [
  189. [Run test(s) with given name in any N-level suite]
  190. [[pre __param_run_test__=\*/\*/test_2]]
  191. [
  192. [pre
  193. suite_1/suite_1/test_2
  194. suite_1/suite_2/test_2
  195. ]
  196. ]
  197. ]
  198. ]
  199. For the syntax productions describing the structure of `<test_set>` value see [link boost_test.utf_reference.rt_param_reference.run_test here].
  200. While using manual absolute test case specification ignores the default run status, it does not ignore the dynamic test dependencies.
  201. If test unit `B` depends on test unit `A` and test `B` is specified to be run by __param_run_test__, `A` is also run, even
  202. if it is not specified, and its failure may cause the execution of `B` to be skipped. Similarly, the failed check of
  203. the __decorator_precondition__ may cause the test selected test to be skipped.
  204. [bt_example decorator_21..run_test and dynamic dependencies..run-fail]
  205. [#ref_command_line_control_enablers][h4 Relative specification]
  206. Term 'relative' in this context means that the configuration is based on either the default run status of the test units or
  207. by the command-line override specified by the ['absolute specification]; and atop of this, we additionally either enable
  208. some disabled test units or disable some enabled tests units. The relative specification is controlled by command-line
  209. argument __param_run_test__, with the value using similar syntax as in the absolute specification, but preceded with
  210. either character `'!'` for disabling enabled test units or with character `'+'` for enabling the disabled test units.
  211. This can be summarized with the following table:
  212. [table
  213. [ [command][specification type][semantics] ]
  214. [ [[pre > test_program --__param_run_test__=!<absolute_spec>]][disabler][Enabled test units that match `<absolute_spec>` become disabled.] ]
  215. [ [[pre > test_program --__param_run_test__=+<absolute_spec>]][enabler][Disabled test units that match `<absolute_spec>` as well as their upstream dependencies become enabled.] ]
  216. ]
  217. The ['enabler] specification is used to enable a set of test units which are initially disabled.
  218. [bt_example decorator_22..command-line enabler..run]
  219. Conversely, the ['disabler] specification is used to disable a set of test units which are initially enabled.
  220. [bt_example decorator_23..command-line disabler..run]
  221. If there are both an enabler and disabler on one command line that specify the same test, the test becomes disabled. I.e.,
  222. the disabler takes the precedence over the enabler.
  223. [note While enabler additionally enables the upstream dependencies (introduced with decorator __decorator_depends_on__),
  224. disabler does not disable them. Therefore when you enable and then disable the same test, you do not disable its upstream dependencies.]
  225. [/----------------------------------------------]
  226. [endsect] [/ section:test_unit_filtering]