-
-
Notifications
You must be signed in to change notification settings - Fork 648
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
SUBCASE in function not behaving as expected #282
Comments
Well.. this is a legit bug, thanks for catching and reporting it! I'll look into fixing it as soon as I can - perhaps in a week or two... EDIT: I'm actually not sure if it is a bug, or an improvement request, since this use case was never thought of, but thanks nonetheless! |
Bug or improvement request - I find the option of moving lots of checks into functions very valuable to avoid code duplication. |
Out of curiosity - do you actually need subcases for the checking? I mean... in the example provided it makes sense for the generation of the data, but not for the checking - that could just be a function with asserts. Or maybe your real use case is more complicated... |
Well, I need them only as much as need subcases. They're not required for anything I do but they're neat because they let you represent tree-like state changes with minimal code. I'm not really sure that's the best way to organize my tests but subcases certainly help a lot to avoid redundant code - as does the ability put them into functions. FYI, the nesting depth of my subcases is max. around 10. I also moved back to catch for the time being since I noticed that threads in tests do seem to work well if they their execution is serialized (which is natural and inherently ensured in my tests). |
Thanks for the context. I do plan on fixing this - hopefully this weekend, but cannot promise a date. |
fixed and pushed in the dev branch - will release an official version soon. |
Description
I have code with multiple ways to generate a piece of data. I also have a set of checks that should be applied to such a piece of data, no matter how it was generated. I don't want to duplicate the checks for each way of generation, and instead put the checks (implemented in SUBCASEs) into a function, which is then called where needed.
So this would be what I want to avoid, but what works as expected:
Output:
Note the 4
#
, indicating the executed SUBCASEs.Instead, I want the checks in a separate function:
However, this results in:
I.e., the checks are run only once, not twice.
This is pretty suprising for me*. How can I make that work as desired?
* Originally, I started writing my tests in Catch, where I didn't have this issue of putting SECTIONs into functions. Now I want to switch to doctest since I need thread-safety.
Steps to reproduce
Copy + paste the code into your online-demo
Thanks for your help!
The text was updated successfully, but these errors were encountered: