clojure.spec.test/instrument causes clojure.spec/exercise-fn to use generators which fail the args spec!?

107 views
Skip to first unread message

J.-F. Rompre

unread,
Oct 20, 2016, 12:17:19 AM10/20/16
to Clojure
I am trying to learn clojure.spec and tried my hand at a spec for a fizzbuzz function.
For some strange reason, generators created for it fail the same spec during clojure.spec/exercise-fn !

Stranger, this happens only if the same function is first instrumented using clojure.spec.stest/instrument.
Otherwise (commenting out the instrument call), exercise-fn generates compliant inputs and returns.

I tried to reproduce this with a trivial example to show here but couldn't, so created a gist to illustrate the issue:
     https://gist.github.com/KingCode/101ff425f1abd9693a7e8c4b5d389e74

Thanks for any comment and enlightening, I can't wait to use spec productively :)
JF

Beau Fabry

unread,
Oct 20, 2016, 2:30:27 AM10/20/16
to Clojure
You have two possible branches for your ::fizbuzz arguments, a one-arity and a 3-arity. The 1-arity branch allows for the value 1, which when passed to the function fizzbuzz recursively calls the function fizzbuzz with the arguments (3 5 1) is not a valid set of values for ::fizzbuzz and so raises an exception.

The reason you only get the exception when you've instrumented the function, is because the non-conforming set of arguments is constructed in the 1-arity, and doesn't get checked against ::fizzbuzz unless instrumentation is turned on.

J.-F. Rompre

unread,
Oct 20, 2016, 6:17:29 AM10/20/16
to Clojure
Ah, I missed that....thank you very much!
Reply all
Reply to author
Forward
0 new messages