librelist archives

« back to archive

custom test reports

custom test reports

From:
Dmitry Neverov
Date:
2013-08-10 @ 13:18
Hi,

I'm trying to implement an on-the-fly test reporting for leiningen
running inside CI server we use (TeamCity). To do that I need to print
some lines for every test a CI server would recognize, something like
'test started' with a test name, 'test finished', 'test failed' and so
on.

I'm trying to implement that using a hook that wraps
clojure.test/report, but without success so far.

My code goes like this:

(defn add-teamcity-reporting [f & args]
  `(binding [~'clojure.test/report
             (fn [m#]
               (println "custom output")
               ((.getRawRoot #'clojure.test/report) m#))]
     ~(apply f args)))

(defn hooks []
  (robert.hooke/add-hook #'leiningen.test/form-for-testing-namespaces
                         add-teamcity-reporting))

I'm testing it by building core.logic, but every time I run 'lein test'
I get the following error:

Exception in thread "main" java.lang.NullPointerException
        at clojure.core$swap_BANG_.invoke(core.clj:2161)
        at leiningen.core.injected$add_hook.invoke(NO_SOURCE_FILE:1)
        at user$eval37.invoke(NO_SOURCE_FILE:1)
        at clojure.lang.Compiler.eval(Compiler.java:6619)
        at clojure.lang.Compiler.eval(Compiler.java:6609)
        at clojure.lang.Compiler.eval(Compiler.java:6582)
        at clojure.core$eval.invoke(core.clj:2852)
        at clojure.main$eval_opt.invoke(main.clj:308)
        at clojure.main$initialize.invoke(main.clj:327)
        at clojure.main$null_opt.invoke(main.clj:362)
        at clojure.main$main.doInvoke(main.clj:440)
        at clojure.lang.RestFn.invoke(RestFn.java:421)
        at clojure.lang.Var.invoke(Var.java:419)
        at clojure.lang.AFn.applyToHelper(AFn.java:163)
        at clojure.lang.Var.applyTo(Var.java:532)
        at clojure.main.main(main.java:37)

Does that happen because leiningen.test/form-for-testing-namespaces
re-binds clojure.test/report? What's the right way to get custom reports
without writing a separate task?