Hi Allen, Stu,

I guess my first inclination would be one of:
> 1) put the unit tests in the same file
using the with-test macro, or
> 2) put the unit tests in a separate file, in the same namespace

Stu's suggestion of with-ns would also work.  But you don't even need
with-ns.  You can refer a private function into the local namespace
like this:

(def private-function (ns-resolve 'other-namespace 'private-function))

You could even write a function that refers all the private symbols of
a namespace:

(defn refer-private [ns]
  (doseq [[symbol var] (ns-interns ns)]
    (when (:private (meta var))
      (intern *ns* symbol var))))

This is slightly evil, and I would never recommend it for any purpose
except unit testing, but there it is.

-Stuart Sierra


On Wed, Jun 3, 2009 at 12:36 AM, Stuart Halloway
<stuart.hallo...@gmail.com> wrote:
> Hi Allen,
>
> You could write a function that uses the clojure.contrib.with-ns/with-ns
> macro to dip into the namespace being tested and return the private
> function, assigning it to a local name in the test namespace.
>
> I need this too, and have been meaning to ping the other Stuart about either
> (a) adding something like this to test-is, or (b) creating a new
> test-helpers library in contrib that would include this function.
>
> Stu
>
>>
>> I have a namespace with some public functions, and some private
>> functions. I would like to write unit tests for the functions, and put
>> them in a separate file from the main name space. I would also like to
>> have an (ns) declaration in my tests file, because the tests require
>> several libraries. Of course, if I have private methods in namespace
>> A, I can't call them from namespace B. Right now, it seems I have
>> several options:
>>
>> 1) put the unit tests in the same file
>> 2) put the unit tests in a separate file, in the same namespace
>> 3) make the private functions public
>> 4) ???
>>
>> I don't really like the first three options. Ideally, the private
>> functions would remain private to every namespace except the testing
>> name space. Is there a good solution for this?
>>
>> Allen
>>
>> >>
>
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to