Missing Metadata when running unit tests

33 views
Skip to first unread message

Adam Krieg

unread,
Feb 24, 2014, 5:34:26 PM2/24/14
to clojure-ma...@googlegroups.com
I'm trying to add some extra metadata on functions defined by users so that I can group them up and run them, ala clojure.test's deftest.  This seems to work from the Repl, but when I run from the maven plugin, it all goes awry.

(ns my.scenario
  (require [clojure.repl :as repl]
           [clojure.test :as test]))


(defn find-tests
  "Examines a namespace and finds all the tests"
  [ns]
  (letfn [(test-symbol? [s]
                        (println (str "symbol = " s " meta = " (meta (resolve s))))
                          (:test (meta (resolve s))))]
  (for [s (repl/dir-fn ns) :when (test-symbol? s)]
    s)))



And my test is:

(ns my.scenario-test
  (require [clojure.test :as test]
           [my.scenario :as scenario]))


;Some other non-test function
(defn not-a-test [])

;Tests that we can lookup all tests defined for a namespace
(test/deftest query-namespace
  (println (str "namespace " *ns*))
  (test/is (= 1
              (count (scenario/find-scenarios 'my.scenario-test)))))

When I run it locally, I see the output:

namespace my.scenario-test
symbol = not-a-test meta = {:ns #<Namespace my.scenario-test>, :name not-a-test,clojure/my/scenario_test.clj", :column 1, :line 7, :arglists ([])}
symbol = query-namespace meta = {:ns #<Namespace my.scenario-test>, :name query-namespace, :file "clojure/my/scenario_test.clj", :column 1, :line 14, :test #<scenario_test$fn__3699 my.scenario_test$fn__3699@d9a68cd>}
query-namespace)

When I run it in Maven with the Clojure Maven plugin, I see the output:
namespace com.theoryinpractise.clojure.testrunner
symbol = not-a-test meta = 
symbol = query-namespace meta = 

Why is the metadata stripped off the symbols?

Ben Smith-Mannschott

unread,
Feb 25, 2014, 4:08:36 AM2/25/14
to clojure-ma...@googlegroups.com
i would expect to find the metadata on the var, not the symbol. 

--
This message was sent via electromagnetism.
--
 
---
You received this message because you are subscribed to the Google Groups "Clojure Maven Plugin" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure-maven-pl...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Mark Derricutt

unread,
Feb 25, 2014, 5:19:21 AM2/25/14
to clojure-ma...@googlegroups.com

I would suspect that (resolve) would return the var.

I've not tried it yet - but I suspect we're falling into AOT issues here with the code being compiled in test-compile and being run separately in the test phase.

I assume meta-data is only retained at run-time and not compiled into the AOT classes anywhere.

Mark

signature.asc
Reply all
Reply to author
Forward
0 new messages