A good pattern to follow would be to have your exposed functions in
one clj file and any dependent functions (your private ones in this
case) in a separate ns (i.e. separate clj file). This hides the
implementation to the caller as well as gives them a good idea of the
functions they're able to
Brian Marick wrote:
Benjamin Esham wrote:
I am writing a library [1] which has only one function that should be
exposed to users. I'd like to be able to test all of the other
functions, which are marked private with defn-. Of course, these
functions are inaccessible from the testing
On Jun 18, 2011, at 7:16 AM, Stuart Halloway wrote:
To access a private var, simply deref through the var:
@#'some-ns/some-private-var
As Rich noted here: http://groups.google.com/group/clojure/msg/513367afb934d41b
, when the var names a function and it's used in an expression emitted from
On Mon, Jun 27, 2011 at 2:13 AM, Stephen C. Gilardi squee...@mac.com wrote:
As Rich noted
here: http://groups.google.com/group/clojure/msg/513367afb934d41b , when the
var names a function and it's used in an expression emitted from a
macro, prefer invoking the var:
(#'some-ns/some-private-var
(defn refer-private [ns]
(doseq [[symbol var] (ns-interns ns)]
(when (:private (meta var))
(intern *ns* symbol var
As he says, this is slightly evil, and I would never recommend it for
any purpose except unit testing, but there it is. This works, and the
On Sat, Jun 18, 2011 at 7:16 AM, Stuart Halloway
stuart.hallo...@gmail.com wrote:
To access a private var, simply deref through the var:
@#'some-ns/some-private-var
This is in the coding standards doc
(http://dev.clojure.org/display/design/Library+Coding+Standards). The doc is
pretty short
Hi all,
I am writing a library [1] which has only one function that should be
exposed to users. I'd like to be able to test all of the other functions,
which are marked private with defn-. Of course, these functions are
inaccessible from the testing namespace (I'm using the testing boilerplate
Benjamin Esham bdes...@gmail.com writes:
Hi Benjamin,
(defn refer-private [ns]
(doseq [[symbol var] (ns-interns ns)]
(when (:private (meta var))
(intern *ns* symbol var
As he says, this is slightly evil, and I would never recommend it for
any purpose
On Jun 17, 2011, at 1:21 PM, Benjamin Esham wrote:
I am writing a library [1] which has only one function that should be
exposed to users. I'd like to be able to test all of the other functions,
which are marked private with defn-. Of course, these functions are
inaccessible from the testing
If you're in a repl*, why not simply use (in-ns namespace) ?
Of course, this wont work in all cases (e.g. testing private functions from
two different namespaces).
In that case, I find it simpler to remove the '-' temporary. When you're
finished, it really doesn't take that much effort to add them
The best way to test private methods is to have very few of them. Test the
ones you do have via the public API, and if you have too many then IMHO they
should be public methods in a separate namespace. Separate the two
namespaces by responsibility. I do this all the time on OOP languages, and
11 matches
Mail list logo