Brian Silverman | 407d3cd | 2018-08-04 17:48:52 -0700 | [diff] [blame^] | 1 | [/ |
| 2 | Copyright 2010, 2011 Beman Dawes |
| 3 | Copyright 2013 Ion Gaztanaga |
| 4 | Copyright 2014, 2017 Peter Dimov |
| 5 | Copyright 2017 Kohei Takahashi |
| 6 | |
| 7 | Distributed under the Boost Software License, Version 1.0. |
| 8 | |
| 9 | See accompanying file LICENSE_1_0.txt |
| 10 | or copy at http://boost.org/LICENSE_1_0.txt |
| 11 | ] |
| 12 | |
| 13 | [section:lightweight_test lightweight_test] |
| 14 | |
| 15 | [simplesect Authors] |
| 16 | |
| 17 | * Peter Dimov |
| 18 | * Beman Dawes |
| 19 | |
| 20 | [endsimplesect] |
| 21 | |
| 22 | [section Header <boost/core/lightweight_test.hpp>] |
| 23 | |
| 24 | The header `<boost/core/lightweight_test.hpp>` is a |
| 25 | lightweight test framework. It's useful for writing |
| 26 | Boost regression tests for components that are dependencies |
| 27 | of Boost.Test. |
| 28 | |
| 29 | When using `lightweight_test.hpp`, *do not forget* to |
| 30 | `return boost::report_errors()` from `main`. |
| 31 | |
| 32 | [section Synopsis] |
| 33 | |
| 34 | `` |
| 35 | #define BOOST_TEST(expression) /*unspecified*/ |
| 36 | #define BOOST_TEST_NOT(expression) /*unspecified*/ |
| 37 | #define BOOST_ERROR(message) /*unspecified*/ |
| 38 | #define BOOST_TEST_EQ(expr1, expr2) /*unspecified*/ |
| 39 | #define BOOST_TEST_NE(expr1, expr2) /*unspecified*/ |
| 40 | #define BOOST_TEST_LT(expr1, expr2) /*unspecified*/ |
| 41 | #define BOOST_TEST_LE(expr1, expr2) /*unspecified*/ |
| 42 | #define BOOST_TEST_GT(expr1, expr2) /*unspecified*/ |
| 43 | #define BOOST_TEST_GE(expr1, expr2) /*unspecified*/ |
| 44 | #define BOOST_TEST_CSTR_EQ(expr1, expr2) /*unspecified*/ |
| 45 | #define BOOST_TEST_CSTR_NE(expr1, expr2) /*unspecified*/ |
| 46 | #define BOOST_TEST_ALL_EQ(begin1, end1, begin2, end2) /* unspecified */ |
| 47 | #define BOOST_TEST_ALL_WITH(begin1, end1, begin2, end2, predicate) /* unspecified */ |
| 48 | #define BOOST_TEST_THROWS(expr, excep) /*unspecified*/ |
| 49 | |
| 50 | namespace boost |
| 51 | { |
| 52 | int report_errors(); |
| 53 | } |
| 54 | `` |
| 55 | |
| 56 | [endsect] |
| 57 | |
| 58 | [section BOOST_TEST] |
| 59 | |
| 60 | `` |
| 61 | BOOST_TEST(expression) |
| 62 | `` |
| 63 | |
| 64 | If expression is false increases the error count and outputs a |
| 65 | message containing `expression`. |
| 66 | |
| 67 | [endsect] |
| 68 | |
| 69 | [section BOOST_TEST_NOT] |
| 70 | |
| 71 | `` |
| 72 | BOOST_TEST_NOT(expression) |
| 73 | `` |
| 74 | |
| 75 | If expression is true increases the error count and outputs a |
| 76 | message containing `!(expression)`. |
| 77 | |
| 78 | [endsect] |
| 79 | |
| 80 | [section BOOST_ERROR] |
| 81 | |
| 82 | `` |
| 83 | BOOST_ERROR(message) |
| 84 | `` |
| 85 | |
| 86 | Increases error count and outputs a message containing |
| 87 | `message`. |
| 88 | |
| 89 | [endsect] |
| 90 | |
| 91 | [section BOOST_TEST_EQ] |
| 92 | |
| 93 | `` |
| 94 | BOOST_TEST_EQ(expr1, expr2) |
| 95 | `` |
| 96 | |
| 97 | If `expr1 == expr2` is not true increases the error count and outputs a |
| 98 | message containing both expressions. |
| 99 | |
| 100 | [endsect] |
| 101 | |
| 102 | [section BOOST_TEST_NE] |
| 103 | |
| 104 | `` |
| 105 | BOOST_TEST_NE(expr1, expr2) |
| 106 | `` |
| 107 | |
| 108 | If `expr1 != expr2` is not true increases the error count and outputs a |
| 109 | message containing both expressions. |
| 110 | |
| 111 | [endsect] |
| 112 | |
| 113 | [section BOOST_TEST_LT] |
| 114 | |
| 115 | `` |
| 116 | BOOST_TEST_LT(expr1, expr2) |
| 117 | `` |
| 118 | |
| 119 | If `expr1 < expr2` is not true increases the error count and outputs a |
| 120 | message containing both expressions. |
| 121 | |
| 122 | [endsect] |
| 123 | |
| 124 | [section BOOST_TEST_LE] |
| 125 | |
| 126 | `` |
| 127 | BOOST_TEST_LE(expr1, expr2) |
| 128 | `` |
| 129 | |
| 130 | If `expr1 <= expr2` is not true increases the error count and outputs a |
| 131 | message containing both expressions. |
| 132 | |
| 133 | [endsect] |
| 134 | |
| 135 | [section BOOST_TEST_GT] |
| 136 | |
| 137 | `` |
| 138 | BOOST_TEST_GT(expr1, expr2) |
| 139 | `` |
| 140 | |
| 141 | If `expr1 > expr2` is not true increases the error count and outputs a |
| 142 | message containing both expressions. |
| 143 | |
| 144 | [endsect] |
| 145 | |
| 146 | [section BOOST_TEST_GE] |
| 147 | |
| 148 | `` |
| 149 | BOOST_TEST_GE(expr1, expr2) |
| 150 | `` |
| 151 | |
| 152 | If `expr1 >= expr2` is not true increases the error count and outputs a |
| 153 | message containing both expressions. |
| 154 | |
| 155 | [endsect] |
| 156 | |
| 157 | [section BOOST_TEST_CSTR_EQ] |
| 158 | |
| 159 | `` |
| 160 | BOOST_TEST_CSTR_EQ(expr1, expr2) |
| 161 | `` |
| 162 | |
| 163 | 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. |
| 164 | |
| 165 | [endsect] |
| 166 | |
| 167 | [section BOOST_TEST_CSTR_NE] |
| 168 | |
| 169 | `` |
| 170 | BOOST_TEST_CSTR_NE(expr1, expr2) |
| 171 | `` |
| 172 | |
| 173 | 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. |
| 174 | |
| 175 | [endsect] |
| 176 | |
| 177 | [section BOOST_TEST_ALL_EQ] |
| 178 | |
| 179 | `` |
| 180 | BOOST_TEST_ALL_EQ(begin1, end1, begin2, end2) |
| 181 | `` |
| 182 | |
| 183 | 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. |
| 184 | |
| 185 | [endsect] |
| 186 | |
| 187 | [section BOOST_TEST_ALL_WITH] |
| 188 | |
| 189 | `` |
| 190 | BOOST_TEST_ALL_WITH(begin1, end1, begin2, end2, predicate) |
| 191 | `` |
| 192 | |
| 193 | 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. |
| 194 | |
| 195 | [endsect] |
| 196 | |
| 197 | [section BOOST_TEST_THROWS] |
| 198 | |
| 199 | `` |
| 200 | BOOST_TEST_THROWS(expr, excep) |
| 201 | `` |
| 202 | |
| 203 | If `BOOST_NO_EXCEPTIONS` is *not* defined and if `expr` does not |
| 204 | throw an exception of type `excep`, increases the error count |
| 205 | and outputs a message containing the expression. |
| 206 | |
| 207 | If `BOOST_NO_EXCEPTIONS` is defined, this macro expands to |
| 208 | nothing and `expr` is not evaluated. |
| 209 | |
| 210 | [endsect] |
| 211 | |
| 212 | [section report_errors] |
| 213 | |
| 214 | `` |
| 215 | int boost::report_errors() |
| 216 | `` |
| 217 | |
| 218 | Return the error count from `main`. |
| 219 | |
| 220 | [endsect] |
| 221 | |
| 222 | [section Example] |
| 223 | |
| 224 | `` |
| 225 | #include <boost/core/lightweight_test.hpp> |
| 226 | |
| 227 | int sqr( int x ) |
| 228 | { |
| 229 | return x * x; |
| 230 | } |
| 231 | |
| 232 | int main() |
| 233 | { |
| 234 | BOOST_TEST( sqr(2) == 4 ); |
| 235 | BOOST_TEST_EQ( sqr(-3), 9 ); |
| 236 | |
| 237 | return boost::report_errors(); |
| 238 | } |
| 239 | `` |
| 240 | |
| 241 | [endsect] |
| 242 | |
| 243 | [endsect] |
| 244 | |
| 245 | [section Header <boost/core/lightweight_test_trait.hpp>] |
| 246 | |
| 247 | The header `<boost/core/lightweight_test_trait.hpp>` defines |
| 248 | a couple of extra macros for testing compile-time traits that |
| 249 | return a boolean value. |
| 250 | |
| 251 | [section Synopsis] |
| 252 | |
| 253 | `` |
| 254 | #define BOOST_TEST_TRAIT_TRUE((Trait)) /*unspecified*/ |
| 255 | #define BOOST_TEST_TRAIT_FALSE((Trait)) /*unspecified*/ |
| 256 | `` |
| 257 | |
| 258 | [endsect] |
| 259 | |
| 260 | [section BOOST_TEST_TRAIT_TRUE] |
| 261 | |
| 262 | `` |
| 263 | BOOST_TEST_TRAIT_TRUE((Trait)) |
| 264 | `` |
| 265 | |
| 266 | If `Trait::value != true` increases the error count and outputs a |
| 267 | message containing `Trait`. Note the double set of parentheses; these |
| 268 | enable `Trait` to contain a comma, which is common for templates. |
| 269 | |
| 270 | [endsect] |
| 271 | |
| 272 | [section BOOST_TEST_TRAIT_FALSE] |
| 273 | |
| 274 | `` |
| 275 | BOOST_TEST_TRAIT_FALSE((Trait)) |
| 276 | `` |
| 277 | |
| 278 | If `Trait::value != false` increases the error count and outputs a |
| 279 | message containing `Trait`. Note the double set of parentheses. |
| 280 | |
| 281 | [endsect] |
| 282 | |
| 283 | [section Example] |
| 284 | |
| 285 | `` |
| 286 | #include <boost/core/lightweight_test_trait.hpp> |
| 287 | #include <boost/core/is_same.hpp> |
| 288 | |
| 289 | template<class T, class U> struct X |
| 290 | { |
| 291 | typedef T type; |
| 292 | }; |
| 293 | |
| 294 | using boost::core::is_same; |
| 295 | |
| 296 | int main() |
| 297 | { |
| 298 | BOOST_TEST_TRAIT_TRUE(( is_same<X<int, long>::type, int> )); |
| 299 | |
| 300 | return boost::report_errors(); |
| 301 | } |
| 302 | `` |
| 303 | |
| 304 | [endsect] |
| 305 | |
| 306 | [endsect] |
| 307 | |
| 308 | [endsect] |