diff --git a/deps.edn b/deps.edn index 3aedfb8..071a819 100644 --- a/deps.edn +++ b/deps.edn @@ -6,5 +6,5 @@ {:jvm-opts ["-ea"] :extra-paths ["dev" "test" "fixtures/core_test" "fixtures/keep_test"] :extra-deps - {io.github.tonsky/duti {:git/sha "8c3c6cdff5fbc909db6da4b2711f9ec2e91dcfb1" - #_#_:local/root "/Users/tonsky/ws/duti"}}}}} \ No newline at end of file + {org.clojure/tools.namespace {:mvn/version "1.5.0"} + io.github.tonsky/duti {:git/sha "176d2083dd21b0aa86584c43e944b37e9fd230d1"}}}}} \ No newline at end of file diff --git a/dev/user.clj b/dev/user.clj index f2f5410..8839766 100644 --- a/dev/user.clj +++ b/dev/user.clj @@ -1,11 +1,24 @@ (ns user (:require - [duti.all :as duti])) + [clojure.tools.namespace.repl :as ns] + [clojure.tools.namespace.track :as track] + [duti.core :as duti])) -(duti/set-dirs "src" "dev" "test") +(ns/disable-reload!) -(def reload - duti/reload) +(ns/set-refresh-dirs "src" "dev" "test") + +(defn reload + ([] + (reload nil)) + ([opts] + (set! *warn-on-reflection* true) + (let [tracker (ns/scan opts) + cnt (count (::track/load tracker)) + res (apply ns/refresh-scanned (mapcat vec opts))] + (when (instance? Throwable res) + (throw res)) + (str "Reloaded " cnt " namespace" (when (> cnt 1) "s"))))) (defn -main [& args] (alter-var-root #'*command-line-args* (constantly args)) @@ -13,12 +26,11 @@ (duti/start-socket-repl {:port (some-> port parse-long)}))) (defn test-all [] - (require 'clj-reload.core-test 'clj-reload.keep-test 'clj-reload.parse-test) (reload) (duti/test-throw #"clj-reload\..*-test")) (defn -test-main [_] - (require 'clj-reload.core-test 'clj-reload.keep-test 'clj-reload.parse-test) + (reload) (duti/test-exit #"clj-reload\..*-test")) (comment diff --git a/test/clj_reload/core_test.clj b/test/clj_reload/core_test.clj index 728db86..966462d 100644 --- a/test/clj_reload/core_test.clj +++ b/test/clj_reload/core_test.clj @@ -252,9 +252,11 @@ (is (= [:unload-m :reload-m] @@(resolve 'o/*atom)))) (deftest unload-hook-fail-test - (tu/with-changed 'm #ml "(ns m (:require n o)) - (defn before-ns-unload [] - (/ 1 0))" + (tu/with-changed 'm "(ns m + (:require n o)) + + (defn before-ns-unload [] + (/ 1 0))" (tu/init 'm) (tu/touch 'm) (tu/reload) @@ -264,9 +266,11 @@ (deftest reload-hook-fail-test (tu/init 'm) - (tu/with-changed 'n #ml "(ns n (:require o)) - (defn after-ns-reload [] - (/ 1 0))" + (tu/with-changed 'n "(ns n + (:require o)) + + (defn after-ns-reload [] + (/ 1 0))" (tu/touch 'o) (is (thrown? Exception (tu/reload))) (is (= '["Unloading" m n o "Loading" o n " failed to load" n] (tu/trace)))) @@ -277,10 +281,10 @@ (tu/init 'no-unload) (let [rand1 @(resolve 'no-unload/rand1) rand2 @(resolve 'no-unload/rand2)] - (tu/with-changed 'no-unload #ml "(ns ^:clj-reload/no-unload no-unload) - - (def rand1 - (rand-int Integer/MAX_VALUE))" + (tu/with-changed 'no-unload "(ns ^:clj-reload/no-unload no-unload) + + (def rand1 + (rand-int Integer/MAX_VALUE))" (tu/reload) (let [rand1' @(resolve 'no-unload/rand1) rand2' @(resolve 'no-unload/rand2)] diff --git a/test/clj_reload/keep_test.clj b/test/clj_reload/keep_test.clj index 0caf36d..e4343ed 100644 --- a/test/clj_reload/keep_test.clj +++ b/test/clj_reload/keep_test.clj @@ -41,25 +41,25 @@ "before (def *atom 777) (reset! *atom nil) after" {'(def *atom) "(def *atom 888)"}))) - (is (= #ml "(ns keep) - - asdas - - 8 10 (def *atom 777) - - - (def just-var 888) - " + (is (= "(ns keep) + + asdas + + 8 10 (def *atom 777) + + + (def just-var 888) + " (keep/patch-file - #ml "(ns keep) - - asdas - - 8 10 (defonce *atom - (atom nil)) - - (defonce just-var - (Object.))" + "(ns keep) + + asdas + + 8 10 (defonce *atom + (atom nil)) + + (defonce just-var + (Object.))" {'(defonce *atom) "(def *atom 777)" '(defonce just-var) "(def just-var 888)"})))) diff --git a/test/clj_reload/parse_test.clj b/test/clj_reload/parse_test.clj index 8c6dcd4..55b87a0 100644 --- a/test/clj_reload/parse_test.clj +++ b/test/clj_reload/parse_test.clj @@ -27,29 +27,29 @@ :form (defonce x 1)} y {:tag defprotocol :form (defprotocol y 2)}}}} - (read-str #ml "(ns x - (:require - a.b.c - [a.b.d] - [a.b.e :as e] - [a.b f g] - [a.b [h :as h]] - [a.b.x :as-alias x] - [a.b [y :as-alias y]]) - (:require - a.b.i) - (:use - a.b.j)) - ... - (defonce x 1) - ... - (require 'a.b.k) - (require '[a.b.z :as-alias z]) - ... - ^:clj-reload/keep - (defprotocol y 2) - ... - (use 'a.b.l)"))) + (read-str "(ns x + (:require + a.b.c + [a.b.d] + [a.b.e :as e] + [a.b f g] + [a.b [h :as h]] + [a.b.x :as-alias x] + [a.b [y :as-alias y]]) + (:require + a.b.i) + (:use + a.b.j)) + ... + (defonce x 1) + ... + (require 'a.b.k) + (require '[a.b.z :as-alias z]) + ... + ^:clj-reload/keep + (defprotocol y 2) + ... + (use 'a.b.l)"))) (is (= '{x nil} (read-str "(ns x)"))) @@ -61,11 +61,11 @@ (read-str "(in-ns 'x)")))) (deftest read-file-errors-test - (let [file #ml "(ns x - (:require 123) - (:require [345]) - (:require [567 :as a]) - (:require [789 a b c]))" + (let [file "(ns x + (:require 123) + (:require [345]) + (:require [567 :as a]) + (:require [789 a b c]))" out (StringWriter.) res (binding [*out* out] (read-str file))]