Skip to content

Commit

Permalink
Add prn messages
Browse files Browse the repository at this point in the history
  • Loading branch information
weavejester committed Dec 6, 2024
1 parent ee4fe6d commit a0785f4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/duct/repl/refers.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
(require ns-sym)
(if (= alias name-sym)
(refer ns-sym :only [name-sym])
(refer ns-sym :only [name-sym] :rename {name-sym alias}))))))
(refer ns-sym :only [name-sym] :rename {name-sym alias})))))
(when-some [syms (seq (keys refers))]
(prn (keyword (str ns-sym) "added") syms)))

(defn- remove-refers [ns-sym refers]
(let [ns (find-ns ns-sym)]
(doseq [[alias sym] refers]
(when (identical? (resolve sym) (ns-resolve ns alias))
(ns-unmap ns alias)))))
(ns-unmap ns alias))))
(when-some [syms (seq (keys refers))]
(prn (keyword (str ns-sym) "removed") syms)))

(defn- identical-kvs [m1 m2]
(reduce-kv (fn [m k v] (if (= v (m2 k ::miss)) (assoc m k v) m))
Expand Down
9 changes: 9 additions & 0 deletions test/duct/repl/refers_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,12 @@
(is (= {'ret-one `return-one} refers'))
(is (= 1 ((ns-resolve ns 'ret-one))))
(is (nil? (ns-resolve ns 'return-two))))))

(deftest test-prn-output
(is (= (str ":user/added (ret-one return-two)\n"
":user/removed (ret-one return-two)\n")
(with-out-str
(let [refers (ig/init-key :duct.repl/refers
{'ret-one `return-one
'return-two `return-two})]
(ig/halt-key! :duct.repl/refers refers))))))

0 comments on commit a0785f4

Please sign in to comment.