Skip to content

Instantly share code, notes, and snippets.

@weissjeffm
Created November 23, 2010 17:20
Show Gist options
  • Save weissjeffm/712134 to your computer and use it in GitHub Desktop.
Save weissjeffm/712134 to your computer and use it in GitHub Desktop.
trying to produce a call to gen-class with annotations put in place (pulled from the metadata of the fn)
(defn method-name [f]
(str (:name (meta f))))
(defn group-ann-val [t]
(->> (meta t) :groups (map name) (into [])))
(defn as-annotation [t]
{(if (configuration? t) (-> (configuration t) (testng-map)) Test)
{:groups (group-ann-val t)}})
(defmacro gen-classes [namespace]
(let [publics (vals (ns-publics namespace))
tests (filter test? publics)
methods (map (fn [test] (let [name (method-name test)]
`[~(with-meta (symbol name) (as-annotation test)) [] ~'void])) tests)]
`(gen-class :prefix "" :name ~(symbol (namespace-munge namespace)) :methods [~@methods])))
(comment "This is the expansion of the above macro (with *print-meta*)"
(clojure.core/gen-class
:prefix
""
:name
test_clj.sample_tests
:methods
[[^{org.testng.annotations.BeforeMethod {:groups []}} config5 [] void]
[^{org.testng.annotations.Test {:groups []}} test4 [] void]
[^{org.testng.annotations.AfterMethod {:groups []}} config6 [] void]
[^{org.testng.annotations.Test {:groups []}} test2 [] void]
[^{org.testng.annotations.Test {:groups []}} test3 [] void]
[^{org.testng.annotations.Test {:groups []}} test1 [] void]
[^{org.testng.annotations.BeforeSuite {:groups []}} config1
[]
void]])
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment