Skip to content

Commit

Permalink
Dev profile: bumped duti, explicitly depend on tools.namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
tonsky committed Feb 29, 2024
1 parent 0a082e9 commit 6f9f3fe
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 64 deletions.
4 changes: 2 additions & 2 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -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"}}}}}
{org.clojure/tools.namespace {:mvn/version "1.5.0"}
io.github.tonsky/duti {:git/sha "176d2083dd21b0aa86584c43e944b37e9fd230d1"}}}}}
24 changes: 18 additions & 6 deletions dev/user.clj
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
(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))
(let [{port "--port"} args]
(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
Expand Down
24 changes: 14 additions & 10 deletions test/clj_reload/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))))
Expand All @@ -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)]
Expand Down
36 changes: 18 additions & 18 deletions test/clj_reload/keep_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)"}))))

Expand Down
56 changes: 28 additions & 28 deletions test/clj_reload/parse_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)")))
Expand All @@ -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))]
Expand Down

0 comments on commit 6f9f3fe

Please sign in to comment.