]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/test/minimal.hpp
bump version to 18.2.2-pve1
[ceph.git] / ceph / src / boost / boost / test / minimal.hpp
1 // (C) Copyright Gennadiy Rozental 2001.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5
6 // See http://www.boost.org/libs/test for the library home page.
7 //
8 /// @file
9 /// @brief Deprecated implementation of simple minimal testing
10 /// @deprecated
11 /// To convert to Unit Test Framework simply rewrite:
12 /// @code
13 /// #include <boost/test/minimal.hpp>
14 ///
15 /// int test_main( int, char *[] )
16 /// {
17 /// ...
18 /// }
19 /// @endcode
20 /// as
21 /// @code
22 /// #include <boost/test/included/unit_test.hpp>
23 ///
24 /// BOOST_AUTO_TEST_CASE(test_main)
25 /// {
26 /// ...
27 /// }
28 /// @endcode
29 // ***************************************************************************
30
31 #ifndef BOOST_TEST_MINIMAL_HPP_071894GER
32 #define BOOST_TEST_MINIMAL_HPP_071894GER
33
34 #include <boost/config/header_deprecated.hpp>
35 BOOST_HEADER_DEPRECATED( "<boost/test/included/unit_test.hpp>" )
36 #if defined(BOOST_ALLOW_DEPRECATED_HEADERS)
37 BOOST_PRAGMA_MESSAGE( "Boost.Test minimal is deprecated. Please convert to the header only variant of Boost.Test." )
38 #endif
39
40 #define BOOST_CHECK(exp) \
41 ( (exp) \
42 ? static_cast<void>(0) \
43 : boost::minimal_test::report_error(#exp,__FILE__,__LINE__, BOOST_CURRENT_FUNCTION) )
44
45 #define BOOST_REQUIRE(exp) \
46 ( (exp) \
47 ? static_cast<void>(0) \
48 : boost::minimal_test::report_critical_error(#exp,__FILE__,__LINE__,BOOST_CURRENT_FUNCTION))
49
50 #define BOOST_ERROR( msg_ ) \
51 boost::minimal_test::report_error( (msg_),__FILE__,__LINE__, BOOST_CURRENT_FUNCTION, true )
52 #define BOOST_FAIL( msg_ ) \
53 boost::minimal_test::report_critical_error( (msg_),__FILE__,__LINE__, BOOST_CURRENT_FUNCTION, true )
54
55 //____________________________________________________________________________//
56
57 // Boost.Test
58 #include <boost/test/detail/global_typedef.hpp>
59 #include <boost/test/impl/execution_monitor.ipp>
60 #include <boost/test/impl/debug.ipp>
61 #include <boost/test/utils/class_properties.hpp>
62 #include <boost/test/utils/basic_cstring/io.hpp>
63
64 // Boost
65 #include <boost/cstdlib.hpp> // for exit codes
66 #include <boost/current_function.hpp> // for BOOST_CURRENT_FUNCTION
67
68 // STL
69 #include <iostream> // std::cerr, std::endl
70 #include <string> // std::string
71
72 #include <boost/test/detail/suppress_warnings.hpp>
73
74 //____________________________________________________________________________//
75
76 int test_main( int argc, char* argv[] ); // prototype for users test_main()
77
78 namespace boost {
79 namespace minimal_test {
80
81 typedef boost::unit_test::const_string const_string;
82
83 inline unit_test::counter_t& errors_counter() { static unit_test::counter_t ec = 0; return ec; }
84
85 inline void
86 report_error( const char* msg, const char* file, int line, const_string func_name, bool is_msg = false )
87 {
88 ++errors_counter();
89 std::cerr << file << "(" << line << "): ";
90
91 if( is_msg )
92 std::cerr << msg;
93 else
94 std::cerr << "test " << msg << " failed";
95
96 if( func_name != "(unknown)" )
97 std::cerr << " in function: '" << func_name << "'";
98
99 std::cerr << std::endl;
100 }
101
102 inline void
103 report_critical_error( const char* msg, const char* file, int line, const_string func_name, bool is_msg = false )
104 {
105 report_error( msg, file, line, func_name, is_msg );
106
107 throw boost::execution_aborted();
108 }
109
110 class caller {
111 public:
112 // constructor
113 caller( int argc, char** argv )
114 : m_argc( argc ), m_argv( argv ) {}
115
116 // execution monitor hook implementation
117 int operator()() { return test_main( m_argc, m_argv ); }
118
119 private:
120 // Data members
121 int m_argc;
122 char** m_argv;
123 }; // monitor
124
125 } // namespace minimal_test
126 } // namespace boost
127
128 //____________________________________________________________________________//
129
130 int BOOST_TEST_CALL_DECL main( int argc, char* argv[] )
131 {
132 using namespace boost::minimal_test;
133
134 try {
135 ::boost::execution_monitor ex_mon;
136 int run_result = ex_mon.execute( caller( argc, argv ) );
137
138 BOOST_CHECK( run_result == 0 || run_result == boost::exit_success );
139 }
140 catch( boost::execution_exception const& exex ) {
141 if( exex.code() != boost::execution_exception::no_error )
142 BOOST_ERROR( (std::string( "exception \"" ) + exex.what() + "\" caught").c_str() );
143 std::cerr << "\n**** Testing aborted.";
144 }
145
146 if( boost::minimal_test::errors_counter() != 0 ) {
147 std::cerr << "\n**** " << errors_counter()
148 << " error" << (errors_counter() > 1 ? "s" : "" ) << " detected\n";
149
150 return boost::exit_test_failure;
151 }
152
153 std::cout << "\n**** no errors detected\n";
154
155 return boost::exit_success;
156 }
157
158 //____________________________________________________________________________//
159
160 #include <boost/test/detail/enable_warnings.hpp>
161
162 #endif // BOOST_TEST_MINIMAL_HPP_071894GER