in clojure, i can test if macro expansion fails by writing (is (thrown? (eval (foo 1 2 3))))`. is there a way to do that in clojurescript?
Are you talking about self-hosted CLJS? Because otherwise CLJS macros are just CLJ code that gets run during compilation.
Apart from that, that thrown? tests not just macro expansion but also whether or not the expanded code works. In CLJS in general, macro expansion and code running are two separate stages, run on different platforms. While it's still possible to check stuff like this, it's definitely not built-in and I can't imagine for it to be trivial to do.
cool, that's what i thought
i'm not talking self-hosted, just plain clojurescript
Why not macro-expand instead of eval?
in clj, it's just what i chose when i wrote the tests. in cljs, neither macro-expand nor eval exist
Oh... Hmm, yeah, of course, because macros are already expanded before runtime 😐
Also, in CLJ it wouldn't test for "the macro works". It would catch only failures where the expansion itself is broken, but eval also catches when the result is broken. A macro can produce garbage like (1) without throwing.
I haven't written enough cljs for my brain to have internalized the rules... Yeah, I guess it depends what you mean by "test if macro expansion fails" 🙂