1 | // (C) Copyright Gennadiy Rozental 2001-2005. |
---|
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) |
---|
6 | |
---|
7 | // See http://www.boost.org/libs/test for the library home page. |
---|
8 | // |
---|
9 | // File : $RCSfile: cpp_main.ipp,v $ |
---|
10 | // |
---|
11 | // Version : $Revision: 1.5 $ |
---|
12 | // |
---|
13 | // Description : main function implementation for Program Executon Monitor |
---|
14 | // *************************************************************************** |
---|
15 | |
---|
16 | #ifndef BOOST_TEST_CPP_MAIN_IPP_012205GER |
---|
17 | #define BOOST_TEST_CPP_MAIN_IPP_012205GER |
---|
18 | |
---|
19 | // Boost.Test |
---|
20 | #include <boost/test/execution_monitor.hpp> |
---|
21 | #include <boost/test/detail/config.hpp> |
---|
22 | #include <boost/test/utils/basic_cstring/io.hpp> |
---|
23 | |
---|
24 | // Boost |
---|
25 | #include <boost/cstdlib.hpp> // for exit codes |
---|
26 | #include <boost/config.hpp> // for workarounds |
---|
27 | |
---|
28 | // STL |
---|
29 | #include <iostream> |
---|
30 | #include <cstdlib> // std::getenv |
---|
31 | |
---|
32 | #include <boost/test/detail/suppress_warnings.hpp> |
---|
33 | |
---|
34 | #include <boost/test/detail/suppress_warnings.hpp> |
---|
35 | |
---|
36 | //____________________________________________________________________________// |
---|
37 | |
---|
38 | #ifdef BOOST_NO_STDC_NAMESPACE |
---|
39 | namespace std { using ::getenv; } |
---|
40 | #endif |
---|
41 | |
---|
42 | int cpp_main( int argc, char* argv[] ); // prototype for user's cpp_main() |
---|
43 | |
---|
44 | namespace { |
---|
45 | |
---|
46 | struct cpp_main_caller { |
---|
47 | cpp_main_caller( int argc, char** argv ) : m_argc( argc ), m_argv( argv ) {} |
---|
48 | |
---|
49 | int operator()() { return cpp_main( m_argc, m_argv ); } |
---|
50 | |
---|
51 | private: |
---|
52 | // Data members |
---|
53 | int m_argc; |
---|
54 | char** m_argv; |
---|
55 | }; |
---|
56 | |
---|
57 | } // local namespace |
---|
58 | |
---|
59 | // ************************************************************************** // |
---|
60 | // ************** cpp main ************** // |
---|
61 | // ************************************************************************** // |
---|
62 | |
---|
63 | int BOOST_TEST_CALL_DECL main( int argc, char* argv[] ) |
---|
64 | { |
---|
65 | int result; |
---|
66 | |
---|
67 | boost::unit_test::const_string p( std::getenv( "BOOST_TEST_CATCH_SYSTEM_ERRORS" ) ); |
---|
68 | bool catch_system_errors = p != "no"; |
---|
69 | |
---|
70 | try { |
---|
71 | ::boost::execution_monitor ex_mon; |
---|
72 | result = ex_mon.execute( ::boost::unit_test::callback0<int>( cpp_main_caller( argc, argv ) ), catch_system_errors ); |
---|
73 | |
---|
74 | if( result == 0 ) |
---|
75 | result = ::boost::exit_success; |
---|
76 | else if( result != ::boost::exit_success ) { |
---|
77 | std::cout << "\n**** error return code: " << result << std::endl; |
---|
78 | result = ::boost::exit_failure; |
---|
79 | } |
---|
80 | } |
---|
81 | catch( ::boost::execution_exception const& exex ) { |
---|
82 | std::cout << "\n**** exception(" << exex.code() << "): " << exex.what() << std::endl; |
---|
83 | result = ::boost::exit_exception_failure; |
---|
84 | } |
---|
85 | |
---|
86 | if( result != ::boost::exit_success ) { |
---|
87 | std::cerr << "******** errors detected; see standard output for details ********" << std::endl; |
---|
88 | } |
---|
89 | else { |
---|
90 | // Some prefer a confirming message when all is well, while others don't |
---|
91 | // like the clutter. Use an environment variable to avoid command |
---|
92 | // line argument modifications; for use in production programs |
---|
93 | // that's a no-no in some organizations. |
---|
94 | ::boost::unit_test::const_string p( std::getenv( "BOOST_PRG_MON_CONFIRM" ) ); |
---|
95 | if( p != "no" ) { |
---|
96 | std::cerr << std::flush << "no errors detected" << std::endl; |
---|
97 | } |
---|
98 | } |
---|
99 | |
---|
100 | return result; |
---|
101 | } |
---|
102 | |
---|
103 | //____________________________________________________________________________// |
---|
104 | |
---|
105 | #include <boost/test/detail/enable_warnings.hpp> |
---|
106 | |
---|
107 | // *************************************************************************** |
---|
108 | // Revision History : |
---|
109 | // |
---|
110 | // $Log: cpp_main.ipp,v $ |
---|
111 | // Revision 1.5 2005/02/20 08:27:07 rogeeff |
---|
112 | // This a major update for Boost.Test framework. See release docs for complete list of fixes/updates |
---|
113 | // |
---|
114 | // Revision 1.4 2005/02/01 06:40:07 rogeeff |
---|
115 | // copyright update |
---|
116 | // old log entries removed |
---|
117 | // minor stilistic changes |
---|
118 | // depricated tools removed |
---|
119 | // |
---|
120 | // Revision 1.3 2005/01/31 07:50:06 rogeeff |
---|
121 | // cdecl portability fix |
---|
122 | // |
---|
123 | // Revision 1.2 2005/01/31 06:01:50 rogeeff |
---|
124 | // BOOST_TEST_CALL_DECL correctness fixes |
---|
125 | // |
---|
126 | // Revision 1.1 2005/01/22 19:22:12 rogeeff |
---|
127 | // implementation moved into headers section to eliminate dependency of included/minimal component on src directory |
---|
128 | // |
---|
129 | // *************************************************************************** |
---|
130 | |
---|
131 | #endif // BOOST_TEST_CPP_MAIN_IPP_012205GER |
---|