Skip to content

Instantly share code, notes, and snippets.

@erdos
Created September 28, 2018 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erdos/1e2f4b9d4fa551f6a4e55be0ddbf56e3 to your computer and use it in GitHub Desktop.
Save erdos/1e2f4b9d4fa551f6a4e55be0ddbf56e3 to your computer and use it in GitHub Desktop.
make all private vars visible for unit testing
(let [target (the-ns 'testable-namespace)]
(doseq [[k v] (ns-map target)
:when (and (var? v) (= target (.ns v)))]
(eval `(defn ~(symbol (str "-" k)) [~'& args#] (apply (deref ~v) args#)))))
;; Now if testable-namespace has a function valled fun1
;; then i am able call -fun1 from the current namespace.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment