blob: 88842391ee0af7c7599b3c9048a208a0eecb7284 [file] [log] [blame]
Brian Silverman407d3cd2018-08-04 17:48:52 -07001[/
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
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_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
50namespace boost
51{
52 int report_errors();
53}
54``
55
56[endsect]
57
58[section BOOST_TEST]
59
60``
61BOOST_TEST(expression)
62``
63
64If expression is false increases the error count and outputs a
65message containing `expression`.
66
67[endsect]
68
69[section BOOST_TEST_NOT]
70
71``
72BOOST_TEST_NOT(expression)
73``
74
75If expression is true increases the error count and outputs a
76message containing `!(expression)`.
77
78[endsect]
79
80[section BOOST_ERROR]
81
82``
83BOOST_ERROR(message)
84``
85
86Increases error count and outputs a message containing
87`message`.
88
89[endsect]
90
91[section BOOST_TEST_EQ]
92
93``
94BOOST_TEST_EQ(expr1, expr2)
95``
96
97If `expr1 == expr2` is not true increases the error count and outputs a
98message containing both expressions.
99
100[endsect]
101
102[section BOOST_TEST_NE]
103
104``
105BOOST_TEST_NE(expr1, expr2)
106``
107
108If `expr1 != expr2` is not true increases the error count and outputs a
109message containing both expressions.
110
111[endsect]
112
113[section BOOST_TEST_LT]
114
115``
116BOOST_TEST_LT(expr1, expr2)
117``
118
119If `expr1 < expr2` is not true increases the error count and outputs a
120message containing both expressions.
121
122[endsect]
123
124[section BOOST_TEST_LE]
125
126``
127BOOST_TEST_LE(expr1, expr2)
128``
129
130If `expr1 <= expr2` is not true increases the error count and outputs a
131message containing both expressions.
132
133[endsect]
134
135[section BOOST_TEST_GT]
136
137``
138BOOST_TEST_GT(expr1, expr2)
139``
140
141If `expr1 > expr2` is not true increases the error count and outputs a
142message containing both expressions.
143
144[endsect]
145
146[section BOOST_TEST_GE]
147
148``
149BOOST_TEST_GE(expr1, expr2)
150``
151
152If `expr1 >= expr2` is not true increases the error count and outputs a
153message containing both expressions.
154
155[endsect]
156
157[section BOOST_TEST_CSTR_EQ]
158
159``
160BOOST_TEST_CSTR_EQ(expr1, expr2)
161``
162
163Specialization 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``
170BOOST_TEST_CSTR_NE(expr1, expr2)
171``
172
173Specialization 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``
180BOOST_TEST_ALL_EQ(begin1, end1, begin2, end2)
181``
182
183Compares 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``
190BOOST_TEST_ALL_WITH(begin1, end1, begin2, end2, predicate)
191``
192
193Compares 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``
200BOOST_TEST_THROWS(expr, excep)
201``
202
203If `BOOST_NO_EXCEPTIONS` is *not* defined and if `expr` does not
204throw an exception of type `excep`, increases the error count
205and outputs a message containing the expression.
206
207If `BOOST_NO_EXCEPTIONS` is defined, this macro expands to
208nothing and `expr` is not evaluated.
209
210[endsect]
211
212[section report_errors]
213
214``
215int boost::report_errors()
216``
217
218Return the error count from `main`.
219
220[endsect]
221
222[section Example]
223
224``
225#include <boost/core/lightweight_test.hpp>
226
227int sqr( int x )
228{
229 return x * x;
230}
231
232int 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
247The header `<boost/core/lightweight_test_trait.hpp>` defines
248a couple of extra macros for testing compile-time traits that
249return 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``
263BOOST_TEST_TRAIT_TRUE((Trait))
264``
265
266If `Trait::value != true` increases the error count and outputs a
267message containing `Trait`. Note the double set of parentheses; these
268enable `Trait` to contain a comma, which is common for templates.
269
270[endsect]
271
272[section BOOST_TEST_TRAIT_FALSE]
273
274``
275BOOST_TEST_TRAIT_FALSE((Trait))
276``
277
278If `Trait::value != false` increases the error count and outputs a
279message 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
289template<class T, class U> struct X
290{
291 typedef T type;
292};
293
294using boost::core::is_same;
295
296int 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]