-
-
Notifications
You must be signed in to change notification settings - Fork 64
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
Allow to Skip Current Generation Attempt in Provider Methods #408
Comments
In some cases (like in our case), the exception is coming from a dependency. So we really don't know all the corner cases that trigger it. So manual filtering and/or |
try {
...
} catch (Throwable t) {
Assume.that(false);
} not nice, but what in this world is... |
Just realized something.... Maybe some kind of mechanism to rerun the provider on an exception would be cleaner? Something like this. @Provide(repeatOnException = { /* List of exceptions */ })
Arbitrary<MyObject> myObjects(@ForAll int size, @ForAll String code) {
if (size == 42) {
// skip generation here because size 42 does never work
}
/* Instead of catching it we just let it fall through */
return new MyObject(size, code);
} That makes the code even cleaner and also makes it quite clear what is happening. No need to return any empty values or crap like that. |
Worth pondering. |
Turns out that @adam-waldenberg I assume it would serve your needs since you brought that option up? |
Yes. Would that end up with the provider executing again, or would it still return a null value back to the test ? That is, will I still need my |
Would just skip generation attempts with specified exception(s). |
Sounds like a plan then. |
Documentation for this is still missing, though. |
Added a paragraph about the new feature: https://jqwik.net/docs/snapshot/user-guide.html#ignoring-exceptions-in-provider-methods |
1.7.2 has been released |
🥳 |
Testing Problem
Motivated by example in #405 (comment).
Sometimes you want to skip the current generation attempt because previously generated values
that are flat-mapped don't allow generation. Example:
Suggested Solution
Introduce something like
Arbitraries.skip()
orArbitraries.fail()
which will proceed to next generation attempt.This only makes sense (I assume) if there's some flat-mapping going on.
Discussion
Assume.that(..)
be a viable option instead ofArbitraries.skip()
?The text was updated successfully, but these errors were encountered: