jqwik-team/jqwik

Cannot use Arbitrary.generator() outside jqwik

odenix opened this issue · 6 comments

I'm trying to use Arbitrary.generator() outside jqwik, but it doesn't work. Is this a bug? jqwik 1.8.4.

var arbitrary = Arbitraries.strings();
var generator = arbitrary.generator(100);
net.jqwik.engine.execution.lifecycle.OutsideJqwikException: The current action must be run on a jqwik thread, i.e. container, property or hook.
Maybe you spawned off a thread?

Not a bug. Using generators works in a certain way: https://jqwik.net/docs/current/user-guide.html#using-arbitraries-directly

Thanks, this looks great. Is there also a way to do shrinking outside jqwik?

Not realistically. Shrinking requires a lot of context; the code is all hidden in the engine module.
What‘s your use case?

I'm trying to add support for property-based testing to Pkl, and I'm hoping that jqwik will do the heavy lifting for me. :-)

https://pkl-lang.org/blog/testing-in-pkl.html

Don't know anything about pkl, but my assumption is that you'd have to wait for jqwik2, which will be much more generic.

Sounds good. For now this is just a POC, and copying/modifying parts of the jqwik source code is good enough.