kaocha

Official support channel: https://clojureverse.org/c/projects/kaocha
zilti 2020-01-03T12:51:22.025400Z

I have a macro generating tests "on the fly", is there a way I can have Kaocha run only the tests by that macro? Adding a metadata key to the generated deftest does not work, I assume Kaocha is statically parsing and looking at the test files.

miikka 2020-01-03T14:02:05.027800Z

Hmm, I believe that adding the metadata should work. Are you sure your macro adds the metadata correctly, though? It's a bit tricky, If you do it like make-test-1 below, it won't work, but I think make-test-2 would work

(defmacro make-test-1 [n] `(deftest ^:my-test ~n))
(defmacro make-test-2 [n] `(deftest ~(with-meta n {:my-test true})))

miikka 2020-01-03T14:06:15.029200Z

You can check it in REPL by requiring the namespace with macro-generated tests and running (meta #'your-namespace/name-of-the-test) . If the metadata is in the result, then Kaocha should see it.

plexus 2020-01-03T14:33:33.031400Z

@miikka is correct, your test files get loaded first, then we look for metadata on the vars. You can also check --print-test-plan to see the metadata Kaocha has found for each var

zilti 2020-01-03T17:38:32.032100Z

Oh, it needs ~(with-meta), yea I just used ^:my-test.

zilti 2020-01-03T17:38:39.032400Z

Thanks! And I'll try --print-test-plan

zilti 2020-01-03T19:01:32.033700Z

Where would the test name go though, before or after the with-meta block? Because neither seems to work for me

plexus 2020-01-03T19:50:58.034200Z

inside the with-meta, you add the metadata to the symbol that becomes the name of the var.