1 #ifndef BOOST_DETAIL_LIGHTWEIGHT_TEST_HPP_INCLUDED
2 #define BOOST_DETAIL_LIGHTWEIGHT_TEST_HPP_INCLUDED
4 // MS compatible compilers support #pragma once
6 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
11 // boost/detail/lightweight_test.hpp - lightweight test library
13 // Copyright (c) 2002, 2009 Peter Dimov
15 // Distributed under the Boost Software License, Version 1.0.
16 // See accompanying file LICENSE_1_0.txt or copy at
17 // http://www.boost.org/LICENSE_1_0.txt
19 // BOOST_TEST(expression)
20 // BOOST_ERROR(message)
21 // BOOST_TEST_EQ(expr1, expr2)
23 // int boost::report_errors()
26 #include <boost/current_function.hpp>
27 #include <boost/assert.hpp>
36 struct report_errors_reminder
38 bool called_report_errors_function;
39 report_errors_reminder() : called_report_errors_function(false) {}
40 ~report_errors_reminder()
42 BOOST_ASSERT(called_report_errors_function); // verify report_errors() was called
46 inline report_errors_reminder& report_errors_remind()
48 static report_errors_reminder r;
52 inline int & test_errors()
55 report_errors_remind();
59 inline void test_failed_impl(char const * expr, char const * file, int line, char const * function)
61 std::cerr << file << "(" << line << "): test '" << expr << "' failed in function '" << function << "'" << std::endl;
65 inline void error_impl(char const * msg, char const * file, int line, char const * function)
67 std::cerr << file << "(" << line << "): " << msg << " in function '" << function << "'" << std::endl;
71 template<class T, class U> inline void test_eq_impl( char const * expr1, char const * expr2, char const * file, int line, char const * function, T const & t, U const & u )
78 std::cerr << file << "(" << line << "): test '" << expr1 << " == " << expr2
79 << "' failed in function '" << function << "': "
80 << "'" << t << "' != '" << u << "'" << std::endl;
87 inline int report_errors()
89 detail::report_errors_remind().called_report_errors_function = true;
91 int errors = detail::test_errors();
95 std::cerr << "No errors detected." << std::endl;
100 std::cerr << errors << " error" << (errors == 1? "": "s") << " detected." << std::endl;
107 #define BOOST_TEST(expr) ((expr)? (void)0: ::boost::detail::test_failed_impl(#expr, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION))
108 #define BOOST_ERROR(msg) ::boost::detail::error_impl(msg, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION)
109 #define BOOST_TEST_EQ(expr1,expr2) ( ::boost::detail::test_eq_impl(#expr1, #expr2, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expr1, expr2) )
111 #endif // #ifndef BOOST_DETAIL_LIGHTWEIGHT_TEST_HPP_INCLUDED