Fork me on GitHub

Is there a way to limit recursion depth for clojure.test.check.generators/recursive-gen?

(require '[clojure.test.check.generators :as g])
(binding [s/*recursion-limit* 1]
        (g/generate (g/recursive-gen #(g/vector % 1 2) g/boolean)))


Seeing results like:

[[[false]] [[true] [true]]]


No. It's your example result a problem?


Yes, this is a contrived example, trying to limit stack overflows with a recursive spec


I think recursive specs are generated in a different way and have their own depth control. Not 100% sure


Wrapping the collections within my component specs using recursive-gen has made stack overflows statistically less likely than not using that wrapping. So I thought they might be helpful if they could be further controlled


Are there other depth controls beside s/*recursion-limi*t?

Alex Miller (Clojure team)20:10:36

no, that's it - there are a few places where they are not being properly checked I think (b/c the gen code wrongly doesn't go through the place it's checked)

Alex Miller (Clojure team)20:10:47

that's just a suspicion right now but seems like I've seen that before

Alex Miller (Clojure team)20:10:34

and that's only for spec generators, won't affect directly constructed test.check generators

👍 3