lightweight_test.qbk 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. [/
  2. Copyright 2010, 2011 Beman Dawes
  3. Copyright 2013 Ion Gaztanaga
  4. Copyright 2014-2019 Peter Dimov
  5. Copyright 2017 Kohei Takahashi
  6. Distributed under the Boost Software License, Version 1.0.
  7. See accompanying file LICENSE_1_0.txt
  8. or copy at http://boost.org/LICENSE_1_0.txt
  9. ]
  10. [section:lightweight_test lightweight_test]
  11. [simplesect Authors]
  12. * Peter Dimov
  13. * Beman Dawes
  14. [endsimplesect]
  15. [section Header <boost/core/lightweight_test.hpp>]
  16. The header `<boost/core/lightweight_test.hpp>` is a
  17. lightweight test framework. It's useful for writing
  18. Boost regression tests for components that are dependencies
  19. of Boost.Test.
  20. When using `lightweight_test.hpp`, *do not forget* to
  21. `return boost::report_errors()` from `main`.
  22. [section Synopsis]
  23. ``
  24. #define BOOST_TEST(expression) /*unspecified*/
  25. #define BOOST_TEST_NOT(expression) /*unspecified*/
  26. #define BOOST_ERROR(message) /*unspecified*/
  27. #define BOOST_TEST_EQ(expr1, expr2) /*unspecified*/
  28. #define BOOST_TEST_NE(expr1, expr2) /*unspecified*/
  29. #define BOOST_TEST_LT(expr1, expr2) /*unspecified*/
  30. #define BOOST_TEST_LE(expr1, expr2) /*unspecified*/
  31. #define BOOST_TEST_GT(expr1, expr2) /*unspecified*/
  32. #define BOOST_TEST_GE(expr1, expr2) /*unspecified*/
  33. #define BOOST_TEST_CSTR_EQ(expr1, expr2) /*unspecified*/
  34. #define BOOST_TEST_CSTR_NE(expr1, expr2) /*unspecified*/
  35. #define BOOST_TEST_ALL_EQ(begin1, end1, begin2, end2) /* unspecified */
  36. #define BOOST_TEST_ALL_WITH(begin1, end1, begin2, end2, predicate) /* unspecified */
  37. #define BOOST_TEST_THROWS(expr, excep) /*unspecified*/
  38. namespace boost
  39. {
  40. int report_errors();
  41. }
  42. ``
  43. [endsect]
  44. [section BOOST_TEST]
  45. ``
  46. BOOST_TEST(expression)
  47. ``
  48. If expression is false increases the error count and outputs a
  49. message containing `expression`.
  50. [endsect]
  51. [section BOOST_TEST_NOT]
  52. ``
  53. BOOST_TEST_NOT(expression)
  54. ``
  55. If expression is true increases the error count and outputs a
  56. message containing `!(expression)`.
  57. [endsect]
  58. [section BOOST_ERROR]
  59. ``
  60. BOOST_ERROR(message)
  61. ``
  62. Increases error count and outputs a message containing
  63. `message`.
  64. [endsect]
  65. [section BOOST_TEST_EQ]
  66. ``
  67. BOOST_TEST_EQ(expr1, expr2)
  68. ``
  69. If `expr1 == expr2` is not true increases the error count and outputs a
  70. message containing both expressions.
  71. [endsect]
  72. [section BOOST_TEST_NE]
  73. ``
  74. BOOST_TEST_NE(expr1, expr2)
  75. ``
  76. If `expr1 != expr2` is not true increases the error count and outputs a
  77. message containing both expressions.
  78. [endsect]
  79. [section BOOST_TEST_LT]
  80. ``
  81. BOOST_TEST_LT(expr1, expr2)
  82. ``
  83. If `expr1 < expr2` is not true increases the error count and outputs a
  84. message containing both expressions.
  85. [endsect]
  86. [section BOOST_TEST_LE]
  87. ``
  88. BOOST_TEST_LE(expr1, expr2)
  89. ``
  90. If `expr1 <= expr2` is not true increases the error count and outputs a
  91. message containing both expressions.
  92. [endsect]
  93. [section BOOST_TEST_GT]
  94. ``
  95. BOOST_TEST_GT(expr1, expr2)
  96. ``
  97. If `expr1 > expr2` is not true increases the error count and outputs a
  98. message containing both expressions.
  99. [endsect]
  100. [section BOOST_TEST_GE]
  101. ``
  102. BOOST_TEST_GE(expr1, expr2)
  103. ``
  104. If `expr1 >= expr2` is not true increases the error count and outputs a
  105. message containing both expressions.
  106. [endsect]
  107. [section BOOST_TEST_CSTR_EQ]
  108. ``
  109. BOOST_TEST_CSTR_EQ(expr1, expr2)
  110. ``
  111. Specialization of `BOOST_TEST_EQ` which interprets `expr1` and `expr2` as pointers to null-terminated byte strings (C strings). If `std::strcmp(expr1, expr2) != 0`, increase the error count and output a message containing both expressions.
  112. [endsect]
  113. [section BOOST_TEST_CSTR_NE]
  114. ``
  115. BOOST_TEST_CSTR_NE(expr1, expr2)
  116. ``
  117. Specialization of `BOOST_TEST_NE` which interprets `expr1` and `expr2` as pointers to null-terminated byte strings (C strings). If `std::strcmp(expr1, expr2) == 0`, increase the error count and output a message containing both expressions.
  118. [endsect]
  119. [section BOOST_TEST_ALL_EQ]
  120. ``
  121. BOOST_TEST_ALL_EQ(begin1, end1, begin2, end2)
  122. ``
  123. Compares the content of two sequences. If they have different sizes, or if any pairwise element differs, increases the error count and outputs a message containing at most 8 differing elements.
  124. [endsect]
  125. [section BOOST_TEST_ALL_WITH]
  126. ``
  127. BOOST_TEST_ALL_WITH(begin1, end1, begin2, end2, predicate)
  128. ``
  129. Compares the content of two sequences. If they have different sizes, or if any pairwise element do not fulfill the binary predicate, increases the error count and outputs a message containing at most 8 differing elements.
  130. [endsect]
  131. [section BOOST_TEST_THROWS]
  132. ``
  133. BOOST_TEST_THROWS(expr, excep)
  134. ``
  135. If `BOOST_NO_EXCEPTIONS` is *not* defined and if `expr` does not
  136. throw an exception of type `excep`, increases the error count
  137. and outputs a message containing the expression.
  138. If `BOOST_NO_EXCEPTIONS` is defined, this macro expands to
  139. nothing and `expr` is not evaluated.
  140. [endsect]
  141. [section report_errors]
  142. ``
  143. int boost::report_errors()
  144. ``
  145. Return the error count from `main`.
  146. [endsect]
  147. [section Example]
  148. ``
  149. #include <boost/core/lightweight_test.hpp>
  150. int sqr( int x )
  151. {
  152. return x * x;
  153. }
  154. int main()
  155. {
  156. BOOST_TEST( sqr(2) == 4 );
  157. BOOST_TEST_EQ( sqr(-3), 9 );
  158. return boost::report_errors();
  159. }
  160. ``
  161. [endsect]
  162. [endsect]
  163. [section Header <boost/core/lightweight_test_trait.hpp>]
  164. The header `<boost/core/lightweight_test_trait.hpp>` defines
  165. a couple of extra macros for testing compile-time traits that
  166. return a boolean value.
  167. [section Synopsis]
  168. ``
  169. #define BOOST_TEST_TRAIT_TRUE((Trait)) /*unspecified*/
  170. #define BOOST_TEST_TRAIT_FALSE((Trait)) /*unspecified*/
  171. #define BOOST_TEST_TRAIT_SAME(Type1, Type2) /*unspecified*/
  172. ``
  173. [endsect]
  174. [section BOOST_TEST_TRAIT_TRUE]
  175. ``
  176. BOOST_TEST_TRAIT_TRUE((Trait))
  177. ``
  178. If `Trait::value != true` increases the error count and outputs a
  179. message containing `Trait`. Note the double set of parentheses; these
  180. enable `Trait` to contain a comma, which is common for templates.
  181. [endsect]
  182. [section BOOST_TEST_TRAIT_FALSE]
  183. ``
  184. BOOST_TEST_TRAIT_FALSE((Trait))
  185. ``
  186. If `Trait::value != false` increases the error count and outputs a
  187. message containing `Trait`. Note the double set of parentheses.
  188. [endsect]
  189. [section BOOST_TEST_TRAIT_SAME]
  190. ``
  191. BOOST_TEST_TRAIT_SAME(Type1, Type2)
  192. ``
  193. If the two types are not the same, increases the error count and outputs a
  194. message containing them. This macro requires that the compiler supports
  195. variadic macros and `__VA_ARGS__`. (Note that unlike `BOOST_TEST_TRAIT_TRUE`
  196. and `BOOST_TEST_TRAIT_FALSE`, this macro only requires a single set of
  197. parentheses.)
  198. [endsect]
  199. [section Example]
  200. ``
  201. #include <boost/core/lightweight_test_trait.hpp>
  202. #include <boost/core/is_same.hpp>
  203. template<class T, class U> struct X
  204. {
  205. typedef T type;
  206. };
  207. using boost::core::is_same;
  208. int main()
  209. {
  210. BOOST_TEST_TRAIT_TRUE(( is_same<X<int, long>::type, int> ));
  211. BOOST_TEST_TRAIT_SAME( X<int, long>::type, int );
  212. return boost::report_errors();
  213. }
  214. ``
  215. [endsect]
  216. [endsect]
  217. [endsect]