Fork me on GitHub
#clojure-spec
<
2020-10-26
>
waffletower20:10:47

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)))

waffletower20:10:57

Seeing results like:

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

gfredericks20:10:11

No. It's your example result a problem?

waffletower20:10:44

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

gfredericks20:10:37

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

waffletower20:10:09

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

waffletower20:10:05

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