From 0a2d2d9e329fe1286b2bd30955a66114b85685cf Mon Sep 17 00:00:00 2001 From: Arne Brasseur Date: Mon, 20 Jan 2020 07:35:55 +0000 Subject: [PATCH 1/2] Address some reflection warnings --- src/kaocha/assertions.clj | 2 +- src/kaocha/watch.clj | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/kaocha/assertions.clj b/src/kaocha/assertions.clj index 674243e4..5c371a1c 100644 --- a/src/kaocha/assertions.clj +++ b/src/kaocha/assertions.clj @@ -21,7 +21,7 @@ (defn longest-substring [s1 s2] (transduce (comp (map #(subs s1 0 (inc %))) - (take-while #(.contains s2 %))) + (take-while #(.contains ^String s2 %))) x-last nil (range (count s1)))) diff --git a/src/kaocha/watch.clj b/src/kaocha/watch.clj index f08ab72e..0b5c2b13 100644 --- a/src/kaocha/watch.clj +++ b/src/kaocha/watch.clj @@ -20,9 +20,11 @@ [lambdaisland.tools.namespace.reload :as ctn-reload] [lambdaisland.tools.namespace.track :as ctn-track] [clojure.stacktrace :as st]) - (:import [java.nio.file FileSystems] + (:import [java.nio.file FileSystems PathMatcher] [java.util.concurrent ArrayBlockingQueue BlockingQueue])) +(set! *warn-on-reflection* true) + (defn make-queue [] (ArrayBlockingQueue. 1024)) @@ -84,12 +86,12 @@ [path patterns] (let [fs (FileSystems/getDefault) patterns (map #(.getPathMatcher fs (str "glob:" %)) patterns)] - (some #(.matches % path) patterns))) + (some #(.matches ^PathMatcher % path) patterns))) (defn wait-and-rescan! [q tracker watch-paths ignore] (let [f (qtake q)] (cond - (and (file? f) (glob? (.toPath f) ignore)) + (and (file? f) (glob? (.toPath ^java.io.File f) ignore)) (recur q tracker watch-paths ignore) (directory? f) From a188e7519af5ee44f9a7ba61f72c9408f54e7cda Mon Sep 17 00:00:00 2001 From: Arne Brasseur Date: Mon, 20 Jan 2020 07:37:16 +0000 Subject: [PATCH 2/2] WIP: implement autotest, pairing with Art Semyonov See https://nextjournal.com/lambdaisland/kaocha-autotest Co-authored-by: Art Semyonov --- src/kaocha/watch.clj | 60 +++++++++++++++++++++++++++++++++++++++++--- tests.edn | 2 +- 2 files changed, 58 insertions(+), 4 deletions(-) diff --git a/src/kaocha/watch.clj b/src/kaocha/watch.clj index 0b5c2b13..99dc382c 100644 --- a/src/kaocha/watch.clj +++ b/src/kaocha/watch.clj @@ -149,6 +149,15 @@ (map ::testable/id)))] (recur tracker config plugin-chain focus))))))) + +(defn- focus-changed-namespaces [tests candidates] + (map (fn [t] + (if (contains? candidates (:kaocha.ns/name t)) + t + (assoc t :kaocha.testable/skip true))) + tests)) + + (defplugin kaocha.watch/plugin "This is an internal plugin, don't use it directly. @@ -157,8 +166,11 @@ care of reloading namespaces inside a Kaocha run, so we can report any load errors as test errors." (pre-load [{::keys [tracker focus] :as config}] (print-scheduled-operations! tracker focus) - (let [tracker (track-reload! tracker) - config (assoc config ::tracker tracker) + (let [loaded (::ctn-track/load tracker) + tracker (track-reload! tracker) + config (assoc config + ::tracker tracker + ::loaded loaded) error (::ctn-reload/error tracker) error-ns (::ctn-reload/error-ns tracker) load-error (::ctn-file/load-error tracker)] @@ -169,6 +181,14 @@ errors as test errors." (partial map (fn [t] (assoc t :kaocha.testable/skip true))))) config))) + (pre-run [{::keys [only-run-changed? loaded] + :as test-plan}] + (let [candidates (set loaded)] + (update test-plan :kaocha.test-plan/tests + (fn [suites] + (for [suite suites] + (update suite :kaocha.test-plan/tests focus-changed-namespaces candidates)))))) + (pre-test [test test-plan] (if-let [error (::error test-plan)] (do @@ -180,7 +200,10 @@ errors as test errors." :kaocha.result/count 1 :kaocha.result/error 1 ::testable/skip-remaining? true)) - test))) + test)) + + + ) (defn watch-paths [config] (into #{} @@ -234,3 +257,34 @@ errors as test errors." (finally (println "[watch] watching stopped."))))] [exit-code finish!])) + + +(comment + + (require 'kaocha.repl) + (def config (kaocha.repl/config)) + + (def paths (watch-paths config)) + + (def tracker (-> (ctn-track/tracker) + (ctn-dir/scan-dirs paths) + (dissoc :lambdaisland.tools.namespace.track/unload + :lambdaisland.tools.namespace.track/load))) + + (select-keys (ctn-dir/scan-dirs tracker paths) + [:lambdaisland.tools.namespace.track/unload + :lambdaisland.tools.namespace.track/load]) + ;; , e e + ;; C-M-x + ;; , e p + + (kaocha.repl/test-plan {:kaocha.filter/focus [:kaocha.watch-test]}) + + + ;; - run changed tests (or dependency changed) first + ;; - run only changed tests (or dependency changed) + + ) + + + diff --git a/tests.edn b/tests.edn index 422094db..a14a1dd9 100644 --- a/tests.edn +++ b/tests.edn @@ -13,5 +13,5 @@ :test-paths ["test/shared" "test/features"] :cucumber/glue-paths ["test/step_definitions"]}] - + ;; :kaocha.watch/only-run-changed? true :kaocha.hooks/pre-load [kaocha.assertions/load-assertions]}