Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/cucumber-cpp/internal/drivers/BoostDriver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class BoostStep : public BasicStep {
const InvokeResult invokeStepBody();

private:
void initBoostTest();
static void initBoostTest();
void runWithMasterSuite();
};

Expand Down
57 changes: 40 additions & 17 deletions src/drivers/BoostDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
#include <sstream>

#include <boost/bind.hpp>

#include <boost/function.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/test/unit_test_log_formatter.hpp>
#include <boost/thread/once.hpp>
#include <boost/version.hpp>

using namespace ::boost::unit_test;
using ::boost::execution_exception;
Expand All @@ -16,7 +18,20 @@ namespace internal {

namespace {

test_case* testCase = 0;
boost::function<void()> 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;
}

Expand All @@ -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;
Expand All @@ -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();
}

}
Expand Down
17 changes: 16 additions & 1 deletion tests/integration/drivers/BoostDriverTest.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#include <boost/version.hpp>

#include <boost/test/unit_test.hpp>

#include <cucumber-cpp/defs.hpp>

#include "../../utils/DriverTestRunner.hpp"
Expand All @@ -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() {
Expand All @@ -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());
}
};
Expand Down