Hi!

I've written a macro to generate tests for functions that have the ":_test" 
key in their metadata. I know that clojure.test automatically runs tests 
associated with ":test" keys, but I'd like to implement my own test-case 
generation.

Here' what it looks like:

(defn my-last
  "P01 (*) Find the last box of a list."
  { :_test '(= (my-last '(a b c d)) 'd) }

  [lst]
  (if (<= (count lst) 1)
    (first lst)
    (recur (rest lst))))

(defmacro gen-tests []
  `(do ~@(for [f (map first (ns-publics *ns*)) :when (:_test (meta 
(ns-resolve *ns* (symbol f))))]
          `(clojure.test/deftest ~(symbol (str f '-test)) (clojure.test/is 
~(:_test (meta (ns-resolve *ns* (symbol f)))))))))

The gen-tests macro basically enumerates all publics in the current 
namespace and generates a 'deftest' declaration for each function that 
contains the ":_test" key in its metadata.

I'm sure there exists more reasonable and idiomatic way to do the same 
thing. Specifically, I'd really like to remove the repeating "(:_test (meta 
...)" part, but I wasn't able to come up with the solution myself.

Any help will be appreciated. Thanks!

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