Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Autotest #131

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/kaocha/assertions.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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))))
Expand Down
68 changes: 62 additions & 6 deletions src/kaocha/watch.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -147,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.

Expand All @@ -155,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)]
Expand All @@ -167,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
Expand All @@ -178,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 #{}
Expand Down Expand Up @@ -232,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)

)



2 changes: 1 addition & 1 deletion tests.edn
Original file line number Diff line number Diff line change
Expand Up @@ -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]}