From 246fc10e96184362f7359714bb2f0fe3dc710699 Mon Sep 17 00:00:00 2001 From: Anthony Grimes Date: Mon, 22 Oct 2012 17:54:26 -0500 Subject: [PATCH] CLJ-866: Provide a function for running specific tests with fixtures. Adds a new function, test-vars, that takes vars and groups them by namespace and then runs them with appropriate fixtures for the namespace those vars came from. It allows vars from different namespaces to be run without mixing fixtures. --- src/clj/clojure/test.clj | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/clj/clojure/test.clj b/src/clj/clojure/test.clj index a393b4f..1b53fcf 100644 --- a/src/clj/clojure/test.clj +++ b/src/clj/clojure/test.clj @@ -704,17 +704,24 @@ :expected nil, :actual e}))) (do-report {:type :end-test-var, :var v})))) +(defn test-vars + "Groups vars by their namespace and runs test-vars on them with + appropriate fixtures applied." + {:added "1.5"} + [vars] + (doseq [[ns vars] (group-by (comp :ns meta) vars)] + (let [once-fixture-fn (join-fixtures (::once-fixtures (meta ns))) + each-fixture-fn (join-fixtures (::each-fixtures (meta ns)))] + (once-fixture-fn + (fn [] + (doseq [v vars] + (each-fixture-fn (fn [] (test-var v))))))))) + (defn test-all-vars - "Calls test-var on every var interned in the namespace, with fixtures." + "Calls test-vars on every var interned in the namespace, with fixtures." {:added "1.1"} [ns] - (let [once-fixture-fn (join-fixtures (::once-fixtures (meta ns))) - each-fixture-fn (join-fixtures (::each-fixtures (meta ns)))] - (once-fixture-fn - (fn [] - (doseq [v (vals (ns-interns ns))] - (when (:test (meta v)) - (each-fixture-fn (fn [] (test-var v))))))))) + (test-vars (vals (ns-interns ns)))) (defn test-ns "If the namespace defines a function named test-ns-hook, calls that. -- 1.8.0