]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | ||
92f5a8d4 TL |
34 | #include <boost/config/header_deprecated.hpp> |
35 | BOOST_HEADER_DEPRECATED( "Boost.Test minimal is deprecated. Please convert to the header only variant of Boost.Test." ) | |
36 | ||
7c673cae FG |
37 | #define BOOST_CHECK(exp) \ |
38 | ( (exp) \ | |
39 | ? static_cast<void>(0) \ | |
40 | : boost::minimal_test::report_error(#exp,__FILE__,__LINE__, BOOST_CURRENT_FUNCTION) ) | |
41 | ||
42 | #define BOOST_REQUIRE(exp) \ | |
43 | ( (exp) \ | |
44 | ? static_cast<void>(0) \ | |
45 | : boost::minimal_test::report_critical_error(#exp,__FILE__,__LINE__,BOOST_CURRENT_FUNCTION)) | |
46 | ||
47 | #define BOOST_ERROR( msg_ ) \ | |
48 | boost::minimal_test::report_error( (msg_),__FILE__,__LINE__, BOOST_CURRENT_FUNCTION, true ) | |
49 | #define BOOST_FAIL( msg_ ) \ | |
50 | boost::minimal_test::report_critical_error( (msg_),__FILE__,__LINE__, BOOST_CURRENT_FUNCTION, true ) | |
51 | ||
52 | //____________________________________________________________________________// | |
53 | ||
54 | // Boost.Test | |
55 | #include <boost/test/detail/global_typedef.hpp> | |
56 | #include <boost/test/impl/execution_monitor.ipp> | |
57 | #include <boost/test/impl/debug.ipp> | |
58 | #include <boost/test/utils/class_properties.hpp> | |
59 | #include <boost/test/utils/basic_cstring/io.hpp> | |
60 | ||
61 | // Boost | |
62 | #include <boost/cstdlib.hpp> // for exit codes | |
63 | #include <boost/current_function.hpp> // for BOOST_CURRENT_FUNCTION | |
64 | ||
65 | // STL | |
66 | #include <iostream> // std::cerr, std::endl | |
67 | #include <string> // std::string | |
68 | ||
69 | #include <boost/test/detail/suppress_warnings.hpp> | |
70 | ||
71 | //____________________________________________________________________________// | |
72 | ||
73 | int test_main( int argc, char* argv[] ); // prototype for users test_main() | |
74 | ||
75 | namespace boost { | |
76 | namespace minimal_test { | |
77 | ||
78 | typedef boost::unit_test::const_string const_string; | |
79 | ||
80 | inline unit_test::counter_t& errors_counter() { static unit_test::counter_t ec = 0; return ec; } | |
81 | ||
82 | inline void | |
83 | report_error( const char* msg, const char* file, int line, const_string func_name, bool is_msg = false ) | |
84 | { | |
85 | ++errors_counter(); | |
86 | std::cerr << file << "(" << line << "): "; | |
87 | ||
88 | if( is_msg ) | |
89 | std::cerr << msg; | |
90 | else | |
91 | std::cerr << "test " << msg << " failed"; | |
92 | ||
93 | if( func_name != "(unknown)" ) | |
94 | std::cerr << " in function: '" << func_name << "'"; | |
95 | ||
96 | std::cerr << std::endl; | |
97 | } | |
98 | ||
99 | inline void | |
100 | report_critical_error( const char* msg, const char* file, int line, const_string func_name, bool is_msg = false ) | |
101 | { | |
102 | report_error( msg, file, line, func_name, is_msg ); | |
103 | ||
104 | throw boost::execution_aborted(); | |
105 | } | |
106 | ||
107 | class caller { | |
108 | public: | |
109 | // constructor | |
110 | caller( int argc, char** argv ) | |
111 | : m_argc( argc ), m_argv( argv ) {} | |
112 | ||
113 | // execution monitor hook implementation | |
114 | int operator()() { return test_main( m_argc, m_argv ); } | |
115 | ||
116 | private: | |
117 | // Data members | |
118 | int m_argc; | |
119 | char** m_argv; | |
120 | }; // monitor | |
121 | ||
122 | } // namespace minimal_test | |
123 | } // namespace boost | |
124 | ||
125 | //____________________________________________________________________________// | |
126 | ||
127 | int BOOST_TEST_CALL_DECL main( int argc, char* argv[] ) | |
128 | { | |
129 | using namespace boost::minimal_test; | |
130 | ||
131 | try { | |
132 | ::boost::execution_monitor ex_mon; | |
133 | int run_result = ex_mon.execute( caller( argc, argv ) ); | |
134 | ||
135 | BOOST_CHECK( run_result == 0 || run_result == boost::exit_success ); | |
136 | } | |
137 | catch( boost::execution_exception const& exex ) { | |
138 | if( exex.code() != boost::execution_exception::no_error ) | |
139 | BOOST_ERROR( (std::string( "exception \"" ) + exex.what() + "\" caught").c_str() ); | |
140 | std::cerr << "\n**** Testing aborted."; | |
141 | } | |
142 | ||
143 | if( boost::minimal_test::errors_counter() != 0 ) { | |
144 | std::cerr << "\n**** " << errors_counter() | |
145 | << " error" << (errors_counter() > 1 ? "s" : "" ) << " detected\n"; | |
146 | ||
147 | return boost::exit_test_failure; | |
148 | } | |
149 | ||
150 | std::cout << "\n**** no errors detected\n"; | |
151 | ||
152 | return boost::exit_success; | |
153 | } | |
154 | ||
155 | //____________________________________________________________________________// | |
156 | ||
157 | #include <boost/test/detail/enable_warnings.hpp> | |
158 | ||
159 | #endif // BOOST_TEST_MINIMAL_HPP_071894GER |