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

Conversation

konserw
Copy link
Contributor

@konserw konserw commented Aug 23, 2017

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

  • Bug fix (non-breaking change which fixes an issue).
  • New feature (non-breaking change which adds functionality).
  • Breaking change (fix or feature that would cause existing functionality to not work as expected).

Checklist:

  • I'm using the same code standards as the existing code (indentation, spacing, variable naming, ...).
  • I've added tests for my code.
  • I have verified whether my change requires changes to the documentation
  • My change either requires no documentation change or I've updated the documentation accordingly.
  • My branch has been rebased to master, keeping only relevant commits.

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.

@muggenhor muggenhor added this to the v0.5 milestone Aug 23, 2017
@muggenhor
Copy link
Contributor

Can you also add a test (perhaps in tests/integration/drivers) that fails without this change and succeeds with it?

@konserw
Copy link
Contributor Author

konserw commented Aug 23, 2017

Gladly, but I'm not sure how

@konserw
Copy link
Contributor Author

konserw commented Aug 25, 2017

@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?

Copy link
Contributor

@muggenhor muggenhor left a 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})
Copy link
Contributor

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()

Copy link
Contributor Author

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>
Copy link
Contributor

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|
Copy link
Contributor

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)
Copy link
Contributor

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

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this tag ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

or replace with @boost ?

Copy link
Contributor

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:
Copy link
Contributor

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..."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@konserw
Copy link
Contributor Author

konserw commented Aug 25, 2017

@muggenhor how do you like it now? I kinda changed it other way around...

@konserw
Copy link
Contributor Author

konserw commented Aug 25, 2017

I've pasted wrong link twice. For failing test see this one: https://travis-ci.org/konserw/cucumber-cpp/jobs/268053073

@cucumber cucumber deleted a comment from coveralls Aug 25, 2017
Copy link
Contributor

@muggenhor muggenhor left a 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)
Copy link
Contributor

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.

Copy link
Member

@paoloambrosio paoloambrosio left a 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
Copy link
Member

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.
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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" |

Copy link
Contributor Author

@konserw konserw Sep 13, 2017

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.

@cucumber cucumber deleted a comment from coveralls Sep 13, 2017
@cucumber cucumber deleted a comment from coveralls Sep 13, 2017
@konserw
Copy link
Contributor Author

konserw commented Sep 13, 2017

I've created new feature file based on @paoloambrosio suggestions - now it contains more boost's macros.
Now I've also rebased against newest master.

Build is failing due to #169

@paoloambrosio
Copy link
Member

After adding the other scenarios, there is again some duplication. I've tried experimenting with a single ScenarioOutline with all the examples, and I think it would be very readable:

    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                              |

What do you think?

@konserw
Copy link
Contributor Author

konserw commented Sep 15, 2017

Looks good - I've commited this change.

Copy link
Member

@paoloambrosio paoloambrosio left a 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 :-/

@coveralls
Copy link

Coverage Status

Coverage increased (+0.003%) to 96.703% when pulling 59a3511 on konserw:issue81 into 0928f25 on cucumber:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.007%) to 96.707% when pulling d9a8f3c on konserw:issue81 into ffba658 on cucumber:master.

@konserw
Copy link
Contributor Author

konserw commented Oct 12, 2017

All green - I just had to rebase on top of master after change in travis scripts. I'll merge now.

konserw added a commit to konserw/cucumber-cpp that referenced this pull request Oct 12, 2017
@konserw konserw merged commit d9a8f3c into cucumber:master Oct 12, 2017
konserw added a commit to konserw/cucumber-cpp that referenced this pull request Oct 12, 2017
@konserw konserw deleted the issue81 branch April 2, 2018 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BOOST_PREDICATE_MESSAGE(boolean, string message)
4 participants