3
3
#include < sstream>
4
4
5
5
#include < boost/bind.hpp>
6
-
6
+ # include < boost/function.hpp >
7
7
#include < boost/test/unit_test.hpp>
8
8
#include < boost/test/unit_test_log_formatter.hpp>
9
+ #include < boost/thread/once.hpp>
10
+ #include < boost/version.hpp>
9
11
10
12
using namespace ::boost::unit_test;
11
13
using ::boost::execution_exception;
@@ -16,7 +18,20 @@ namespace internal {
16
18
17
19
namespace {
18
20
21
+ test_case* testCase = 0 ;
22
+ boost::function<void ()> currentTestBody;
23
+
24
+ void exec_test_body () {
25
+ if (currentTestBody) {
26
+ currentTestBody ();
27
+ }
28
+ }
29
+
30
+
19
31
bool boost_test_init () {
32
+ testCase = BOOST_TEST_CASE (&exec_test_body);
33
+ framework::master_test_suite ().add (testCase);
34
+
20
35
return true ;
21
36
}
22
37
@@ -39,14 +54,17 @@ class CukeBoostLogInterceptor : public ::boost::unit_test::unit_test_log_formatt
39
54
void test_unit_finish ( std::ostream&, test_unit const & tu, unsigned long elapsed) {};
40
55
void test_unit_skipped ( std::ostream&, test_unit const & tu) {};
41
56
42
- void log_exception ( std::ostream&, log_checkpoint_data const &, execution_exception const & ex) {};
57
+ void log_exception_start ( std::ostream&, log_checkpoint_data const &, execution_exception const &) {};
58
+ void log_exception_finish ( std::ostream& ) {};
43
59
44
60
void log_entry_start ( std::ostream&, log_entry_data const &, log_entry_types let) {};
45
61
void log_entry_value ( std::ostream&, const_string value);
46
62
void log_entry_value ( std::ostream&, lazy_ostream const & value) {};
47
63
void log_entry_finish ( std::ostream&) {};
48
64
49
- void log_exception (std::ostream&, const boost::unit_test::log_checkpoint_data&, boost::unit_test::const_string) {};
65
+ void entry_context_start ( std::ostream&, log_level l ) {}
66
+ void log_entry_context ( std::ostream&, const_string value ) {}
67
+ void entry_context_finish ( std::ostream& ) {}
50
68
51
69
private:
52
70
std::stringstream description;
@@ -73,29 +91,34 @@ const InvokeResult CukeBoostLogInterceptor::getResult() const {
73
91
}
74
92
75
93
const InvokeResult BoostStep::invokeStepBody () {
76
- initBoostTest ();
94
+ static boost::once_flag initialized;
95
+ boost::call_once (initialized, BoostStep::initBoostTest);
96
+
77
97
logInterceptor->reset ();
78
98
runWithMasterSuite ();
79
99
return logInterceptor->getResult ();
80
100
}
81
101
82
102
void BoostStep::initBoostTest () {
83
- if (!framework::is_initialized ()) {
84
- int argc = 2 ;
85
- char *argv[] = { (char *) " " , (char *) " " };
86
- framework::init (&boost_test_init, argc, argv);
87
- logInterceptor = new CukeBoostLogInterceptor;
88
- ::boost::unit_test::unit_test_log.set_formatter (logInterceptor);
89
- ::boost::unit_test::unit_test_log.set_threshold_level (log_all_errors);
90
- }
103
+ int argc = 1 ;
104
+ char dummyArg[] = " dummy" ;
105
+ char *argv[] = { dummyArg };
106
+ framework::init (&boost_test_init, argc, argv);
107
+ #if BOOST_VERSION >= 105900
108
+ framework::finalize_setup_phase ();
109
+ #endif
110
+
111
+ logInterceptor = new CukeBoostLogInterceptor;
112
+ ::boost::unit_test::unit_test_log.set_formatter (logInterceptor);
113
+ ::boost::unit_test::unit_test_log.set_threshold_level (log_all_errors);
91
114
}
92
115
93
116
void BoostStep::runWithMasterSuite () {
94
- using namespace ::boost::unit_test ;
95
- test_case *tc = BOOST_TEST_CASE ( boost::bind (&BoostStep::body, this ));
96
- framework::master_test_suite (). add (tc );
97
- framework::run (tc, false );
98
- framework::master_test_suite (). remove (tc-> p_id );
117
+ currentTestBody = boost::bind (&BoostStep::body, this ) ;
118
+
119
+ ::boost::unit_test:: framework::run (testCase, false );
120
+
121
+ currentTestBody. clear ( );
99
122
}
100
123
101
124
}
0 commit comments