* Fix #1688: use-fixtures should add metadata to *ns* * fix test
This commit is contained in:
parent
ba35032253
commit
b47a5cc21d
3 changed files with 19 additions and 12 deletions
|
|
@ -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
|
[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)
|
## 1.3.190 (2024-04-17)
|
||||||
|
|
||||||
- Fix [#1679](https://github.com/babashka/babashka/issues/1679): bump timbre and fix wrapping `timbre/log!`
|
- Fix [#1679](https://github.com/babashka/babashka/issues/1679): bump timbre and fix wrapping `timbre/log!`
|
||||||
|
|
|
||||||
|
|
@ -660,14 +660,12 @@
|
||||||
|
|
||||||
;;; DEFINING FIXTURES
|
;;; DEFINING FIXTURES
|
||||||
|
|
||||||
(def ^:private ns->fixtures (atom {}))
|
|
||||||
|
|
||||||
(defn- add-ns-meta
|
(defn- add-ns-meta
|
||||||
"Adds elements in coll to the current namespace metadata as the
|
"Adds elements in coll to the current namespace metadata as the
|
||||||
value of key."
|
value of key."
|
||||||
{:added "1.1"}
|
{:added "1.1"}
|
||||||
[key coll]
|
[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
|
(defmulti use-fixtures
|
||||||
"Wrap test runs in a fixture function to perform setup and
|
"Wrap test runs in a fixture function to perform setup and
|
||||||
|
|
@ -677,10 +675,10 @@
|
||||||
(fn [fixture-type & args] fixture-type))
|
(fn [fixture-type & args] fixture-type))
|
||||||
|
|
||||||
(defmethod use-fixtures :each [fixture-type & args]
|
(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]
|
(defmethod use-fixtures :once [fixture-type & args]
|
||||||
(add-ns-meta ::once-fixtures args))
|
(add-ns-meta :clojure.test/once-fixtures args))
|
||||||
|
|
||||||
(defn- default-fixture
|
(defn- default-fixture
|
||||||
"The default, empty, fixture function. Just calls its argument."
|
"The default, empty, fixture function. Just calls its argument."
|
||||||
|
|
@ -731,10 +729,8 @@
|
||||||
[vars]
|
[vars]
|
||||||
(doseq [[ns vars] (group-by (comp :ns meta) vars)
|
(doseq [[ns vars] (group-by (comp :ns meta) vars)
|
||||||
:when ns]
|
:when ns]
|
||||||
(let [ns-name (sci-namespaces/sci-ns-name ns)
|
(let [once-fixture-fn (join-fixtures (:clojure.test/once-fixtures (meta ns)))
|
||||||
fixtures (get @ns->fixtures ns-name)
|
each-fixture-fn (join-fixtures (:clojure.test/each-fixtures (meta ns)))]
|
||||||
once-fixture-fn (join-fixtures (::once-fixtures fixtures))
|
|
||||||
each-fixture-fn (join-fixtures (::each-fixtures fixtures))]
|
|
||||||
(once-fixture-fn
|
(once-fixture-fn
|
||||||
(fn []
|
(fn []
|
||||||
(doseq [v vars]
|
(doseq [v vars]
|
||||||
|
|
|
||||||
|
|
@ -37,8 +37,12 @@
|
||||||
(deftest fixtures-test
|
(deftest fixtures-test
|
||||||
(let [output (bb "
|
(let [output (bb "
|
||||||
(require '[clojure.test :as t])
|
(require '[clojure.test :as t])
|
||||||
(defn once [f] (prn :once-before) (f) (prn :once-after))
|
(defn once [f] (prn :once-before) (f)
|
||||||
(defn each [f] (prn :each-before) (f) (prn :each-after))
|
(prn :once-after)
|
||||||
|
(prn (some? (::t/once-fixtures (meta *ns*)))))
|
||||||
|
|
||||||
|
(defn each [f] (prn :each-before) (f) (prn :each-after)
|
||||||
|
(prn (some? (::t/each-fixtures (meta *ns*)))))
|
||||||
(t/use-fixtures :once once)
|
(t/use-fixtures :once once)
|
||||||
(t/use-fixtures :each each)
|
(t/use-fixtures :each each)
|
||||||
(t/deftest foo)
|
(t/deftest foo)
|
||||||
|
|
@ -48,9 +52,12 @@
|
||||||
:once-before
|
:once-before
|
||||||
:each-before
|
:each-before
|
||||||
:each-after
|
:each-after
|
||||||
|
true
|
||||||
:each-before
|
:each-before
|
||||||
:each-after
|
:each-after
|
||||||
:once-after")))))
|
true
|
||||||
|
:once-after
|
||||||
|
true")))))
|
||||||
|
|
||||||
(deftest with-test
|
(deftest with-test
|
||||||
(let [output (bb "
|
(let [output (bb "
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue