clojure-spec

About: http://clojure.org/about/spec Guide: http://clojure.org/guides/spec API: https://clojure.github.io/spec.alpha/clojure.spec.alpha-api.html
2020-10-26T20:28:47.133500Z

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

2020-10-26T20:28:57.133800Z

Seeing results like:

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

2020-10-26T20:30:11.134300Z

No. It's your example result a problem?

2020-10-26T20:30:44.134900Z

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

2020-10-26T20:31:37.135900Z

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

2020-10-26T20:33:09.137Z

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

2020-10-26T20:35:05.137900Z

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

alexmiller 2020-10-26T20:40:36.138600Z

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)

alexmiller 2020-10-26T20:40:47.138900Z

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

alexmiller 2020-10-26T20:41:34.139600Z

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

👍 1