Hi All,

I'm trying to test some private functions using the Clojure convention of 
placing tests in a separate test- namespace.  Of course, you can't reference 
private vars from other namespaces (please correct me if I'm wrong).  Not 
knowing anything at all about how stuff is interned in Clojure, I found this 
blog post:  
http://formpluslogic.blogspot.com/2009/08/clojure-unit-testing-part-1.html.  
Using ns-resolve works.

I'm trying to generalize it into a macro named use-private

(defmacro
  #^{:private true}
  use-private
  [ns sym]
  `(def
     #^{:private true}
     ~sym (ns-resolve ~ns ~sym)))

This, however, doesn't work.  The first ~sym macroexpands to (quote sym), which 
cannot be passed as a name to def.  An exception is thrown saying that the 
first argument must be a symbol, and this is because, I assume, that the quote 
form is a form.  So...

Is there a better way the community has found to test private functions?
Is there a way to reference private functions from a test- namespace?  Is there 
some proposal floating around to allow this?
Is there a better approach than my ghetto macro, outside of extending the core 
language and libraries?
In my ghetto macro, how do I get the sym arg to macroexpand to just the sym and 
not a quote form?

Thanks,
Johnny

-- 
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