Fork me on GitHub
#clojurescript
<
2024-03-11
>
karol.adamiec16:03:27

given

(deftest aaa
  (= true true))
I would like to shadow deftest macro with my own "identity" macro that does nothing. i.e.
(defmacro deftest
   [name & body]
  body)
The reason is, i want to run individual tests without the annoying dance of moving back one character before evaluating. Can this be done? do i need to load up my macro redefinition at some specific time?

p-himik17:03:08

It's good that you've provided the reason because it's an instance of the XY problem. Why do you have to have that "annoying dance" in the first place?

karol.adamiec18:03:11

when navigating around s-exps i land at the end of the form and then evaluate the form before cursor. So normally i land at the closing bracket of deftest. Need to step back one bracket, to eval the insides.

p-himik18:03:48

If I were you, I would try my damndest to figure out how to navigate in a way that precludes it. Changing how the code runs just to make code navigation slightly less annoying feels incredibly wrong. :) FWIW, I use Vim bindings, so I usually just /deft<Enter> and then navigate between the tests with n and N.

karol.adamiec18:03:13

well in my dev alias i see no reason to not override deftest macro. It is mostly used from "test" alias. Also, this being clojurescript makes all that double whammy. In clojure cider understands deftest and can do sth meaningful. I am tired of trying to wrangle all that tooling around, and what i do on daily basics is run the "insides" of a test 😄

karol.adamiec18:03:11

i use emacs, and navigating forward by a sexp lands me rightly on the closing bracket

p-himik18:03:51

You have elisp. ;) But to answer your original question - it gets really finicky as it's not about evaluating a set of forms and being done with it. It's about evaluating forms in a REPL, potentially from multiple namespaces, potentially with changing the state of the REPL in some relevant way, on top of CLJS. You can try evaluating that defmacro from your original post before you evaluate any of the tests. If done within the context of the namespace where you run tests, should work. You'd have to do it again if you switch the namespace though.

karol.adamiec18:03:15

elisp is cool indeed. but writing an advice for standard move command that inspects whether we are in context of deftest sounds very wrong 🙂