On Sun, Aug 29, 2010 at 5:27 PM, Sean Corfield <seancorfi...@gmail.com> wrote: > So I thought I'd see if I could use tests in source code and add a > hook to lein to bind *load-tests* to false around the compile but I'm > missing something... > > (defn no-tests [task & args] > (binding [clojure.test/*load-tests* false] > (apply task args))) > > (add-hook #'leiningen.compile/compile no-tests) > > What am I missing?
You're very close. If the tests ran in the same JVM as Leiningen, this would work. However, Leiningen has to spawn another JVM in order to avoid contamination. Leiningen uses the leiningen.test/form-for-testing-namespaces function to return a form that's evaled in the project's JVM. You would have to add a hook to wrap that form in a binding call: (defn add-load-tests-binding [f & args] `(binding [clojure.test/*load-tests* false] ~(apply f args))) (add-hook #'leiningen.test/form-for-testing-namespaces add-load-tests-binding) The problem is that doesn't quite work because clojure.test isn't loaded in your project JVM yet. And you can't just require it right before you bind it either, since you can't compile a form that loads a var and includes it at compile-time either; the var must exist at compile-time. This is why you see the use of ns-resolve in form-for-testing-namespaces--that way the var doesn't need to be loaded at compile time. I'm not sure if there's a way around it aside from nesting evals. Anyone else have an idea? -Phil -- 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