From a2fa3f31b36e2e2cf179d686a33cb71b8cd73594 Mon Sep 17 00:00:00 2001 From: Kamil Strzempowicz Date: Wed, 23 Aug 2017 18:12:44 +0200 Subject: [PATCH 1/2] Fix issue #81 by intercepting messages from BOOST_*_MESSAGE macros --- CMakeLists.txt | 15 ++-- features/specific/predicate_message.feature | 72 +++++++++++++++++++ features/specific/simple.feature | 2 +- .../step_definitions/cucumber_cpp_mappings.rb | 4 ++ .../step_definitions/cucumber_cpp_steps.rb | 4 ++ src/drivers/BoostDriver.cpp | 10 ++- 6 files changed, 99 insertions(+), 8 deletions(-) create mode 100644 features/specific/predicate_message.feature diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b8aaecf..a6aef791 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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') @@ -242,6 +248,7 @@ 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 @@ -249,9 +256,9 @@ else() ) 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") diff --git a/features/specific/predicate_message.feature b/features/specific/predicate_message.feature new file mode 100644 index 00000000..8c397646 --- /dev/null +++ b/features/specific/predicate_message.feature @@ -0,0 +1,72 @@ +@boost +Feature: Predicate Message Feature + + This is just a simple feature meant to test boost's + validation macros that also output custom message. + Problem was Cucumber-Cpp didn't capture those messages + and even didn't recognize failed asserations. + Expected results when using following Boost macros: + BOOST_WARN_MESSAGE( predicate, message ) -> should pass + BOOST_CHECK_MESSAGE( predicate, message ) -> should fail + BOOST_REQUIRE_MESSAGE( predicate, message ) -> should fail + + Scenario: BOOST_WARN_MESSAGE Scenario + Given the following feature: + """ + Feature: Feature name + + Scenario: Scenario name + Given a step + """ + And a step definition file with: + """ + #include + #include + + GIVEN("a step") { + BOOST_WARN_MESSAGE(false, "boost message"); + } + """ + When Cucumber runs the feature + Then the scenario passes + + Scenario: BOOST_CHECK_MESSAGE Scenario + Given the following feature: + """ + Feature: Feature name + + Scenario: Scenario name + Given a step + """ + And a step definition file with: + """ + #include + #include + + GIVEN("a step") { + BOOST_CHECK_MESSAGE(false, "boost message"); + } + """ + When Cucumber runs the feature + Then the failure message "boost message" is output + + Scenario: BOOST_REQUIRE_MESSAGE Scenario + Given the following feature: + """ + Feature: Feature name + + Scenario: Scenario name + Given a step + """ + And a step definition file with: + """ + #include + #include + + GIVEN("a step") { + BOOST_REQUIRE_MESSAGE(false, "boost message"); + } + """ + When Cucumber runs the feature + Then the failure message "boost message" is output + diff --git a/features/specific/simple.feature b/features/specific/simple.feature index a1d70eed..51e754f2 100644 --- a/features/specific/simple.feature +++ b/features/specific/simple.feature @@ -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 diff --git a/features/step_definitions/cucumber_cpp_mappings.rb b/features/step_definitions/cucumber_cpp_mappings.rb index 43e39e18..a64deb1a 100644 --- a/features/step_definitions/cucumber_cpp_mappings.rb +++ b/features/step_definitions/cucumber_cpp_mappings.rb @@ -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 diff --git a/features/step_definitions/cucumber_cpp_steps.rb b/features/step_definitions/cucumber_cpp_steps.rb index b41eaa58..32cad073 100644 --- a/features/step_definitions/cucumber_cpp_steps.rb +++ b/features/step_definitions/cucumber_cpp_steps.rb @@ -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 diff --git a/src/drivers/BoostDriver.cpp b/src/drivers/BoostDriver.cpp index fcd0bf61..f96ed1b3 100644 --- a/src/drivers/BoostDriver.cpp +++ b/src/drivers/BoostDriver.cpp @@ -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*/) {} @@ -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; } From d9a8f3ca04b476aef0cdfb6f3193b5b6c4fb2bdb Mon Sep 17 00:00:00 2001 From: Kamil Strzempowicz Date: Wed, 13 Sep 2017 20:15:10 +0200 Subject: [PATCH 2/2] Feature file to test boost macros --- features/specific/boost_specific.feature | 34 +++++++++ features/specific/predicate_message.feature | 72 ------------------- .../step_definitions/cucumber_cpp_steps.rb | 6 ++ 3 files changed, 40 insertions(+), 72 deletions(-) create mode 100644 features/specific/boost_specific.feature delete mode 100644 features/specific/predicate_message.feature diff --git a/features/specific/boost_specific.feature b/features/specific/boost_specific.feature new file mode 100644 index 00000000..c27f0097 --- /dev/null +++ b/features/specific/boost_specific.feature @@ -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: macro + Given the following feature: + """ + Feature: Feature name + Scenario: Scenario name + Given a step + """ + And a step definition file with: + """ + #include + #include + GIVEN("a step") { + ; + } + """ + When Cucumber runs the feature + Then the scenario + + 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 | diff --git a/features/specific/predicate_message.feature b/features/specific/predicate_message.feature deleted file mode 100644 index 8c397646..00000000 --- a/features/specific/predicate_message.feature +++ /dev/null @@ -1,72 +0,0 @@ -@boost -Feature: Predicate Message Feature - - This is just a simple feature meant to test boost's - validation macros that also output custom message. - Problem was Cucumber-Cpp didn't capture those messages - and even didn't recognize failed asserations. - Expected results when using following Boost macros: - BOOST_WARN_MESSAGE( predicate, message ) -> should pass - BOOST_CHECK_MESSAGE( predicate, message ) -> should fail - BOOST_REQUIRE_MESSAGE( predicate, message ) -> should fail - - Scenario: BOOST_WARN_MESSAGE Scenario - Given the following feature: - """ - Feature: Feature name - - Scenario: Scenario name - Given a step - """ - And a step definition file with: - """ - #include - #include - - GIVEN("a step") { - BOOST_WARN_MESSAGE(false, "boost message"); - } - """ - When Cucumber runs the feature - Then the scenario passes - - Scenario: BOOST_CHECK_MESSAGE Scenario - Given the following feature: - """ - Feature: Feature name - - Scenario: Scenario name - Given a step - """ - And a step definition file with: - """ - #include - #include - - GIVEN("a step") { - BOOST_CHECK_MESSAGE(false, "boost message"); - } - """ - When Cucumber runs the feature - Then the failure message "boost message" is output - - Scenario: BOOST_REQUIRE_MESSAGE Scenario - Given the following feature: - """ - Feature: Feature name - - Scenario: Scenario name - Given a step - """ - And a step definition file with: - """ - #include - #include - - GIVEN("a step") { - BOOST_REQUIRE_MESSAGE(false, "boost message"); - } - """ - When Cucumber runs the feature - Then the failure message "boost message" is output - diff --git a/features/step_definitions/cucumber_cpp_steps.rb b/features/step_definitions/cucumber_cpp_steps.rb index 32cad073..bcf9f0a5 100644 --- a/features/step_definitions/cucumber_cpp_steps.rb +++ b/features/step_definitions/cucumber_cpp_steps.rb @@ -13,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 +