Skip to content

Commit 28ce2f6

Browse files
committed
Added support for boost 1.59 and 1.60
Adapted code to API changes in boost 1.59 and 1.60: - Register global test case during initialization only (adding test case later does not work any longer) and exchange step body function dynamically instead. - Replacement for removed boost::test::unit_test::framework::is_initialized()
1 parent 1e633c6 commit 28ce2f6

File tree

3 files changed

+57
-19
lines changed

3 files changed

+57
-19
lines changed

include/cucumber-cpp/internal/drivers/BoostDriver.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class BoostStep : public BasicStep {
1313
const InvokeResult invokeStepBody();
1414

1515
private:
16-
void initBoostTest();
16+
static void initBoostTest();
1717
void runWithMasterSuite();
1818
};
1919

src/drivers/BoostDriver.cpp

+40-17
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
#include <sstream>
44

55
#include <boost/bind.hpp>
6-
6+
#include <boost/function.hpp>
77
#include <boost/test/unit_test.hpp>
88
#include <boost/test/unit_test_log_formatter.hpp>
9+
#include <boost/thread/once.hpp>
10+
#include <boost/version.hpp>
911

1012
using namespace ::boost::unit_test;
1113
using ::boost::execution_exception;
@@ -16,7 +18,20 @@ namespace internal {
1618

1719
namespace {
1820

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+
1931
bool boost_test_init() {
32+
testCase = BOOST_TEST_CASE(&exec_test_body);
33+
framework::master_test_suite().add(testCase);
34+
2035
return true;
2136
}
2237

@@ -39,14 +54,17 @@ class CukeBoostLogInterceptor : public ::boost::unit_test::unit_test_log_formatt
3954
void test_unit_finish( std::ostream&, test_unit const& tu, unsigned long elapsed) {};
4055
void test_unit_skipped( std::ostream&, test_unit const& tu) {};
4156

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& ) {};
4359

4460
void log_entry_start( std::ostream&, log_entry_data const&, log_entry_types let) {};
4561
void log_entry_value( std::ostream&, const_string value);
4662
void log_entry_value( std::ostream&, lazy_ostream const& value) {};
4763
void log_entry_finish( std::ostream&) {};
4864

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& ) {}
5068

5169
private:
5270
std::stringstream description;
@@ -73,29 +91,34 @@ const InvokeResult CukeBoostLogInterceptor::getResult() const {
7391
}
7492

7593
const InvokeResult BoostStep::invokeStepBody() {
76-
initBoostTest();
94+
static boost::once_flag initialized;
95+
boost::call_once(initialized, BoostStep::initBoostTest);
96+
7797
logInterceptor->reset();
7898
runWithMasterSuite();
7999
return logInterceptor->getResult();
80100
}
81101

82102
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);
91114
}
92115

93116
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();
99122
}
100123

101124
}

tests/integration/drivers/BoostDriverTest.cpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
#include <boost/version.hpp>
2+
13
#include <boost/test/unit_test.hpp>
4+
25
#include <cucumber-cpp/defs.hpp>
36

47
#include "../../utils/DriverTestRunner.hpp"
@@ -25,6 +28,18 @@ THEN(PENDING_MATCHER_2) {
2528

2629
using namespace cucumber::internal;
2730

31+
#if BOOST_VERSION >= 105900
32+
namespace boost {
33+
namespace unit_test {
34+
namespace framework {
35+
bool is_initialized() {
36+
return boost::unit_test::framework::master_test_suite().argc > 0;
37+
}
38+
}
39+
}
40+
}
41+
#endif
42+
2843
class BoostStepDouble : public BoostStep {
2944
public:
3045
const InvokeResult invokeStepBody() {
@@ -47,7 +62,7 @@ class BoostDriverTest : public DriverTest {
4762
using namespace boost::unit_test;
4863
BoostStepDouble step;
4964
expectFalse("Framework is not initialized before the first test", framework::is_initialized());
50-
step.invokeStepBody();
65+
step.invokeStepBody();
5166
expectTrue("Framework is initialized after the first test", framework::is_initialized());
5267
}
5368
};

0 commit comments

Comments
 (0)