• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1[/
2  Copyright 2010, 2011 Beman Dawes
3  Copyright 2013 Ion Gaztanaga
4  Copyright 2014-2019 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
24The header `<boost/core/lightweight_test.hpp>` is a
25lightweight test framework. It's useful for writing
26Boost regression tests for components that are dependencies
27of Boost.Test.
28
29When 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_WITH(expr1, expr2, pred) /*unspecified*/
47#define BOOST_TEST_ALL_EQ(begin1, end1, begin2, end2) /* unspecified */
48#define BOOST_TEST_ALL_WITH(begin1, end1, begin2, end2, predicate) /* unspecified */
49#define BOOST_TEST_THROWS(expr, excep) /*unspecified*/
50#define BOOST_TEST_NO_THROW(expr) /*unspecified*/
51
52namespace boost
53{
54    int report_errors();
55}
56``
57
58[endsect]
59
60[section BOOST_TEST]
61
62``
63BOOST_TEST(expression)
64``
65
66If expression is false increases the error count and outputs a
67message containing `expression`.
68
69[endsect]
70
71[section BOOST_TEST_NOT]
72
73``
74BOOST_TEST_NOT(expression)
75``
76
77If expression is true increases the error count and outputs a
78message containing `!(expression)`.
79
80[endsect]
81
82[section BOOST_ERROR]
83
84``
85BOOST_ERROR(message)
86``
87
88Increases error count and outputs a message containing
89`message`.
90
91[endsect]
92
93[section BOOST_TEST_EQ]
94
95``
96BOOST_TEST_EQ(expr1, expr2)
97``
98
99If `expr1 == expr2` is not true increases the error count and outputs a
100message containing both expressions.
101
102[endsect]
103
104[section BOOST_TEST_NE]
105
106``
107BOOST_TEST_NE(expr1, expr2)
108``
109
110If `expr1 != expr2` is not true increases the error count and outputs a
111message containing both expressions.
112
113[endsect]
114
115[section BOOST_TEST_LT]
116
117``
118BOOST_TEST_LT(expr1, expr2)
119``
120
121If `expr1 < expr2` is not true increases the error count and outputs a
122message containing both expressions.
123
124[endsect]
125
126[section BOOST_TEST_LE]
127
128``
129BOOST_TEST_LE(expr1, expr2)
130``
131
132If `expr1 <= expr2` is not true increases the error count and outputs a
133message containing both expressions.
134
135[endsect]
136
137[section BOOST_TEST_GT]
138
139``
140BOOST_TEST_GT(expr1, expr2)
141``
142
143If `expr1 > expr2` is not true increases the error count and outputs a
144message containing both expressions.
145
146[endsect]
147
148[section BOOST_TEST_GE]
149
150``
151BOOST_TEST_GE(expr1, expr2)
152``
153
154If `expr1 >= expr2` is not true increases the error count and outputs a
155message containing both expressions.
156
157[endsect]
158
159[section BOOST_TEST_CSTR_EQ]
160
161``
162BOOST_TEST_CSTR_EQ(expr1, expr2)
163``
164
165Specialization 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.
166
167[endsect]
168
169[section BOOST_TEST_CSTR_NE]
170
171``
172BOOST_TEST_CSTR_NE(expr1, expr2)
173``
174
175Specialization 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.
176
177[endsect]
178
179[section BOOST_TEST_WITH]
180
181``
182BOOST_TEST_WITH(expr1, expr2, pred)
183``
184
185If `pred(expr1, expr2)` is not true increases the error count and outputs a
186message containing both expressions.
187
188[endsect]
189
190[section BOOST_TEST_ALL_EQ]
191
192``
193BOOST_TEST_ALL_EQ(begin1, end1, begin2, end2)
194``
195
196Compares 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.
197
198[endsect]
199
200[section BOOST_TEST_ALL_WITH]
201
202``
203BOOST_TEST_ALL_WITH(begin1, end1, begin2, end2, predicate)
204``
205
206Compares 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.
207
208[endsect]
209
210[section BOOST_TEST_THROWS]
211
212``
213BOOST_TEST_THROWS(expr, excep)
214``
215
216If `BOOST_NO_EXCEPTIONS` is *not* defined and if `expr` does not
217throw an exception of type `excep`, increases the error count
218and outputs a message containing the expression.
219
220If `BOOST_NO_EXCEPTIONS` is defined, this macro expands to
221nothing and `expr` is not evaluated.
222
223[endsect]
224
225[section BOOST_TEST_NO_THROW]
226
227``
228BOOST_TEST_NO_THROW(expr)
229``
230
231If `BOOST_NO_EXCEPTIONS` is *not* defined and if `expr` throws an exception,
232increases the error count and outputs a message containing the expression
233and (if possible) the exception message.
234
235If `BOOST_NO_EXCEPTIONS` is defined, `expr` is evaluated.
236
237[endsect]
238
239[section report_errors]
240
241``
242int boost::report_errors()
243``
244
245Return the error count from `main`.
246
247[endsect]
248
249[section Example]
250
251``
252#include <boost/core/lightweight_test.hpp>
253
254int sqr( int x )
255{
256    return x * x;
257}
258
259int main()
260{
261    BOOST_TEST( sqr(2) == 4 );
262    BOOST_TEST_EQ( sqr(-3), 9 );
263
264    return boost::report_errors();
265}
266``
267
268[endsect]
269
270[endsect]
271
272[section Header <boost/core/lightweight_test_trait.hpp>]
273
274The header `<boost/core/lightweight_test_trait.hpp>` defines
275a couple of extra macros for testing compile-time traits that
276return a boolean value.
277
278[section Synopsis]
279
280``
281#define BOOST_TEST_TRAIT_TRUE((Trait)) /*unspecified*/
282#define BOOST_TEST_TRAIT_FALSE((Trait)) /*unspecified*/
283#define BOOST_TEST_TRAIT_SAME(Type1, Type2) /*unspecified*/
284``
285
286[endsect]
287
288[section BOOST_TEST_TRAIT_TRUE]
289
290``
291BOOST_TEST_TRAIT_TRUE((Trait))
292``
293
294If `Trait::value != true` increases the error count and outputs a
295message containing `Trait`. Note the double set of parentheses; these
296enable `Trait` to contain a comma, which is common for templates.
297
298[endsect]
299
300[section BOOST_TEST_TRAIT_FALSE]
301
302``
303BOOST_TEST_TRAIT_FALSE((Trait))
304``
305
306If `Trait::value != false` increases the error count and outputs a
307message containing `Trait`. Note the double set of parentheses.
308
309[endsect]
310
311[section BOOST_TEST_TRAIT_SAME]
312
313``
314BOOST_TEST_TRAIT_SAME(Type1, Type2)
315``
316
317If the two types are not the same, increases the error count and outputs a
318message containing them. This macro requires that the compiler supports
319variadic macros and `__VA_ARGS__`. (Note that unlike `BOOST_TEST_TRAIT_TRUE`
320and `BOOST_TEST_TRAIT_FALSE`, this macro only requires a single set of
321parentheses.)
322
323[endsect]
324
325[section Example]
326
327``
328#include <boost/core/lightweight_test_trait.hpp>
329#include <boost/core/is_same.hpp>
330
331template<class T, class U> struct X
332{
333    typedef T type;
334};
335
336using boost::core::is_same;
337
338int main()
339{
340    BOOST_TEST_TRAIT_TRUE(( is_same<X<int, long>::type, int> ));
341
342    BOOST_TEST_TRAIT_SAME( X<int, long>::type, int );
343
344    return boost::report_errors();
345}
346``
347
348[endsect]
349
350[endsect]
351
352[endsect]
353