Skip to content

Commit fa5483a

Browse files
Raynesstuarthalloway
authored andcommitted
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. Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
1 parent 70ea978 commit fa5483a

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/clj/clojure/test.clj

+15-8
Original file line numberDiff line numberDiff line change
@@ -707,17 +707,24 @@
707707
:expected nil, :actual e})))
708708
(do-report {:type :end-test-var, :var v}))))
709709

710+
(defn test-vars
711+
"Groups vars by their namespace and runs test-vars on them with
712+
appropriate fixtures applied."
713+
{:added "1.5"}
714+
[vars]
715+
(doseq [[ns vars] (group-by (comp :ns meta) vars)]
716+
(let [once-fixture-fn (join-fixtures (::once-fixtures (meta ns)))
717+
each-fixture-fn (join-fixtures (::each-fixtures (meta ns)))]
718+
(once-fixture-fn
719+
(fn []
720+
(doseq [v vars]
721+
(each-fixture-fn (fn [] (test-var v)))))))))
722+
710723
(defn test-all-vars
711-
"Calls test-var on every var interned in the namespace, with fixtures."
724+
"Calls test-vars on every var interned in the namespace, with fixtures."
712725
{:added "1.1"}
713726
[ns]
714-
(let [once-fixture-fn (join-fixtures (::once-fixtures (meta ns)))
715-
each-fixture-fn (join-fixtures (::each-fixtures (meta ns)))]
716-
(once-fixture-fn
717-
(fn []
718-
(doseq [v (vals (ns-interns ns))]
719-
(when (:test (meta v))
720-
(each-fixture-fn (fn [] (test-var v)))))))))
727+
(test-vars (vals (ns-interns ns))))
721728

722729
(defn test-ns
723730
"If the namespace defines a function named test-ns-hook, calls that.

0 commit comments

Comments
 (0)