Skip to content

Commit

Permalink
Merge cucumber#164 'Intercept messages from BOOST_*_MESSAGE macros'
Browse files Browse the repository at this point in the history
  • Loading branch information
konserw committed Oct 12, 2017
2 parents ffba658 + d9a8f3c commit 9fe2e73
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Please see [CONTRIBUTING.md](https://github.com/cucumber/cucumber/blob/master/CO

### Fixed

* Fix issue #81 by intercepting messages from BOOST_*_MESSAGE macros ([#164](https://github.com/cucumber/cucumber-cpp/pull/164) Kamil Strzempowicz)
* Allow running all GTest cases without filter separation ([#144](https://github.com/cucumber/cucumber-cpp/pull/144) Giel van Schijndel)
* Fix QNX build by depending on standard C++ instead of specific implementation ([#156](https://github.com/cucumber/cucumber-cpp/issues/156) Giel van Schijndel)
* Ensure CMake 3.1+ is available, 2.8.12 wasn't enough for quite a while ([#152](https://github.com/cucumber/cucumber-cpp/pull/152) Giel van Schijndel)
Expand Down
15 changes: 11 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,13 @@ else()
add_executable(e2e-steps EXCLUDE_FROM_ALL ${CUKE_DYNAMIC_CPP_STEPS})
# Mark this file as generated so it isn't required at CMake generation time (it is necessary when the target gets built though)
set_source_files_properties(${CUKE_DYNAMIC_CPP_STEPS} PROPERTIES GENERATED TRUE)
target_link_libraries(e2e-steps ${CUKE_LIBRARIES})
target_link_libraries(e2e-steps PRIVATE ${CUKE_LIBRARIES})
#Boost test lib required for boost specific scenario "Predicate Message"
if(Boost_UNIT_TEST_FRAMEWORK_FOUND)
target_link_libraries(e2e-steps PRIVATE ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
else()
set(CUKE_E2E_TAGS "--tags ~@boost")
endif()

set(CUKE_COMPILE_DYNAMIC_CPP_STEPS '"${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --target e2e-steps')

Expand All @@ -242,16 +248,17 @@ else()
COMPILE_DYNAMIC_CPP_STEPS=${CUKE_COMPILE_DYNAMIC_CPP_STEPS}
CUCUMBER_RUBY=${CUCUMBER_RUBY}
--format=junit "--out=${CMAKE_BINARY_DIR}/features"
${CUKE_E2E_TAGS}
${ARGN}
${CUKE_FEATURES_DIR}
DEPENDS cucumber-cpp
${USES_TERMINAL}
)
endfunction(add_feature_target)

add_feature_target(features --format progress)
add_feature_target(features-pretty --format pretty)
add_feature_target(features-wip --format pretty --tags @wip)
add_feature_target(features --format progress)
add_feature_target(features-pretty --format pretty)
add_feature_target(features-wip --format pretty --tags @wip)

else()
message(WARNING "Could not find Cucumber: skipping end-to-end tests")
Expand Down
34 changes: 34 additions & 0 deletions features/specific/boost_specific.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
@boost
Feature: Check macros used with boost test driver

This is just a simple feature meant to test boost's
specyfic validation macros interop with cucumber.

Scenario Outline: <check> macro
Given the following feature:
"""
Feature: Feature name
Scenario: Scenario name
Given a step
"""
And a step definition file with:
"""
#include <boost/test/unit_test.hpp>
#include <cucumber-cpp/autodetect.hpp>
GIVEN("a step") {
<check>;
}
"""
When Cucumber runs the feature
Then the scenario <passes or fails?>

Examples:
| check | passes or fails? |
| BOOST_CHECK(false) | fails |
| BOOST_CHECK_MESSAGE(false, "boost message") | fails with message "boost message" |
| BOOST_ERROR("boost message") | fails with message "boost message" |
| BOOST_FAIL("boost message") | fails with message "boost message" |
| BOOST_REQUIRE(false) | fails |
| BOOST_REQUIRE_MESSAGE(false, "boost message") | fails with message "boost message" |
| BOOST_WARN(false) | passes |
| BOOST_WARN_MESSAGE(false, "boost message") | passes |
2 changes: 1 addition & 1 deletion features/specific/simple.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Feature: Simple Feature
Scenario: Scenario name
Given a step
"""
And a step definition file with:
And a step definition file with support code including:
"""
#include <iostream>
Expand Down
4 changes: 4 additions & 0 deletions features/step_definitions/cucumber_cpp_mappings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ def append_step_definition(step_name, code) # todo params parameter?
EOF
end

def set_code(code)
@support_code = code
end

def append_support_code(code)
helper_functions = get_absolute_path('../support/HelperFunctions.hpp');
@support_code ||= <<-EOF
Expand Down
10 changes: 10 additions & 0 deletions features/step_definitions/cucumber_cpp_steps.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
Given /^a step definition file with:$/ do |code|
set_code code
end

Given /^a step definition file with support code including:$/ do |code|
append_support_code code
end

Expand All @@ -9,3 +13,9 @@
Then /^a step definition snippet with (".*") is suggested$/ do |regex_string|
assert_partial_output("(#{regex_string}) {", all_output)
end

Then /^the scenario fails with message "([^"]*)"$/ do |message|
assert_partial_output(message, all_output)
assert_success false
end

10 changes: 7 additions & 3 deletions src/drivers/BoostDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ class CukeBoostLogInterceptor : public ::boost::unit_test::unit_test_log_formatt
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_value( std::ostream&, const_string value);
void log_entry_value( std::ostream&, lazy_ostream const& value);
void log_entry_finish( std::ostream&) {};

void entry_context_start( std::ostream&, log_level /*l*/) {}
Expand All @@ -79,7 +79,11 @@ void CukeBoostLogInterceptor::reset() {
/*
* Threshold level set to log_all_errors, so we should be fine logging everything
*/
void CukeBoostLogInterceptor::log_entry_value( std::ostream&, const_string value) {
void CukeBoostLogInterceptor::log_entry_value(std::ostream&, const_string value) {
description << value;
}

void CukeBoostLogInterceptor::log_entry_value(std::ostream&, lazy_ostream const& value) {
description << value;
}

Expand Down

0 comments on commit 9fe2e73

Please sign in to comment.