Fork me on GitHub
#kaocha
<
2022-02-15
>
Ferdinand Beyer09:02:58

Is there a (built-in) way to make kaocha detect :source-paths and :test-paths automatically? Or take them from deps.edn? I have split my code into multiple sub-projects and would like to run all tests. For that, my :test alias has all sub/x/test directories in :extra-paths. I do not want to repeat all these paths in tests.edn.

plexus14:02:45

there's nothing built in for that, you could make a plugin for that or do it through a hook

Ferdinand Beyer07:02:13

Just wanted to come back here to share the quick and dirty solution I came up with, and to say thank you @U07FP7QJ0 for making Kaocha awesome and extensible. I was surprised how easy that was! 💪 Here is the gist of my pre-load hook:

(require '[clojure.java.classpath :as cp])

(defn- classpath-test-paths
  "Finds all 'test' directories on the classpath."
  []
  (into []
        (comp (filter #(= "test" (.getName %)))
              (map #(.getPath %)))
        (cp/classpath-directories)))

(defn pre-load-classpath-test-paths
  "Kaocha pre-load hook to set test-paths from the classpath."
  [config]
  ;; Quick and dirty -- YMMV
  (assoc-in config [:kaocha/tests 0 :kaocha/test-paths] (classpath-test-paths)))

Ferdinand Beyer07:02:15

…and then this line in tests.edn and done:

:kaocha.hooks/pre-load [my.kaocha.hooks/pre-load-classpath-test-paths]

plexus18:02:02

very cool!