Skip to content

Commit ec26000

Browse files
committed
Merge cucumber#164 'Intercept messages from BOOST_*_MESSAGE macros'
2 parents ffba658 + d9a8f3c commit ec26000

File tree

6 files changed

+67
-8
lines changed

6 files changed

+67
-8
lines changed

CMakeLists.txt

+11-4
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,13 @@ else()
217217
add_executable(e2e-steps EXCLUDE_FROM_ALL ${CUKE_DYNAMIC_CPP_STEPS})
218218
# Mark this file as generated so it isn't required at CMake generation time (it is necessary when the target gets built though)
219219
set_source_files_properties(${CUKE_DYNAMIC_CPP_STEPS} PROPERTIES GENERATED TRUE)
220-
target_link_libraries(e2e-steps ${CUKE_LIBRARIES})
220+
target_link_libraries(e2e-steps PRIVATE ${CUKE_LIBRARIES})
221+
#Boost test lib required for boost specific scenario "Predicate Message"
222+
if(Boost_UNIT_TEST_FRAMEWORK_FOUND)
223+
target_link_libraries(e2e-steps PRIVATE ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
224+
else()
225+
set(CUKE_E2E_TAGS "--tags ~@boost")
226+
endif()
221227

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

@@ -242,16 +248,17 @@ else()
242248
COMPILE_DYNAMIC_CPP_STEPS=${CUKE_COMPILE_DYNAMIC_CPP_STEPS}
243249
CUCUMBER_RUBY=${CUCUMBER_RUBY}
244250
--format=junit "--out=${CMAKE_BINARY_DIR}/features"
251+
${CUKE_E2E_TAGS}
245252
${ARGN}
246253
${CUKE_FEATURES_DIR}
247254
DEPENDS cucumber-cpp
248255
${USES_TERMINAL}
249256
)
250257
endfunction(add_feature_target)
251258

252-
add_feature_target(features --format progress)
253-
add_feature_target(features-pretty --format pretty)
254-
add_feature_target(features-wip --format pretty --tags @wip)
259+
add_feature_target(features --format progress)
260+
add_feature_target(features-pretty --format pretty)
261+
add_feature_target(features-wip --format pretty --tags @wip)
255262

256263
else()
257264
message(WARNING "Could not find Cucumber: skipping end-to-end tests")
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
@boost
2+
Feature: Check macros used with boost test driver
3+
4+
This is just a simple feature meant to test boost's
5+
specyfic validation macros interop with cucumber.
6+
7+
Scenario Outline: <check> macro
8+
Given the following feature:
9+
"""
10+
Feature: Feature name
11+
Scenario: Scenario name
12+
Given a step
13+
"""
14+
And a step definition file with:
15+
"""
16+
#include <boost/test/unit_test.hpp>
17+
#include <cucumber-cpp/autodetect.hpp>
18+
GIVEN("a step") {
19+
<check>;
20+
}
21+
"""
22+
When Cucumber runs the feature
23+
Then the scenario <passes or fails?>
24+
25+
Examples:
26+
| check | passes or fails? |
27+
| BOOST_CHECK(false) | fails |
28+
| BOOST_CHECK_MESSAGE(false, "boost message") | fails with message "boost message" |
29+
| BOOST_ERROR("boost message") | fails with message "boost message" |
30+
| BOOST_FAIL("boost message") | fails with message "boost message" |
31+
| BOOST_REQUIRE(false) | fails |
32+
| BOOST_REQUIRE_MESSAGE(false, "boost message") | fails with message "boost message" |
33+
| BOOST_WARN(false) | passes |
34+
| BOOST_WARN_MESSAGE(false, "boost message") | passes |

features/specific/simple.feature

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Feature: Simple Feature
1212
Scenario: Scenario name
1313
Given a step
1414
"""
15-
And a step definition file with:
15+
And a step definition file with support code including:
1616
"""
1717
#include <iostream>
1818

features/step_definitions/cucumber_cpp_mappings.rb

+4
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,10 @@ def append_step_definition(step_name, code) # todo params parameter?
228228
EOF
229229
end
230230

231+
def set_code(code)
232+
@support_code = code
233+
end
234+
231235
def append_support_code(code)
232236
helper_functions = get_absolute_path('../support/HelperFunctions.hpp');
233237
@support_code ||= <<-EOF

features/step_definitions/cucumber_cpp_steps.rb

+10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
Given /^a step definition file with:$/ do |code|
2+
set_code code
3+
end
4+
5+
Given /^a step definition file with support code including:$/ do |code|
26
append_support_code code
37
end
48

@@ -9,3 +13,9 @@
913
Then /^a step definition snippet with (".*") is suggested$/ do |regex_string|
1014
assert_partial_output("(#{regex_string}) {", all_output)
1115
end
16+
17+
Then /^the scenario fails with message "([^"]*)"$/ do |message|
18+
assert_partial_output(message, all_output)
19+
assert_success false
20+
end
21+

src/drivers/BoostDriver.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ class CukeBoostLogInterceptor : public ::boost::unit_test::unit_test_log_formatt
6060
void log_exception_finish( std::ostream& ) {};
6161

6262
void log_entry_start( std::ostream&, log_entry_data const&, log_entry_types /*let*/) {};
63-
void log_entry_value( std::ostream&, const_string /*value*/);
64-
void log_entry_value( std::ostream&, lazy_ostream const& /*value*/) {};
63+
void log_entry_value( std::ostream&, const_string value);
64+
void log_entry_value( std::ostream&, lazy_ostream const& value);
6565
void log_entry_finish( std::ostream&) {};
6666

6767
void entry_context_start( std::ostream&, log_level /*l*/) {}
@@ -79,7 +79,11 @@ void CukeBoostLogInterceptor::reset() {
7979
/*
8080
* Threshold level set to log_all_errors, so we should be fine logging everything
8181
*/
82-
void CukeBoostLogInterceptor::log_entry_value( std::ostream&, const_string value) {
82+
void CukeBoostLogInterceptor::log_entry_value(std::ostream&, const_string value) {
83+
description << value;
84+
}
85+
86+
void CukeBoostLogInterceptor::log_entry_value(std::ostream&, lazy_ostream const& value) {
8387
description << value;
8488
}
8589

0 commit comments

Comments
 (0)