1
// (C) Copyright Gennadiy Rozental 2001-2008.
2
// (C) Copyright Beman Dawes 1995-2001.
3
// Distributed under the Boost Software License, Version 1.0.
4
// (See accompanying file LICENSE_1_0.txt or copy at
5
// http://www.boost.org/LICENSE_1_0.txt)
7
// See http://www.boost.org/libs/test for the library home page.
11
// Version : $Revision: 49312 $
13
// Description : main function implementation for Program Executon Monitor
14
// ***************************************************************************
16
#ifndef BOOST_TEST_CPP_MAIN_IPP_012205GER
17
#define BOOST_TEST_CPP_MAIN_IPP_012205GER
20
#include <boost/test/execution_monitor.hpp>
21
#include <boost/test/detail/config.hpp>
22
#include <boost/test/utils/basic_cstring/io.hpp>
25
#include <boost/cstdlib.hpp> // for exit codes
26
#include <boost/config.hpp> // for workarounds
30
#include <cstdlib> // std::getenv
31
#include <cstring> // std::strerror
33
#include <boost/test/detail/suppress_warnings.hpp>
35
//____________________________________________________________________________//
37
#ifdef BOOST_NO_STDC_NAMESPACE
38
namespace std { using ::getenv; using ::strerror; }
43
struct cpp_main_caller {
44
cpp_main_caller( int (*cpp_main_func)( int argc, char* argv[] ), int argc, char** argv )
45
: m_cpp_main_func( cpp_main_func )
49
int operator()() { return (*m_cpp_main_func)( m_argc, m_argv ); }
53
int (*m_cpp_main_func)( int argc, char* argv[] );
60
// ************************************************************************** //
61
// ************** prg_exec_monitor_main ************** //
62
// ************************************************************************** //
67
prg_exec_monitor_main( int (*cpp_main)( int argc, char* argv[] ), int argc, char* argv[] )
72
boost::unit_test::const_string p( std::getenv( "BOOST_TEST_CATCH_SYSTEM_ERRORS" ) );
73
::boost::execution_monitor ex_mon;
75
ex_mon.p_catch_system_errors.value = p != "no";
77
result = ex_mon.execute(
78
::boost::unit_test::callback0<int>( cpp_main_caller( cpp_main, argc, argv ) ) );
81
result = ::boost::exit_success;
82
else if( result != ::boost::exit_success ) {
83
std::cout << "\n**** error return code: " << result << std::endl;
84
result = ::boost::exit_failure;
87
catch( ::boost::execution_exception const& exex ) {
88
std::cout << "\n**** exception(" << exex.code() << "): " << exex.what() << std::endl;
89
result = ::boost::exit_exception_failure;
91
catch( ::boost::system_error const& ex ) {
92
std::cout << "\n**** failed to initialize execution monitor."
93
<< "\n**** expression at fault: " << ex.p_failed_exp
94
<< "\n**** error(" << ex.p_errno << "): " << std::strerror( ex.p_errno ) << std::endl;
95
result = ::boost::exit_exception_failure;
98
if( result != ::boost::exit_success ) {
99
std::cerr << "******** errors detected; see standard output for details ********" << std::endl;
102
// Some prefer a confirming message when all is well, while others don't
103
// like the clutter. Use an environment variable to avoid command
104
// line argument modifications; for use in production programs
105
// that's a no-no in some organizations.
106
::boost::unit_test::const_string p( std::getenv( "BOOST_PRG_MON_CONFIRM" ) );
108
std::cerr << std::flush << "no errors detected" << std::endl;
117
#if !defined(BOOST_TEST_DYN_LINK) && !defined(BOOST_TEST_NO_MAIN)
119
// ************************************************************************** //
120
// ************** main function for tests using lib ************** //
121
// ************************************************************************** //
123
int cpp_main( int argc, char* argv[] ); // prototype for user's cpp_main()
125
int BOOST_TEST_CALL_DECL
126
main( int argc, char* argv[] )
128
return ::boost::prg_exec_monitor_main( &cpp_main, argc, argv );
131
//____________________________________________________________________________//
133
#endif // !BOOST_TEST_DYN_LINK && !BOOST_TEST_NO_MAIN
135
//____________________________________________________________________________//
137
#include <boost/test/detail/enable_warnings.hpp>
139
#endif // BOOST_TEST_CPP_MAIN_IPP_012205GER