kaocha

Ferdinand Beyer 2022-02-15T09:00:58.069009Z

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.

plexus 2022-02-15T14:14:45.212419Z

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

Ferdinand Beyer 2022-02-15T16:24:12.762719Z

OK, thanks!

Ferdinand Beyer 2022-02-16T07:29:13.685679Z

Just wanted to come back here to share the quick and dirty solution I came up with, and to say thank you @plexus 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 Beyer 2022-02-16T07:30:15.624329Z

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

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

plexus 2022-02-16T18:21:02.899049Z

very cool!