-
Notifications
You must be signed in to change notification settings - Fork 131
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
Conversation
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) {};
^
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
Can you also add a test (perhaps in |
Gladly, but I'm not sure how |
@muggenhor - could you take a look at the test I've added? I'm not good with ruby... Also maybe we should rethink how the "support code" is inserted to every feature with C++ code? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a Ruby expert myself, but they mostly look good to me.
One thing that I'm missing though is a way to prevent this feature from being executed if we're building without Boost.Test. Not sure how easy that would or wouldn't be. Probably it involves adding a tag to the feature and adding a parameter to filter that out in the CMake features*
targets.
PS Do you have a link to a travis job demonstrating that this new test case fails without your changes to the driver?
CMakeLists.txt
Outdated
@@ -216,7 +216,7 @@ 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 ${CUKE_LIBRARIES} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this a separate statement, like this:
if(Boost_UNIT_TEST_FRAMEWORK_FOUND)
target_link_libraries(e2e-steps PRIVATE ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
endif()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point.
@@ -1,4 +1,5 @@ | |||
#include <boost/test/unit_test.hpp> | |||
// Pretend to be GTest | |||
#define EXPECT_EQ BOOST_CHECK_EQUAL | |||
#include <cucumber-cpp/autodetect.hpp> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line should not be necessary as it's the first line found in CalculatorSteps.cpp
@@ -1,3 +1,7 @@ | |||
Given /^a step definition file without support code:$/ do |code| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rename to "a step definition file with only this content"
@@ -228,6 +228,10 @@ def append_step_definition(step_name, code) # todo params parameter? | |||
EOF | |||
end | |||
|
|||
def no_support_code(code) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to only_support_code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is without the support code (code from support folder)
@@ -0,0 +1,70 @@ | |||
@wip |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this tag ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or replace with @boost ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's a good one
|
||
This is just a simple feature meant to test the fix for issue #81. | ||
Problem was Cucumber-Cpp didn't recoginize failed asserations | ||
when using following Boost macros: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rephrase without the issue please. I.e. something like "Support Boost.Test's different validation and reporting macros..."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@muggenhor how do you like it now? I kinda changed it other way around... |
I've pasted wrong link twice. For failing test see this one: https://travis-ci.org/konserw/cucumber-cpp/jobs/268053073 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good for merging with the one suggested change.
CMakeLists.txt
Outdated
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 ${CUKE_E2E_TAGS} --format progress) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just add it before ${ARGN}
in the add_feature_target
function instead. That reduces repetition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nicely done! Just some comments on the feature file...
@@ -0,0 +1,72 @@ | |||
@boost | |||
Feature: Predicate Message Feature |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either this should be in a boost
directory or it should specify that it is related to Boost. Please remove the redundant Feature
at the end.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The description should capture the behaviour, not why you did it (you should find that in the PR).
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant and can get out of sync with the scenarios.
BOOST_CHECK_MESSAGE( predicate, message ) -> should fail | ||
BOOST_REQUIRE_MESSAGE( predicate, message ) -> should fail | ||
|
||
Scenario: BOOST_WARN_MESSAGE Scenario |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove redundant Scenario
at the end.
} | ||
""" | ||
When Cucumber runs the feature | ||
Then the failure message "boost message" is output |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we condense all those scenarios into one scenario outline?
Scenario Outline: <check>
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>(false, "boost message");
}
"""
When Cucumber runs the feature
Then the scenario <passes or fails?>
Examples:
| check | passes or fails? |
| BOOST_WARN_MESSAGE | passes |
| BOOST_CHECK_MESSAGE | fails with message "boost message" |
| BOOST_REQUIRE_MESSAGE | fails with message "boost message" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat 👍 I was thinking about something like that - I just wasn't sure how to use it with C++ code.
I've created new feature file based on @paoloambrosio suggestions - now it contains more boost's macros. Build is failing due to #169 |
After adding the other scenarios, there is again some duplication. I've tried experimenting with a single
What do you think? |
Looks good - I've commited this change. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice PR! It can be merged as soon as the build passes. Travis seems to be really slow, but I guess #169 will make it fail :-/
All green - I just had to rebase on top of master after change in travis scripts. I'll merge now. |
Summary
Intercept messages from BOOST_*_MESSAGE macros
Details
Motivation and Context
Fixes #81
How Has This Been Tested?
It has been tested manually by adding following line to BoostCalc example and running that example:
BOOST_CHECK_MESSAGE(false, "Message");
Types of changes
Checklist: