source: NonGTP/Boost/boost/detail/lightweight_test.hpp @ 857

Revision 857, 1.9 KB checked in by igarcia, 19 years ago (diff)
RevLine 
[857]1#ifndef BOOST_DETAIL_LIGHTWEIGHT_TEST_HPP_INCLUDED
2#define BOOST_DETAIL_LIGHTWEIGHT_TEST_HPP_INCLUDED
3
4// MS compatible compilers support #pragma once
5
6#if defined(_MSC_VER) && (_MSC_VER >= 1020)
7# pragma once
8#endif
9
10//
11//  boost/detail/lightweight_test.hpp - lightweight test library
12//
13//  Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
14//
15// Distributed under the Boost Software License, Version 1.0. (See
16// accompanying file LICENSE_1_0.txt or copy at
17// http://www.boost.org/LICENSE_1_0.txt)
18//
19//  BOOST_TEST(expression)
20//  BOOST_ERROR(message)
21//
22//  int boost::report_errors()
23//
24
25#include <boost/current_function.hpp>
26#include <iostream>
27
28namespace boost
29{
30
31namespace detail
32{
33
34inline int & test_errors()
35{
36    static int x = 0;
37    return x;
38}
39
40inline void test_failed_impl(char const * expr, char const * file, int line, char const * function)
41{
42    std::cerr << file << "(" << line << "): test '" << expr << "' failed in function '" << function << "'" << std::endl;
43    ++test_errors();
44}
45
46inline void error_impl(char const * msg, char const * file, int line, char const * function)
47{
48    std::cerr << file << "(" << line << "): " << msg << " in function '" << function << "'" << std::endl;
49    ++test_errors();
50}
51
52} // namespace detail
53
54inline int report_errors()
55{
56    int errors = detail::test_errors();
57
58    if(errors == 0)
59    {
60        std::cerr << "No errors detected." << std::endl;
61        return 0;
62    }
63    else
64    {
65        std::cerr << errors << " error" << (errors == 1? "": "s") << " detected." << std::endl;
66        return 1;
67    }
68}
69
70} // namespace boost
71
72#define BOOST_TEST(expr) ((expr)? (void)0: ::boost::detail::test_failed_impl(#expr, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION))
73#define BOOST_ERROR(msg) ::boost::detail::error_impl(msg, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION)
74
75#endif // #ifndef BOOST_DETAIL_LIGHTWEIGHT_TEST_HPP_INCLUDED
Note: See TracBrowser for help on using the repository browser.