123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325 |
- [/
- Copyright 2010, 2011 Beman Dawes
- Copyright 2013 Ion Gaztanaga
- Copyright 2014-2019 Peter Dimov
- Copyright 2017 Kohei Takahashi
- Distributed under the Boost Software License, Version 1.0.
- See accompanying file LICENSE_1_0.txt
- or copy at http://boost.org/LICENSE_1_0.txt
- ]
- [section:lightweight_test lightweight_test]
- [simplesect Authors]
- * Peter Dimov
- * Beman Dawes
- [endsimplesect]
- [section Header <boost/core/lightweight_test.hpp>]
- The header `<boost/core/lightweight_test.hpp>` is a
- lightweight test framework. It's useful for writing
- Boost regression tests for components that are dependencies
- of Boost.Test.
- When using `lightweight_test.hpp`, *do not forget* to
- `return boost::report_errors()` from `main`.
- [section Synopsis]
- ``
- #define BOOST_TEST(expression) /*unspecified*/
- #define BOOST_TEST_NOT(expression) /*unspecified*/
- #define BOOST_ERROR(message) /*unspecified*/
- #define BOOST_TEST_EQ(expr1, expr2) /*unspecified*/
- #define BOOST_TEST_NE(expr1, expr2) /*unspecified*/
- #define BOOST_TEST_LT(expr1, expr2) /*unspecified*/
- #define BOOST_TEST_LE(expr1, expr2) /*unspecified*/
- #define BOOST_TEST_GT(expr1, expr2) /*unspecified*/
- #define BOOST_TEST_GE(expr1, expr2) /*unspecified*/
- #define BOOST_TEST_CSTR_EQ(expr1, expr2) /*unspecified*/
- #define BOOST_TEST_CSTR_NE(expr1, expr2) /*unspecified*/
- #define BOOST_TEST_ALL_EQ(begin1, end1, begin2, end2) /* unspecified */
- #define BOOST_TEST_ALL_WITH(begin1, end1, begin2, end2, predicate) /* unspecified */
- #define BOOST_TEST_THROWS(expr, excep) /*unspecified*/
- namespace boost
- {
- int report_errors();
- }
- ``
- [endsect]
- [section BOOST_TEST]
- ``
- BOOST_TEST(expression)
- ``
- If expression is false increases the error count and outputs a
- message containing `expression`.
- [endsect]
- [section BOOST_TEST_NOT]
- ``
- BOOST_TEST_NOT(expression)
- ``
- If expression is true increases the error count and outputs a
- message containing `!(expression)`.
- [endsect]
- [section BOOST_ERROR]
- ``
- BOOST_ERROR(message)
- ``
- Increases error count and outputs a message containing
- `message`.
- [endsect]
- [section BOOST_TEST_EQ]
- ``
- BOOST_TEST_EQ(expr1, expr2)
- ``
- If `expr1 == expr2` is not true increases the error count and outputs a
- message containing both expressions.
- [endsect]
- [section BOOST_TEST_NE]
- ``
- BOOST_TEST_NE(expr1, expr2)
- ``
- If `expr1 != expr2` is not true increases the error count and outputs a
- message containing both expressions.
- [endsect]
- [section BOOST_TEST_LT]
- ``
- BOOST_TEST_LT(expr1, expr2)
- ``
- If `expr1 < expr2` is not true increases the error count and outputs a
- message containing both expressions.
- [endsect]
- [section BOOST_TEST_LE]
- ``
- BOOST_TEST_LE(expr1, expr2)
- ``
- If `expr1 <= expr2` is not true increases the error count and outputs a
- message containing both expressions.
- [endsect]
- [section BOOST_TEST_GT]
- ``
- BOOST_TEST_GT(expr1, expr2)
- ``
- If `expr1 > expr2` is not true increases the error count and outputs a
- message containing both expressions.
- [endsect]
- [section BOOST_TEST_GE]
- ``
- BOOST_TEST_GE(expr1, expr2)
- ``
- If `expr1 >= expr2` is not true increases the error count and outputs a
- message containing both expressions.
- [endsect]
- [section BOOST_TEST_CSTR_EQ]
- ``
- BOOST_TEST_CSTR_EQ(expr1, expr2)
- ``
- 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.
- [endsect]
- [section BOOST_TEST_CSTR_NE]
- ``
- BOOST_TEST_CSTR_NE(expr1, expr2)
- ``
- 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.
- [endsect]
- [section BOOST_TEST_ALL_EQ]
- ``
- BOOST_TEST_ALL_EQ(begin1, end1, begin2, end2)
- ``
- 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.
- [endsect]
- [section BOOST_TEST_ALL_WITH]
- ``
- BOOST_TEST_ALL_WITH(begin1, end1, begin2, end2, predicate)
- ``
- 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.
- [endsect]
- [section BOOST_TEST_THROWS]
- ``
- BOOST_TEST_THROWS(expr, excep)
- ``
- If `BOOST_NO_EXCEPTIONS` is *not* defined and if `expr` does not
- throw an exception of type `excep`, increases the error count
- and outputs a message containing the expression.
- If `BOOST_NO_EXCEPTIONS` is defined, this macro expands to
- nothing and `expr` is not evaluated.
- [endsect]
- [section report_errors]
- ``
- int boost::report_errors()
- ``
- Return the error count from `main`.
- [endsect]
- [section Example]
- ``
- #include <boost/core/lightweight_test.hpp>
- int sqr( int x )
- {
- return x * x;
- }
- int main()
- {
- BOOST_TEST( sqr(2) == 4 );
- BOOST_TEST_EQ( sqr(-3), 9 );
- return boost::report_errors();
- }
- ``
- [endsect]
- [endsect]
- [section Header <boost/core/lightweight_test_trait.hpp>]
- The header `<boost/core/lightweight_test_trait.hpp>` defines
- a couple of extra macros for testing compile-time traits that
- return a boolean value.
- [section Synopsis]
- ``
- #define BOOST_TEST_TRAIT_TRUE((Trait)) /*unspecified*/
- #define BOOST_TEST_TRAIT_FALSE((Trait)) /*unspecified*/
- #define BOOST_TEST_TRAIT_SAME(Type1, Type2) /*unspecified*/
- ``
- [endsect]
- [section BOOST_TEST_TRAIT_TRUE]
- ``
- BOOST_TEST_TRAIT_TRUE((Trait))
- ``
- If `Trait::value != true` increases the error count and outputs a
- message containing `Trait`. Note the double set of parentheses; these
- enable `Trait` to contain a comma, which is common for templates.
- [endsect]
- [section BOOST_TEST_TRAIT_FALSE]
- ``
- BOOST_TEST_TRAIT_FALSE((Trait))
- ``
- If `Trait::value != false` increases the error count and outputs a
- message containing `Trait`. Note the double set of parentheses.
- [endsect]
- [section BOOST_TEST_TRAIT_SAME]
- ``
- BOOST_TEST_TRAIT_SAME(Type1, Type2)
- ``
- If the two types are not the same, increases the error count and outputs a
- message containing them. This macro requires that the compiler supports
- variadic macros and `__VA_ARGS__`. (Note that unlike `BOOST_TEST_TRAIT_TRUE`
- and `BOOST_TEST_TRAIT_FALSE`, this macro only requires a single set of
- parentheses.)
- [endsect]
- [section Example]
- ``
- #include <boost/core/lightweight_test_trait.hpp>
- #include <boost/core/is_same.hpp>
- template<class T, class U> struct X
- {
- typedef T type;
- };
- using boost::core::is_same;
- int main()
- {
- BOOST_TEST_TRAIT_TRUE(( is_same<X<int, long>::type, int> ));
- BOOST_TEST_TRAIT_SAME( X<int, long>::type, int );
- return boost::report_errors();
- }
- ``
- [endsect]
- [endsect]
- [endsect]
|