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

Port to C++11/C++14 removing superflous Boost facilities #88

Merged
merged 45 commits into from
Jan 23, 2022

Conversation

Flamefire
Copy link
Collaborator

@Flamefire Flamefire commented Jul 12, 2020

This addresses #69 by replacing Boost components for which equivalents or improved versions in C++11/14 exist.

This will reduce compile times for real world projects and potentially make test easier to debug.

@Flamefire Flamefire marked this pull request as draft July 12, 2020 11:46
@Flamefire Flamefire force-pushed the c++11 branch 8 times, most recently from 937c321 to ec41d7c Compare July 13, 2020 14:05
@coveralls
Copy link

coveralls commented Jul 13, 2020

Coverage Status

Coverage decreased (-0.02%) to 97.8% when pulling 41148ea on Flamefire:c++11 into bfd1701 on mat007:master.

@Flamefire Flamefire force-pushed the c++11 branch 8 times, most recently from 9e9b5ed to f51dce4 Compare July 14, 2020 19:23
@Flamefire
Copy link
Collaborator Author

@mat007 I'm done for the first step, appveyor failure is doc generation related and just a HTTP error.

I'll rebase once #90 is merged to make this a bit smaller but you can have a look already. Next step would be replacing Boost.PP usage by variadic templates which should make the code much more understandable. If wanted I can try to port the inclusion of the benchmarks into the build to current master so we can compare build times before/after for those. Note that those are not fully accurate as one can assume the std headers are used already while the benchmarks assume a "clean state"

@Flamefire Flamefire marked this pull request as ready for review July 16, 2020 12:14
@Flamefire
Copy link
Collaborator Author

@mat007 Ready. The decreased coverage is due to https://coveralls.io/builds/32087216/source?filename=include/turtle/detail/expectation_template.hpp where I reduced the number of lines by 7 which causes a decrease in relative coverage. Might be worth checking if we can test the currently uncovered serialization functions.

Copy link
Owner

@mat007 mat007 left a comment

Choose a reason for hiding this comment

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

Awesome work on the code makeover, thanks for doing this!

I’m not totally convinced on the testing of the documentation code though, I understand the value but this adds many visible side effects for the users to wonder why they’re in the docs.
Can’t we split these out to a different PR so that we can merge the rest?

