Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #81 by intercepting messages from BOOST_*_MESSAGE macros #164

Merged
merged 2 commits into from
Oct 12, 2017
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
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't do this: this causes warnings about "unused parameters", that's the reason it was commented out like that in the first place.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we are actually using them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grep for unused and for param hasn't show me any warning

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, nevermind, I didn't notice that you changed the empty inline function ({}) to just a declaration with the function's definition elsewhere.

As for warnings: you should compile with -Wall -Wextra to see any. I think we should probably consider building with that one plus -Werror by default on our CI systems at least.

The old code (with empty inline function definition) without commented out parameter produces this with `-DCMAKE_CXX_FLAGS='-Wall -Wextra -Werror':

../src/drivers/BoostDriver.cpp:64:62: error: unused parameter 'value' [-Werror,-Wunused-parameter]                                                                 void log_entry_value( std::ostream&, lazy_ostream const& value) {};                                                               
                                                             ^

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we are doing so for debug builds, but now I can see that there is only -Weffc++ being set for those. We could add those flags to CMAKE_CXX_FLAGS_DEBUG in CMakelists ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just submitted 3ec9d03 which enables warnings for all GCC/Clang builds. I don't think it makes sense to make it dependent on the build type. Adding -Werror is something we should do only when the warnings are fixed.

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