2 Copyright 2010, 2011 Beman Dawes
3 Copyright 2013 Ion Gaztanaga
4 Copyright 2014 Peter Dimov
6 Distributed under the Boost Software License, Version 1.0.
8 See accompanying file LICENSE_1_0.txt
9 or copy at http://boost.org/LICENSE_1_0.txt
12 [section:lightweight_test lightweight_test]
21 [section Header <boost/core/lightweight_test.hpp>]
23 The header `<boost/core/lightweight_test.hpp>` is a
24 lightweight test framework. It's useful for writing
25 Boost regression tests for components that are dependencies
28 When using `lightweight_test.hpp`, *do not forget* to
29 `return boost::report_errors()` from `main`.
34 #define BOOST_TEST(expression) /*unspecified*/
35 #define BOOST_TEST_NOT(expression) /*unspecified*/
36 #define BOOST_ERROR(message) /*unspecified*/
37 #define BOOST_TEST_EQ(expr1, expr2) /*unspecified*/
38 #define BOOST_TEST_NE(expr1, expr2) /*unspecified*/
39 #define BOOST_TEST_CSTR_EQ(expr1, expr2) /*unspecified*/
40 #define BOOST_TEST_CSTR_NE(expr1, expr2) /*unspecified*/
41 #define BOOST_TEST_ALL_EQ(begin1, end1, begin2, end2) /* unspecified */
42 #define BOOST_TEST_ALL_WITH(begin1, end1, begin2, end2, predicate) /* unspecified */
43 #define BOOST_TEST_THROWS(expr, excep) /*unspecified*/
56 BOOST_TEST(expression)
59 If expression is false increases the error count and outputs a
60 message containing `expression`.
64 [section BOOST_TEST_NOT]
67 BOOST_TEST_NOT(expression)
70 If expression is true increases the error count and outputs a
71 message containing `!(expression)`.
81 Increases error count and outputs a message containing
86 [section BOOST_TEST_EQ]
89 BOOST_TEST_EQ(expr1, expr2)
92 If `expr1 != expr2` increases the error count and outputs a
93 message containing both expressions.
97 [section BOOST_TEST_NE]
100 BOOST_TEST_NE(expr1, expr2)
103 If `expr1 == expr2` increases the error count and outputs a
104 message containing both expressions.
108 [section BOOST_TEST_CSTR_EQ]
111 BOOST_TEST_CSTR_EQ(expr1, expr2)
114 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.
118 [section BOOST_TEST_CSTR_NE]
121 BOOST_TEST_CSTR_NE(expr1, expr2)
124 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.
128 [section BOOST_TEST_ALL_EQ]
131 BOOST_TEST_ALL_EQ(begin1, end1, begin2, end2)
134 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.
138 [section BOOST_TEST_ALL_WITH]
141 BOOST_TEST_ALL_WITH(begin1, end1, begin2, end2, predicate)
144 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.
148 [section BOOST_TEST_THROWS]
151 BOOST_TEST_THROWS(expr, excep)
154 If `BOOST_NO_EXCEPTIONS` is *not* defined and if `expr` does not
155 throw an exception of type `excep`, increases the error count
156 and outputs a message containing the expression.
158 If `BOOST_NO_EXCEPTIONS` is defined, this macro expands to
159 nothing and `expr` is not evaluated.
163 [section report_errors]
166 int boost::report_errors()
169 Return the error count from `main`.
176 #include <boost/core/lightweight_test.hpp>
185 BOOST_TEST( sqr(2) == 4 );
186 BOOST_TEST_EQ( sqr(-3), 9 );
188 return boost::report_errors();
196 [section Header <boost/core/lightweight_test_trait.hpp>]
198 The header `<boost/core/lightweight_test_trait.hpp>` defines
199 a couple of extra macros for testing compile-time traits that
200 return a boolean value.
205 #define BOOST_TEST_TRAIT_TRUE((Trait)) /*unspecified*/
206 #define BOOST_TEST_TRAIT_FALSE((Trait)) /*unspecified*/
211 [section BOOST_TEST_TRAIT_TRUE]
214 BOOST_TEST_TRAIT_TRUE((Trait))
217 If `Trait::value != true` increases the error count and outputs a
218 message containing `Trait`. Note the double set of parentheses; these
219 enable `Trait` to contain a comma, which is common for templates.
223 [section BOOST_TEST_TRAIT_FALSE]
226 BOOST_TEST_TRAIT_FALSE((Trait))
229 If `Trait::value != false` increases the error count and outputs a
230 message containing `Trait`. Note the double set of parentheses.
237 #include <boost/core/lightweight_test_trait.hpp>
238 #include <boost/core/is_same.hpp>
240 template<class T, class U> struct X
245 using boost::core::is_same;
249 BOOST_TEST_TRAIT_TRUE(( is_same<X<int, long>::type, int> ));
251 return boost::report_errors();