Re: What's the best way to test private functions?

2011-07-17 Thread Matthew Boston
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

Re: What's the best way to test private functions?

2011-07-16 Thread Benjamin Esham
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

Re: What's the best way to test private functions?

2011-06-27 Thread Stephen C. Gilardi
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

Re: What's the best way to test private functions?

2011-06-27 Thread Ken Wesson
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

Re: What's the best way to test private functions?

2011-06-18 Thread Stuart Halloway
(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

Re: What's the best way to test private functions?

2011-06-18 Thread Ken Wesson
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

What's the best way to test private functions?

2011-06-17 Thread Benjamin Esham
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

Re: What's the best way to test private functions?

2011-06-17 Thread Tassilo Horn
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

Re: What's the best way to test private functions?

2011-06-17 Thread Brian Marick
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

Re: What's the best way to test private functions?

2011-06-17 Thread Jonathan Fischer Friberg
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

Re: What's the best way to test private functions?

2011-06-17 Thread Alex Baranosky
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