-
Notifications
You must be signed in to change notification settings - Fork 10
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
Catch2 emulation: list tests has a footer #168
Catch2 emulation: list tests has a footer #168
Conversation
This is a bit of an annoyance from the early design of the reporter configuration. The public I think the core or the issue is that snitch/include/snitch/snitch_macros_reporter.hpp Lines 12 to 16 in fe24bc4
It could be that the signature of the callbacks may have to change, see #80. Or we could reserve some storage space in the registry to allocate (in place) the reporter instance. For this PR, I think we probably should stick with the current API and make it work (probably means having to create a global console reporter, or maybe store it as a member of the registry). If we can't, then we'll have to bite the bullet, break compatibility, and move to v2.0. |
output the number of tests discovered as a footer to the listed tests. This commit transforms the console reporter from a collection of free functions to a struct so that it can maintain the count of tests as they are listed.
e2cc082
to
c781809
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #168 +/- ##
==========================================
- Coverage 94.06% 93.88% -0.18%
==========================================
Files 27 28 +1
Lines 1701 1651 -50
==========================================
- Hits 1600 1550 -50
Misses 101 101
Continue to review full report in Codecov by Sentry.
|
This works around the need for there to be an instantiation of the console reporter now that it has state. Since the console reporter is the default reporter it can be statically initialized in the registry. To allow the registry to continue being constinit, a defaulted constructor was added to the console reporter. There are also static functions in the registry that are used to register the console reporter as a reporter with the existing API.
somewhat silly, but it does re-init the console reporter and should fix the test coverage failure.
55822c3
to
cc625e0
Compare
making it a member wasn't a bad idea, at least for maintaining compatibility. Since the console reporter is the "default" reporter it's not that absurd I don't think. I made it a static member, and added some private static functions that call it so that it can be registered with the The |
Thanks, this is looking good! I have only one issue with the implementation: the use of a The fault is actually mine; the I have been experimenting on top of your PR to fix this, and have a working solution to remove this global state for all reporters, but this is out of scope of this PR. If this is OK with you, I propose we merge your PR as is, and I can follow up with my own changes in another PR to take it a step further. |
66a7d84
to
022b552
Compare
Agreed. The main reason was that the default value of I took a closer look at the template<typename ObjectType, auto MemberFunction>
constexpr function_ref(ObjectType& obj, constant<MemberFunction>) noexcept; So I just pushed a change where the console reporter isn't static and I use this constructor to set the default value of |
The reporter needed to be static to allow the assignment of it's functions to the function references. But the function reference type actually does have storage for a single pointer that could be used to store the `this` pointer of the registery. To do this we need to be sure and invoke the appropriate constructor for the function reference.
022b552
to
2c864b1
Compare
If you don't mind, please! |
as suggested by horenmar in issue snitch-org#140, check against availability of consteval propagation (P2564) instead of a specific MSVC version.
The constructor was used as the function to call when wrapping the struct into functions for registrations. As of the latest refactor it isn't used though and so triggers a test coverage reduction. Remove the unused constructor to again be following rule of zero.
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.
Thank you!
There's one minor comment I would make, but I don't think it's blocking this PR from being merged. Although the console reporter is a bit special (in that, it is the default), we should still try to keep it as standard as possible, so it doesn't deviate from other reporters. The main reason is that, it being the default, I think it will be where most people will look for an example if they want to create their own reporter.
With this in mind, I would prefer to keep the constructor taking a registry&
, and keeping the REGISTER_REPORTER
macro at the bottom of snitch_reporter_console.cpp
.
I'm happy to leave it as it is now, and I can address this when I tackle issue #171; I think it will be easier then (see e.g. d3d5f8a).
This MR changes the console reporter from free functions to a struct, so that it can maintain state and count the
tests when listing them.
I am stuck trying to figure out how to properly initialize the
report_callback
in the registry. When the console report function was a free function it could just get a reference to that function. But now that it is a struct there needs to be an instance somewhere. The registry isconstinit
so there shouldn't be a static order issue, but it also can't have a nonconstexpr
constructor.Some tests also required a reporter instance, and there I declared one either in the test function itself or in an anonymous namespace in the test file if the lifetime needed to outlast the spot it was used.