Hi, This is a problem I was working on this morning (with the help of
chouser, thank you!), and ended up with a 'with-private-fns' macro that
works like this:

(with-private-fns [org.foo.bar [fn1 fn2]]
  (deftest test-fn1..)
  (deftest test-fn2..))

I'm a Clojure greenhorn, but I like this approach because my private fn
tests are consolidated.  I think in the end thought it boils down to a
matter of personal style :)

The macro itself looks like this:

(defmacro with-private-fns [[ns fns] & tests]
  "Refers private fns from ns and runs tests in context."
    `(let ~(reduce #(conj %1 %2 `(ns-resolve '~ns '~%2)) [] fns)
         ~...@tests))

A test file making use of it can be found here:
http://github.com/alandipert/clj-utils/blob/master/test/org/dipert/utils/test/math.clj

Cheers,
Alan

Excerpts from Meikel Brandmeyer's message of 2010-02-22 07:08:59 -0500:
> Hi,
> 
> On Feb 22, 11:55 am, Johnny Kwan <johnny.c.k...@gmail.com> wrote:
> 
> > You're absolutely right.  I use 'ns and 'sym because that's what all of the 
> > ns- functions use.  I realize now that this is a macro, not a fn...  :)  I 
> > would like to make the fact that this is a macro transparent, so that it 
> > only accepts symbol arguments.  The caller shouldn't have to know that this 
> > is a macro.
> 
> Here we go:
> 
> (defmacro #^{:private true} use-private
>   [ns sym]
>   `(def ~(with-meta (second sym) {:private true}) @(ns-resolve ~ns
> ~sym)))
> 
> Not tested, though, but should come close.
> 
> > > Use @#'foo.bar/private-fn. Or...
> >
> > Thanks!
> 
> This feels a little hacky, however.
> 
> > That's what I figured, since the few library implementations I've read seem 
> > to do that.  I assume there's a way to remove these namespaces from 
> > generated docs, so there's at least some obfuscation?
> 
> I'd say, that depends on what you use (and how you use it) to generate
> the documentation.
> 
> Sincerely
> Meikel
> 

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