doc/example/calculator.hpp Show resolved Hide resolved
doc/example/calculator.hpp Show resolved Hide resolved
doc/example/customization.cpp Outdated Show resolved Hide resolved
{
mock_view v;
calculator c( v );
MOCK_EXPECT( v.display ).once().with( 0 ); // missing returns( true )
c.add( 0, 0 );
assert_failure("missing action");
Copy link
Owner

Choose a reason for hiding this comment

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

This is showing up in the docs, I don’t think this was intentional, was it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is. The docs say that at this point a test assertion fails that an action is missing. This highlights it AND actually tests it

Copy link
Owner

Choose a reason for hiding this comment

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

I’m thinking some newcomers will be puzzled by this line, especially since the definition for assert_failure will not be visible.
There should maybe at least be a comment?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If we upgrade the required boost version to 1.59 (or higher) we can use assertions in fixtures teardown

  • Initial support via BOOST_AUTO_TEST_CASE(test, *utf::fixture<MixFixture>) is in 1.59
  • Better in 1.65 via BOOST_FIXTURE_TEST_CASE(test, MyFixture) (like now but teardown() is supported in 1.65+)

What shall it be?

Copy link
Owner

Choose a reason for hiding this comment

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

I think 1.65 is fine if that helps.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Upgraded that for new CI

doc/example/getting_started.cpp Outdated Show resolved Hide resolved
include/turtle/detail/type_name.hpp Show resolved Hide resolved
include/turtle/detail/void_t.hpp Show resolved Hide resolved
include/turtle/mock.hpp Show resolved Hide resolved
test/detail/test_type_name.cpp Outdated Show resolved Hide resolved
test/test_log.cpp Show resolved Hide resolved
@Flamefire
Copy link
Collaborator Author

As many comments are for code style: would you mind creating a clangformat file for clangformat 9 which I could use? I find it pretty hard to guess how to do that otherwise... Or if you don't care which style is used I could use one from another project. Avoids the bikeshedding and confusion...

About the docs: sure I can extract that but this would be hard as I had to fix them and used the new changes already there. So they would need to be merged afterwards. But then I feel that test coverage is missing. Some macros are only used there and I might miss a bug.
Maybe leave them in here until the pr is ready and I extract them to a follow up just before merging if you really want them separately.

I'll address the other comments next week when I work on this again. A style guide or definition until then would be nice. Check https://github.com/Return-To-The-Roots or https://github.com/boostorg/nowide for example configs which would be easiest

@Flamefire
Copy link
Collaborator Author

I rebased this to current master to resolve the conflict.

@mat007 I'm still waiting for your call on using clang-format which would greatly reduce the work for keeping the formatting uniform.

@Flamefire
Copy link
Collaborator Author

@mat007 Kindly requesting on guidance how to continue on this. If wanted we could meet in a chat or so if there is stuff for discussion so it is faster than through github. I'd like to build more stuff on top of this like replacing the preprocessor generated implementations by variadic templates to make it easier to read and debug and using a macro that allows method specifiers (const, ref qualifiers) and especially override support. This will make the mock much safer and avoids many warnings we have in our code.

@mat007
Copy link
Owner

mat007 commented Sep 5, 2020

@mat007 Kindly requesting on guidance how to continue on this.

Sorry, I’ve been away quite a lot over the summer.
I think they were two remaining points that we need solving: formatting and docs.

As many comments are for code style: would you mind creating a clangformat file for clangformat 9 which I could use? I find it pretty hard to guess how to do that otherwise... Or if you don't care which style is used I could use one from another project. Avoids the bikeshedding and confusion...

I don’t care as long as it’s used everywhere in the code.
Doesn’t Boost suggest a clangformat file? Or some of the library authors?

About the docs: sure I can extract that but this would be hard as I had to fix them and used the new changes already there. So they would need to be merged afterwards. But then I feel that test coverage is missing. Some macros are only used there and I might miss a bug.
Maybe leave them in here until the pr is ready and I extract them to a follow up just before merging if you really want them separately.

I liked how the reference documentation only explained each bit one at a time, but I can understand how making sure it compiles helps.
I’ll take a look to see what it looks like now, but I don’t think it’s a blocker for the PR as it can be adjusted later if needed.

Again, sorry for my poor reactivity this last couple of months!

Tests via Fixture::teardown that the assertion is fulfilled
…r_passed_as_parameter_of_a_mock_method

Only show what is required
I.e. it means the maximum allowed difference, similar to how other testing frameworks handle this and it allows a threshold of 0 to mean "equal"
This is allowed in C++20 and doesn't need to be tested anyway.
This avoids false positives when warnings-as-error is enabled
- Move travis to GHA (travis is dead for OSS)
- Update Boost on appveyor
@Flamefire
Copy link
Collaborator Author

Flamefire commented Jan 7, 2022

@mat007 After some heavy fighting against the CI and some peculiarities of the Ubuntu linker I finally managed to get this working on CI again including the coverage report.
I addressed your review comments unfortunately the history got a bit messed up. Basically the last 8 commits starting at 728dfd0 are new incorporating your requests and the new CI. The tests now also pass on C++20.

After this is merged I can quickly add the formatting as discussed in #97

};
template<typename T>
using parameter_type_t = typename parameter_type<T>::type;
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to use boost::callable_traits for parameter type deduction instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Would be possible. But similar to is_callable this only supports simple methods which seemingly is(/was?) enough, so this (much smaller) implementation should suffice.
And Boost.CallableTraits was introduced in Boost 1.66, i.e. it would need another increase in the minimum Boost version required which I wanted to avoid at the time of writing this.

{};
template<typename T>
struct is_callable: is_callable_impl< std::remove_cv_t<T> >
{};
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not really. I tried to translate what was there before and this whole thing isn't really good anyway: Besides a plain function there isn't a Type "callable" (this trait only takes a single parameter!)
Actually you would need to check if you can invoke something with specific parameters as is_invocable does. But we don't have those.

So a better name would be e.g. is_function.

Copy link
Owner

@mat007 mat007 left a comment

Choose a reason for hiding this comment

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

Thanks @Flamefire this is a huge achievement, and I have to tip my hat off to you for your commitment! 😁

I can either merge the PR, or I can add you as a collaborator to the project and you can merge it yourself? (you don’t have to accept if you don’t feel like it, no worries)

{
mock_concept b;
MOCK_EXPECT(b.method_int).once().with(42);
MOCK_EXPECT(b.method_string).once().with(mock::equal(std::string("string")));
Copy link
Owner

Choose a reason for hiding this comment

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

I still think mock::equal<std::string> is a bit clearer, as in meaning «equal as a string», but that’s pretty minor.

@Flamefire
Copy link
Collaborator Author

I can either merge the PR, or I can add you as a collaborator to the project and you can merge it yourself? (you don’t have to accept if you don’t feel like it, no worries)

Either is fine for me ;)
Next thing I'll open a PR for is the formatting change as previewed in #97

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants