(do
(defn f [x] x)
(s/fdef f :ret int?)
(stest/instrument)
(f "hello"))
i would expect this to throw, but i don't see that happening. what am i missing?there are many of these libs, guardrails, orchestra, ghostwheel
some use instrument/check, some avoid it (intentionally)
I saw in the #announcements channel that guardrails now has an async instrumentation thing, so it doesn't slow down your functions but you will eventually know something is wrong - at least that's what I got from it
yeah, it's optional. I think the approach with guardrails is by default just to log the failures
so that's ok to do it that way
I *reall*y wonder what spec2 will do in that regard, since apparently it's one area where there's some heavy hammocking going on. [edit] By that I don't mean Rich is heavy!
Interesting way to solve the slowness that instrumentation brings.
but yes, guardrails is the most interesting of the bunch so far imho. One thing is missing is editor support (indentation annotations), it's a bit ugly out of the box
you mean like flycheck integration? that's pretty easy if you have file:line:col: ERROR message kind of output
no, indentation, if you use something like aggressive-ident on emacs you'll get some ugly defn's with guardrails
(same with cljfmt)
isn't that a general clojure tooling problem then?
it's easy to solve, at conf level or even lib level
you can add annotation to the macros to give hints to editors :style/ident
it's not standard, but I think both emacs/cursive support it at least
right. oh, this tool forces you to use a different defn macro? hmm
maybe even cljfmt
yeah
well no, you can also use the annotation version
but you also have these def defn macros
we use it quite a lot, and like it. Sure there are rough edges but nothing too bad
(spec1 I mean)
are you doing this in the repl? I've had surprising behavior wrapping defn and similar in do/let. Try executing line-by-line?
instrument
is for argument checking, not return value checking.
instrument
checks that your function is being called correctly by other code. check
is what you use to generatively test the behavior of the function itself.
See https://clojure.org/guides/spec#_instrumentation_and_testing @michael740
@seancorfield, thank you!
i misunderstood instrument
I think almost everyone does when they first start using Spec.
There is an unofficial spec tool which will check return values as well, called orchestra
I think that library is a bit misguided since it deliberately blurs the lines that Clojure Spec draws by design. Caveat programmer.
Seemed worth mentioning, because a lot of people use it exactly for this reason.
No comment 🙂
Hehe, well, I don't use it either ;)