diff --git a/include/cucumber-cpp/internal/drivers/BoostDriver.hpp b/include/cucumber-cpp/internal/drivers/BoostDriver.hpp index e421bb9d..387a4427 100644 --- a/include/cucumber-cpp/internal/drivers/BoostDriver.hpp +++ b/include/cucumber-cpp/internal/drivers/BoostDriver.hpp @@ -13,7 +13,7 @@ class BoostStep : public BasicStep { const InvokeResult invokeStepBody(); private: - void initBoostTest(); + static void initBoostTest(); void runWithMasterSuite(); }; diff --git a/src/drivers/BoostDriver.cpp b/src/drivers/BoostDriver.cpp index ec74ab40..6e773c02 100644 --- a/src/drivers/BoostDriver.cpp +++ b/src/drivers/BoostDriver.cpp @@ -3,9 +3,11 @@ #include #include - +#include #include #include +#include +#include using namespace ::boost::unit_test; using ::boost::execution_exception; @@ -16,7 +18,20 @@ namespace internal { namespace { + test_case* testCase = 0; + boost::function currentTestBody; + + void exec_test_body() { + if (currentTestBody) { + currentTestBody(); + } + } + + bool boost_test_init() { + testCase = BOOST_TEST_CASE(&exec_test_body); + framework::master_test_suite().add(testCase); + return true; } @@ -39,14 +54,17 @@ class CukeBoostLogInterceptor : public ::boost::unit_test::unit_test_log_formatt void test_unit_finish( std::ostream&, test_unit const& tu, unsigned long elapsed) {}; void test_unit_skipped( std::ostream&, test_unit const& tu) {}; - void log_exception( std::ostream&, log_checkpoint_data const&, execution_exception const& ex) {}; + void log_exception_start( std::ostream&, log_checkpoint_data const&, execution_exception const&) {}; + void log_exception_finish( std::ostream& ) {}; void log_entry_start( std::ostream&, log_entry_data const&, log_entry_types let) {}; void log_entry_value( std::ostream&, const_string value); void log_entry_value( std::ostream&, lazy_ostream const& value) {}; void log_entry_finish( std::ostream&) {}; - void log_exception(std::ostream&, const boost::unit_test::log_checkpoint_data&, boost::unit_test::const_string) {}; + void entry_context_start( std::ostream&, log_level l ) {} + void log_entry_context( std::ostream&, const_string value ) {} + void entry_context_finish( std::ostream& ) {} private: std::stringstream description; @@ -73,29 +91,34 @@ const InvokeResult CukeBoostLogInterceptor::getResult() const { } const InvokeResult BoostStep::invokeStepBody() { - initBoostTest(); + static boost::once_flag initialized; + boost::call_once(initialized, BoostStep::initBoostTest); + logInterceptor->reset(); runWithMasterSuite(); return logInterceptor->getResult(); } void BoostStep::initBoostTest() { - if (!framework::is_initialized()) { - int argc = 2; - char *argv[] = { (char *) "", (char *) "" }; - framework::init(&boost_test_init, argc, argv); - logInterceptor = new CukeBoostLogInterceptor; - ::boost::unit_test::unit_test_log.set_formatter(logInterceptor); - ::boost::unit_test::unit_test_log.set_threshold_level(log_all_errors); - } + int argc = 1; + char dummyArg[] = "dummy"; + char *argv[] = { dummyArg }; + framework::init(&boost_test_init, argc, argv); +#if BOOST_VERSION >= 105900 + framework::finalize_setup_phase(); +#endif + + logInterceptor = new CukeBoostLogInterceptor; + ::boost::unit_test::unit_test_log.set_formatter(logInterceptor); + ::boost::unit_test::unit_test_log.set_threshold_level(log_all_errors); } void BoostStep::runWithMasterSuite() { - using namespace ::boost::unit_test; - test_case *tc = BOOST_TEST_CASE(boost::bind(&BoostStep::body, this)); - framework::master_test_suite().add(tc); - framework::run(tc, false); - framework::master_test_suite().remove(tc->p_id); + currentTestBody = boost::bind(&BoostStep::body, this); + + ::boost::unit_test::framework::run(testCase, false); + + currentTestBody.clear(); } } diff --git a/tests/integration/drivers/BoostDriverTest.cpp b/tests/integration/drivers/BoostDriverTest.cpp index d48d817c..7c8b85da 100644 --- a/tests/integration/drivers/BoostDriverTest.cpp +++ b/tests/integration/drivers/BoostDriverTest.cpp @@ -1,4 +1,7 @@ +#include + #include + #include #include "../../utils/DriverTestRunner.hpp" @@ -25,6 +28,18 @@ THEN(PENDING_MATCHER_2) { using namespace cucumber::internal; +#if BOOST_VERSION >= 105900 +namespace boost { + namespace unit_test { + namespace framework { + bool is_initialized() { + return boost::unit_test::framework::master_test_suite().argc > 0; + } + } + } +} +#endif + class BoostStepDouble : public BoostStep { public: const InvokeResult invokeStepBody() { @@ -47,7 +62,7 @@ class BoostDriverTest : public DriverTest { using namespace boost::unit_test; BoostStepDouble step; expectFalse("Framework is not initialized before the first test", framework::is_initialized()); - step.invokeStepBody(); + step.invokeStepBody(); expectTrue("Framework is initialized after the first test", framework::is_initialized()); } };