fix doc example typo
[boost.git] / boost / test / minimal.hpp
blob7d32150560077a4b02d40c91cc1b9c204f354cbe
1 // (C) Copyright Gennadiy Rozental 2002-2008.
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.
7 //
8 // File : $RCSfile$
9 //
10 // Version : $Revision$
12 // Description : simple minimal testing definitions and implementation
13 // ***************************************************************************
15 #ifndef BOOST_TEST_MINIMAL_HPP_071894GER
16 #define BOOST_TEST_MINIMAL_HPP_071894GER
18 #define BOOST_CHECK(exp) \
19 ( (exp) \
20 ? static_cast<void>(0) \
21 : boost::minimal_test::report_error(#exp,__FILE__,__LINE__, BOOST_CURRENT_FUNCTION) )
23 #define BOOST_REQUIRE(exp) \
24 ( (exp) \
25 ? static_cast<void>(0) \
26 : boost::minimal_test::report_critical_error(#exp,__FILE__,__LINE__,BOOST_CURRENT_FUNCTION))
28 #define BOOST_ERROR( msg_ ) \
29 boost::minimal_test::report_error( (msg_),__FILE__,__LINE__, BOOST_CURRENT_FUNCTION, true )
30 #define BOOST_FAIL( msg_ ) \
31 boost::minimal_test::report_critical_error( (msg_),__FILE__,__LINE__, BOOST_CURRENT_FUNCTION, true )
33 //____________________________________________________________________________//
35 // Boost.Test
36 #include <boost/test/detail/global_typedef.hpp>
37 #include <boost/test/impl/execution_monitor.ipp>
38 #include <boost/test/impl/debug.ipp>
39 #include <boost/test/utils/class_properties.hpp>
40 #include <boost/test/utils/basic_cstring/io.hpp>
42 // Boost
43 #include <boost/cstdlib.hpp> // for exit codes#include <boost/cstdlib.hpp> // for exit codes
44 #include <boost/current_function.hpp> // for BOOST_CURRENT_FUNCTION
46 // STL
47 #include <iostream> // std::cerr, std::endl
48 #include <string> // std::string
50 #include <boost/test/detail/suppress_warnings.hpp>
52 //____________________________________________________________________________//
54 int test_main( int argc, char* argv[] ); // prototype for users test_main()
56 namespace boost {
57 namespace minimal_test {
59 typedef boost::unit_test::const_string const_string;
61 inline unit_test::counter_t& errors_counter() { static unit_test::counter_t ec = 0; return ec; }
63 inline void
64 report_error( const char* msg, const char* file, int line, const_string func_name, bool is_msg = false )
66 ++errors_counter();
67 std::cerr << file << "(" << line << "): ";
69 if( is_msg )
70 std::cerr << msg;
71 else
72 std::cerr << "test " << msg << " failed";
74 if( func_name != "(unknown)" )
75 std::cerr << " in function: '" << func_name << "'";
77 std::cerr << std::endl;
80 inline void
81 report_critical_error( const char* msg, const char* file, int line, const_string func_name, bool is_msg = false )
83 report_error( msg, file, line, func_name, is_msg );
85 throw boost::execution_aborted();
88 class caller {
89 public:
90 // constructor
91 caller( int argc, char** argv )
92 : m_argc( argc ), m_argv( argv ) {}
94 // execution monitor hook implementation
95 int operator()() { return test_main( m_argc, m_argv ); }
97 private:
98 // Data members
99 int m_argc;
100 char** m_argv;
101 }; // monitor
103 } // namespace minimal_test
105 } // namespace boost
107 //____________________________________________________________________________//
109 int BOOST_TEST_CALL_DECL main( int argc, char* argv[] )
111 using namespace boost::minimal_test;
113 try {
114 ::boost::execution_monitor ex_mon;
115 int run_result = ex_mon.execute( caller( argc, argv ) );
117 BOOST_CHECK( run_result == 0 || run_result == boost::exit_success );
119 catch( boost::execution_exception const& exex ) {
120 if( exex.code() != boost::execution_exception::no_error )
121 BOOST_ERROR( (std::string( "exception \"" ).
122 append( exex.what().begin(), exex.what().end() ).
123 append( "\" caught" ) ).c_str() );
124 std::cerr << "\n**** Testing aborted.";
127 if( boost::minimal_test::errors_counter() != 0 ) {
128 std::cerr << "\n**** " << errors_counter()
129 << " error" << (errors_counter() > 1 ? "s" : "" ) << " detected\n";
131 return boost::exit_test_failure;
134 std::cout << "\n**** no errors detected\n";
136 return boost::exit_success;
139 //____________________________________________________________________________//
141 #include <boost/test/detail/enable_warnings.hpp>
143 #endif // BOOST_TEST_MINIMAL_HPP_071894GER