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 #define BOOST_CHECK(exp) \
36 ? static_cast<void>(0) \
37 : boost::minimal_test::report_error(#exp,__FILE__,__LINE__, BOOST_CURRENT_FUNCTION) )
39 #define BOOST_REQUIRE(exp) \
41 ? static_cast<void>(0) \
42 : boost::minimal_test::report_critical_error(#exp,__FILE__,__LINE__,BOOST_CURRENT_FUNCTION))
44 #define BOOST_ERROR( msg_ ) \
45 boost::minimal_test::report_error( (msg_),__FILE__,__LINE__, BOOST_CURRENT_FUNCTION, true )
46 #define BOOST_FAIL( msg_ ) \
47 boost::minimal_test::report_critical_error( (msg_),__FILE__,__LINE__, BOOST_CURRENT_FUNCTION, true )
49 //____________________________________________________________________________//
52 #include <boost/test/detail/global_typedef.hpp>
53 #include <boost/test/impl/execution_monitor.ipp>
54 #include <boost/test/impl/debug.ipp>
55 #include <boost/test/utils/class_properties.hpp>
56 #include <boost/test/utils/basic_cstring/io.hpp>
59 #include <boost/cstdlib.hpp> // for exit codes
60 #include <boost/current_function.hpp> // for BOOST_CURRENT_FUNCTION
63 #include <iostream> // std::cerr, std::endl
64 #include <string> // std::string
66 #include <boost/test/detail/suppress_warnings.hpp>
68 //____________________________________________________________________________//
70 int test_main( int argc, char* argv[] ); // prototype for users test_main()
73 namespace minimal_test {
75 typedef boost::unit_test::const_string const_string;
77 inline unit_test::counter_t& errors_counter() { static unit_test::counter_t ec = 0; return ec; }
80 report_error( const char* msg, const char* file, int line, const_string func_name, bool is_msg = false )
83 std::cerr << file << "(" << line << "): ";
88 std::cerr << "test " << msg << " failed";
90 if( func_name != "(unknown)" )
91 std::cerr << " in function: '" << func_name << "'";
93 std::cerr << std::endl;
97 report_critical_error( const char* msg, const char* file, int line, const_string func_name, bool is_msg = false )
99 report_error( msg, file, line, func_name, is_msg );
101 throw boost::execution_aborted();
107 caller( int argc, char** argv )
108 : m_argc( argc ), m_argv( argv ) {}
110 // execution monitor hook implementation
111 int operator()() { return test_main( m_argc, m_argv ); }
119 } // namespace minimal_test
122 //____________________________________________________________________________//
124 int BOOST_TEST_CALL_DECL main( int argc, char* argv[] )
126 using namespace boost::minimal_test;
129 ::boost::execution_monitor ex_mon;
130 int run_result = ex_mon.execute( caller( argc, argv ) );
132 BOOST_CHECK( run_result == 0 || run_result == boost::exit_success );
134 catch( boost::execution_exception const& exex ) {
135 if( exex.code() != boost::execution_exception::no_error )
136 BOOST_ERROR( (std::string( "exception \"" ) + exex.what() + "\" caught").c_str() );
137 std::cerr << "\n**** Testing aborted.";
140 if( boost::minimal_test::errors_counter() != 0 ) {
141 std::cerr << "\n**** " << errors_counter()
142 << " error" << (errors_counter() > 1 ? "s" : "" ) << " detected\n";
144 return boost::exit_test_failure;
147 std::cout << "\n**** no errors detected\n";
149 return boost::exit_success;
152 //____________________________________________________________________________//
154 #include <boost/test/detail/enable_warnings.hpp>
156 #endif // BOOST_TEST_MINIMAL_HPP_071894GER