How to check Clojure spec's for macros?

90 views
Skip to first unread message

Dylon Edwards

unread,
Jan 15, 2018, 3:44:01 AM1/15/18
to Clojure
For spec'd functions, you may check them automatically with clojure.test.check.alpha/check.  Is there something similar for spec'd macros?  I can always use test.check to generate unit testing parameters for macros, but is there a way to get that for free with Clojure spec?

Regards,
Dylon

Dylon Edwards

unread,
Jan 15, 2018, 4:04:58 AM1/15/18
to Clojure
By clojure.test.check.alpha, I meant clojure.spec.test.alpha.  If there's not a way to check macros now, is the feature planned?

Didier

unread,
Jan 15, 2018, 1:19:31 PM1/15/18
to Clojure
With macros I believe you get compile time check, ie, static checking. This is because the input to a macro is availaible at compile time, so spec just validates it on macro-expanssion.

You can use test.check to instrument a generative test to test the expanded code too if you want.

Alex Miller

unread,
Jan 15, 2018, 1:54:23 PM1/15/18
to Clojure
stest/check does not work with spec'ed macros. In general, most macros emit code (in the form of data) and in my experience it's usually either not possible or more effort than it's worth to write :ret or :fn specs for macros, so in practice I have not found this to be needed.

stest/instrument also doesn't work with macros, although this is somewhat replaced by always checking the args on macros during macroexpansion.

Dylon Edwards

unread,
Jan 15, 2018, 2:41:30 PM1/15/18
to clo...@googlegroups.com
That helps a lot, thanks!
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to a topic in the Google Groups "Clojure" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojure/RxnwKcha0cE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages