Fix #1688: use-fixtures should add metadata to *ns*

This commit is contained in:
Michiel Borkent 2024-04-28 15:49:14 +02:00
parent ba35032253
commit d4691a999e
3 changed files with 16 additions and 11 deletions

View file

@ -7,6 +7,10 @@ A preview of the next release can be installed from
[Babashka](https://github.com/babashka/babashka): Native, fast starting Clojure interpreter for scripting
## Unreleased
- Fix [#1688](https://github.com/babashka/babashka/issues/1688): use-fixtures should add metadata to `*ns*`
## 1.3.190 (2024-04-17)
- Fix [#1679](https://github.com/babashka/babashka/issues/1679): bump timbre and fix wrapping `timbre/log!`

View file

@ -660,14 +660,12 @@
;;; DEFINING FIXTURES
(def ^:private ns->fixtures (atom {}))
(defn- add-ns-meta
"Adds elements in coll to the current namespace metadata as the
value of key."
{:added "1.1"}
[key coll]
(swap! ns->fixtures assoc-in [(sci-namespaces/sci-ns-name @sci/ns) key] coll))
(alter-meta! @sci/ns assoc key coll))
(defmulti use-fixtures
"Wrap test runs in a fixture function to perform setup and
@ -677,10 +675,10 @@
(fn [fixture-type & args] fixture-type))
(defmethod use-fixtures :each [fixture-type & args]
(add-ns-meta ::each-fixtures args))
(add-ns-meta :clojure.test/each-fixtures args))
(defmethod use-fixtures :once [fixture-type & args]
(add-ns-meta ::once-fixtures args))
(add-ns-meta :clojure.test/once-fixtures args))
(defn- default-fixture
"The default, empty, fixture function. Just calls its argument."
@ -731,10 +729,8 @@
[vars]
(doseq [[ns vars] (group-by (comp :ns meta) vars)
:when ns]
(let [ns-name (sci-namespaces/sci-ns-name ns)
fixtures (get @ns->fixtures ns-name)
once-fixture-fn (join-fixtures (::once-fixtures fixtures))
each-fixture-fn (join-fixtures (::each-fixtures fixtures))]
(let [once-fixture-fn (join-fixtures (:clojure.test/once-fixtures (meta ns)))
each-fixture-fn (join-fixtures (:clojure.test/each-fixtures (meta ns)))]
(once-fixture-fn
(fn []
(doseq [v vars]

View file

@ -43,14 +43,19 @@
(t/use-fixtures :each each)
(t/deftest foo)
(t/deftest bar)
(t/run-tests)")]
(t/run-tests)
(prn (some? (::t/each-fixtures (meta *ns*))))
(prn (some? (::t/once-fixtures (meta *ns*))))")]
(println output)
(is (str/includes? output (str/trim "
:once-before
:each-before
:each-after
:each-before
:each-after
:once-after")))))
:once-after
true
true")))))
(deftest with-test
(let [output (bb "