Fork me on GitHub
#clojure-spec
<
2020-12-21
>
Michael Stokley18:12:36

(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?

valerauko18:12:02

are you doing this in the repl? I've had surprising behavior wrapping defn and similar in do/let. Try executing line-by-line?

seancorfield18:12:35

instrument is for argument checking, not return value checking.

👌 3
seancorfield18:12:13

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.

Michael Stokley18:12:22

i misunderstood instrument

seancorfield18:12:47

I think almost everyone does when they first start using Spec.

borkdude19:12:42

There is an unofficial spec tool which will check return values as well, called orchestra

seancorfield19:12:53

I think that library is a bit misguided since it deliberately blurs the lines that Clojure Spec draws by design. Caveat programmer.

borkdude19:12:44

Seemed worth mentioning, because a lot of people use it exactly for this reason.

seancorfield20:12:29

No comment 🙂

borkdude20:12:06

Hehe, well, I don't use it either ;)

mpenet14:12:24

there are many of these libs, guardrails, orchestra, ghostwheel

mpenet14:12:41

some use instrument/check, some avoid it (intentionally)

borkdude14:12:30

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

mpenet14:12:53

yeah, it's optional. I think the approach with guardrails is by default just to log the failures

mpenet14:12:00

so that's ok to do it that way

mpenet14:12:44

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!

borkdude14:12:54

Interesting way to solve the slowness that instrumentation brings.

mpenet15:12:00

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

borkdude15:12:16

you mean like flycheck integration? that's pretty easy if you have file:line:col: ERROR message kind of output

mpenet15:12:43

no, indentation, if you use something like aggressive-ident on emacs you'll get some ugly defn's with guardrails

mpenet15:12:53

(same with cljfmt)

borkdude15:12:04

isn't that a general clojure tooling problem then?

mpenet15:12:09

it's easy to solve, at conf level or even lib level

mpenet15:12:33

you can add annotation to the macros to give hints to editors :style/ident

mpenet15:12:52

it's not standard, but I think both emacs/cursive support it at least

borkdude15:12:02

right. oh, this tool forces you to use a different defn macro? hmm

mpenet15:12:03

maybe even cljfmt

mpenet15:12:17

well no, you can also use the annotation version

mpenet15:12:28

but you also have these def defn macros

mpenet15:12:15

we use it quite a lot, and like it. Sure there are rough edges but nothing too bad

mpenet15:12:34

(spec1 I mean)