Fork me on GitHub
#kaocha
<
2020-01-23
>
plexus08:01:27

@edenferreira

#kaocha/v1
{:plugins [:kaocha.plugin/hooks]

 :tests [{:id           :unit
          :source-paths ["checkouts/**/src"]
          :test-paths   ["test"]}]

 :kaocha.hooks/pre-load [my.kaocha.hooks/expand-globs]}
(ns my.kaocha.hooks
  (:import [java.nio.file Files Path FileSystems])
  (:require [ :as io]
            [clojure.string :as str]))

(defn fs []
  (FileSystems/getDefault))

(defn path [s]
  (.getPath (fs) s (into-array String [])))

(defn glob-matcher [glob]
  (.getPathMatcher (fs) (str "glob:" glob)))

(defn glob-scan [glob]
  (let [glob (glob-matcher glob)]
    (->> (io/file ".")
         file-seq
         (filter #(.matches glob (path (str/replace (str %) #"^\./" ""))))
         (map str))))

(defn expand-globs [config]
  (update config :kaocha/tests
          (partial map
                   (fn [suite]
                     (-> suite
                         (update :kaocha/source-paths (partial mapcat glob-scan))
                         (update :kaocha/test-paths (partial mapcat glob-scan)))))))

plexus08:01:02

it's a little involved because doing glob patterns in java is :poop: , but there you have it

plexus08:01:10

It also seems the hooks plugin does not as of yet support config hooks, that's an oversight, that's why I'm using a pre-load hook instead. I'll add config hooks in the next release.

plexus17:01:21

[lambdaisland/kaocha-boot "0.0-20"] is out with this fix https://github.com/lambdaisland/kaocha-boot/pull/3. Thanks @jffry !

❤️ 4