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)
6 // See http://www.boost.org/libs/test for the library home page.
9 /// @brief Deprecated implementation of simple minimal testing
11 /// To convert to Unit Test Framework simply rewrite:
13 /// #include <boost/test/minimal.hpp>
15 /// int test_main( int, char *[] )
22 /// #include <boost/test/included/unit_test.hpp>
24 /// BOOST_AUTO_TEST_CASE(test_main)
29 // ***************************************************************************
31 #ifndef BOOST_TEST_MINIMAL_HPP_071894GER
32 #define BOOST_TEST_MINIMAL_HPP_071894GER
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." )
40 #define BOOST_CHECK(exp) \
42 ? static_cast<void>(0) \
43 : boost::minimal_test::report_error(#exp,__FILE__,__LINE__, BOOST_CURRENT_FUNCTION) )
45 #define BOOST_REQUIRE(exp) \
47 ? static_cast<void>(0) \
48 : boost::minimal_test::report_critical_error(#exp,__FILE__,__LINE__,BOOST_CURRENT_FUNCTION))
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 )
55 //____________________________________________________________________________//
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>
65 #include <boost/cstdlib.hpp> // for exit codes
66 #include <boost/current_function.hpp> // for BOOST_CURRENT_FUNCTION
69 #include <iostream> // std::cerr, std::endl
70 #include <string> // std::string
72 #include <boost/test/detail/suppress_warnings.hpp>
74 //____________________________________________________________________________//
76 int test_main( int argc, char* argv[] ); // prototype for users test_main()
79 namespace minimal_test {
81 typedef boost::unit_test::const_string const_string;
83 inline unit_test::counter_t& errors_counter() { static unit_test::counter_t ec = 0; return ec; }
86 report_error( const char* msg, const char* file, int line, const_string func_name, bool is_msg = false )
89 std::cerr << file << "(" << line << "): ";
94 std::cerr << "test " << msg << " failed";
96 if( func_name != "(unknown)" )
97 std::cerr << " in function: '" << func_name << "'";
99 std::cerr << std::endl;
103 report_critical_error( const char* msg, const char* file, int line, const_string func_name, bool is_msg = false )
105 report_error( msg, file, line, func_name, is_msg );
107 throw boost::execution_aborted();
113 caller( int argc, char** argv )
114 : m_argc( argc ), m_argv( argv ) {}
116 // execution monitor hook implementation
117 int operator()() { return test_main( m_argc, m_argv ); }
125 } // namespace minimal_test
128 //____________________________________________________________________________//
130 int BOOST_TEST_CALL_DECL main( int argc, char* argv[] )
132 using namespace boost::minimal_test;
135 ::boost::execution_monitor ex_mon;
136 int run_result = ex_mon.execute( caller( argc, argv ) );
138 BOOST_CHECK( run_result == 0 || run_result == boost::exit_success );
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.";
146 if( boost::minimal_test::errors_counter() != 0 ) {
147 std::cerr << "\n**** " << errors_counter()
148 << " error" << (errors_counter() > 1 ? "s" : "" ) << " detected\n";
150 return boost::exit_test_failure;
153 std::cout << "\n**** no errors detected\n";
155 return boost::exit_success;
158 //____________________________________________________________________________//
160 #include <boost/test/detail/enable_warnings.hpp>
162 #endif // BOOST_TEST_MINIMAL_HPP_071894GER