diff --git a/CHANGELOG.md b/CHANGELOG.md index c6482d71..e14a587f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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!` diff --git a/src/babashka/impl/clojure/test.clj b/src/babashka/impl/clojure/test.clj index 9767aef3..05d01dba 100644 --- a/src/babashka/impl/clojure/test.clj +++ b/src/babashka/impl/clojure/test.clj @@ -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] diff --git a/test/babashka/test_test.clj b/test/babashka/test_test.clj index b0ad6da5..0f4c6cdc 100644 --- a/test/babashka/test_test.clj +++ b/test/babashka/test_test.clj @@ -37,8 +37,12 @@ (deftest fixtures-test (let [output (bb " (require '[clojure.test :as t]) -(defn once [f] (prn :once-before) (f) (prn :once-after)) -(defn each [f] (prn :each-before) (f) (prn :each-after)) +(defn once [f] (prn :once-before) (f) +(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 :each each) (t/deftest foo) @@ -48,9 +52,12 @@ :once-before :each-before :each-after +true :each-before :each-after -:once-after"))))) +true +:once-after +true"))))) (deftest with-test (let [output (bb "