Open 12AT7 opened 4 years ago
I'm not sure about this. I intended for this to be handled with a simple for
loop or std::for_each
or whatever the ranges version of that is. If we lived in a world where there were easy, standard ways to iterate over types, I might never have added support for type-parameterization either.
On the other hand, there's a certain symmetry to providing a special creator for value-parameterized suites. Though on the third(?) hand, "symmetry" is a pretty weak argument.
The way that this works basically is exactly that; just a for
loop over a container (and, presumably, ranges will be similar and awesome). In my use, I actually have a custom generator class that I use as well. It is definitely not required that this function be part of Mettle itself to be useful in applications; it is easy enough to adapt this outside of mettle as I have done.
This is sort of similar to the discussion we had a couple of years ago about supporting properties based testing. It has the similar feel of generating a batch of tests from a programmable rule. It has been a while since I looked at that, but I seem to remember that we settled on a similar pattern of using a free function to populate the suite in a specialized way.
You can close this issue, or use it as an example, or whatever you want to do with it. If others find it useful, then it is still going to be here in issues as a reference.
I thought about this a bit more, and I think there's some value in doing this, since it's a bit more difficult to parameterize root-level suites with multiple values (obviously, you can't have a for
loop at global scope). I'll probably do the same sort of thing for test cases too.
My favorite Mettle feature is the template parameters to instantiate tests on different types. However, I have also been experimenting with function parameters to solve a different kind of testing problem. Specifically, I need to sample my tests with different numerical parameters. They are always the same type, and there might be a great many of them. While these parameters can be coaxed into compile time arguments, the Mettle compile times then become prohibitive. Some test patterns are just more naturally expressed via sets of function parameters. This is particularly true in the scientific programming I normally do.
Here I demonstrate a prototype
mettle::enumerate<>(...)
that is supposed to emulatemettle::subsuite<>(...)
as closely as possible, except for these differences:name
argument for the tests use alibfmt
pattern instead of a plain string, and_.test()
invocations.I am completely unmarried to my names here, and I am certain extra wizardry would be required to fully support important Mettle features like fixtures and marks. I am posting this as a feature request, not a fully formed pull request, because I am sure some design discussion up front would be helpful.
From my code sample below, this is the output that I get. I am not actually making any test assertions (those work fine); I am more interested here is seeing which tests are collected and how the names are formatted.
Here is my investigation: