Hey folks,
Sorry if this has been answered elsewhere (in which case, please point me in the right direction), but why doesn’t clojure.spec.test.alpha/instrument
test anything other than the :args
of an fdef
?
I was hoping to use instrumentation to replace specifying :pre
and :post
conditions on functions. Instrumentation would give a finer grain control over when I take a performance hit for validation, as I would only have to turn it on for functions I care about during dev.
However, it appears it doesn’t check the :ret
or :fn
params of the fdef
. I know these can be useful for generating test data, but that isn’t very helpful for my use case.
Or am I just missing something?
Thanks,
–Darren
This blog post I wrote a while back might give you some more background on Spec and the various ways it can be used, based on how it is designed to be used:
An Architect’s View: How do you use clojure.spec
At work, we were a fairly early adopter, and tried to follow the design guidelines as much as possible.
One area where we diverged was to rely on Spec for value coercion as part of conforming and validation. We began to regret this decision after a few years but haven’t fully extricated ourselves from that! A caution against trying to swim upstream by “abusing” the intended design of a feature that Rich et al have spent a lot of time thinking about.
1 Like
Thanks for the info and the pointers. Sorry I missed that in my search.
On a practical level, you can use orchestra to check :ret specs (and other fdef specs). Old but still works fine. GitHub - jeaye/orchestra: Complete instrumentation for clojure.spec
Although one big annoyance is the error wording is the exact same as for when the input args are wrong, you just have to figure out it is referring to the output being wrong.
Apparently you can do so by examining the data in the failure and/or using a companion library Exception no longer mentions source? (:args, :ret) · Issue #51 · jeaye/orchestra · GitHub