instrumented fdef with fspec unnecessarily invokes fspec generator
Description
Environment
Activity
Brandon Bloom January 5, 2017 at 9:38 PM
Whoops submitted a moment too soon. I wanted to add: During dev, I'd rather more things be checked a little bit (ie ret and fn) than fewer things be tested thoroughly (ie higher order functions subjected to generated inputs).
I think a distinction needs to be drawn between what can be conformed with 100% confidence and what cannot. For pure data w/o functions, we can expect conform to make some promises. With fspec etc, we can't rely on valid? => true as a security measure. I'm fine with that, but different contexts/times require different levels of confidence.
Brandon Bloom January 5, 2017 at 9:33 PM
Following up from a discussion occurring now in Slack #clojure-spec. Lots more discussion there, check timestamp.
I found this very surprising. I've been using instrument during dev/repl-time (as recommended? distinguishing form test-time), but just learned that fspec isn't suitable for functions with side-effects due to the use of generators. I expected instrument to only instrument calls to vars, never to use the generators, and either 1) ignore fspec's details (easier) or 2) proxy the fn (many challenges here).
instrument has been very useful for dev (again, vs test), but not as useful as it could be if :ret and :fn were checked, and generators were never used.
Alex Miller November 3, 2016 at 9:54 PM
That's an interesting idea, not sure if it satisfies though. Also note that instrument provides a number of options for specifying simpler instrumented replacement specs/stubs.
Allen Rohner November 3, 2016 at 6:59 PM
Instrument could wrap the function in an fn that checks arguments the same way instrument does. fspec being tied to generators makes it significantly less useful for functions with side effects.
Alex Miller November 3, 2016 at 6:24 PM
If an argument takes a function and you pass it a function, instrument cannot validate the fspec other than by generating args for the fspec and trying it out. So, this is the intended behavior. So, this is working as intended.
Details
Assignee
UnassignedUnassignedReporter
Allen RohnerAllen RohnerLabels
Approval
TriagedPriority
MajorAffects versions
Details
Details
Assignee
Reporter
Labels
Approval
Priority

With test.check is on the classpath, an instrumented fdef with fspec will invoke the generator for the fspec when invoked:
Without test.check, this fails: