kaocha

Official support channel: https://clojureverse.org/c/projects/kaocha
mogenslund 2019-12-10T14:03:27.075300Z

Hi. I am trying to make tests stop on first error in each test and continue with the rest of the tests. Since the "is" macro counteracts this feature, I am trying to use exceptions as a way to "report" errors. Is there a way to avoid the tests from failing with "Test ran without assertions. Did you forget an (is ...)?", when there is no "is" statements? Since I do not want to use "is".

plexus 2019-12-10T15:08:38.076900Z

hey @mogenslund, interesting use case. This is not directly configurable as such, but you can work around it like this

#kaocha/v1
{:plugins [:kaocha.plugin/hooks]
 :kaocha.hooks/pre-run [(fn [test-plan]
                          (alter-var-root (var kaocha.hierarchy/hierarchy)
                                          underive
                                          :kaocha.type.var/zero-assertions :kaocha/fail-type)
                          test-plan)]}
at least in theory, but it seems this underive blows up at the moment because there is another key in there that has an ancestor via two different paths, which it doesn't like. I'll have to fix that in Kaocha. This seems to work though.
#kaocha/v1
{:plugins [:kaocha.plugin/hooks]
 :kaocha.hooks/pre-run [(fn [test-plan]
                          (alter-var-root (var kaocha.hierarchy/hierarchy)
                                          underive
                                          :end-test-var :kaocha/known-key)
                          (alter-var-root (var kaocha.hierarchy/hierarchy)
                                          underive
                                          :kaocha.type.var/zero-assertions :kaocha/fail-type)
                          test-plan)]}

mogenslund 2019-12-10T15:21:17.077400Z

That is great. Thank you for your quick answer.

plexus 2019-12-10T15:29:06.079200Z

I'm releasing a new kaocha, with that the first version should work. Also note that your hooks can be in a regular namespace, you don't have to have an ugly inline function like that.

#kaocha/v1
{:plugins [:kaocha.plugin/hooks]
 :kaocha.hooks/pre-run [my.kaocha.hooks/remove-zero-assertions]}
(ns my.kaocha.hooks)

(defn remove-zero-assertions [test-plan]
  ...
  test-plan)

mogenslund 2019-12-10T16:07:46.079700Z

Great. Thank you very much. I will try it out 🙂