diff --git a/test/darkleaf/di/dependencies_test.clj b/test/darkleaf/di/dependencies_test.clj index 7b20051..dba4330 100644 --- a/test/darkleaf/di/dependencies_test.clj +++ b/test/darkleaf/di/dependencies_test.clj @@ -2,7 +2,8 @@ (:require [clojure.test :as t] [darkleaf.di.core :as di] - [darkleaf.di.protocols :as dip])) + [darkleaf.di.protocols :as dip] + [darkleaf.di.test-utils :refer [catch-some]])) ;; root ;; / \ @@ -51,11 +52,6 @@ [`c :stopped]] @log)))) -(defmacro try-ex-data [& body] - `(try ~@body - (catch clojure.lang.ExceptionInfo e# - (ex-data e#)))) - (defn root-path [{::syms [a-path b-path c-path]}] :done) @@ -79,7 +75,9 @@ (t/deftest error-path-test (t/is (= {:type ::di/missing-dependency :stack [`missing-path `b-path `root-path ::di/implicit-root]} - (try-ex-data (di/start `root-path))))) + (-> (di/start `root-path) + catch-some + ex-data)))) (defn parent @@ -90,11 +88,15 @@ (t/deftest missing-dependency-test (t/is (= {:type ::di/missing-dependency :stack [`missing-root ::di/implicit-root]} - (try-ex-data (di/start `missing-root)))) + (-> (di/start `missing-root) + catch-some + ex-data))) (t/is (= {:type ::di/missing-dependency :stack [`missing-key `parent ::di/implicit-root]} - (try-ex-data (di/start `parent))))) + (-> (di/start `parent) + catch-some + ex-data)))) (defn recursion-a @@ -112,9 +114,14 @@ (t/deftest circular-dependency-test (t/is (= {:type ::di/circular-dependency :stack [`recursion-a `recursion-b `recursion-a ::di/implicit-root]} - (try-ex-data (di/start `recursion-a)))) + (-> (di/start `recursion-a) + catch-some + ex-data))) + (t/is (= {:type ::di/circular-dependency :stack [`recursion-c `recursion-c ::di/implicit-root]} - (try-ex-data (di/start `recursion-c))))) + (-> (di/start `recursion-c) + catch-some + ex-data)))) diff --git a/test/darkleaf/di/test_utils.clj b/test/darkleaf/di/test_utils.clj new file mode 100644 index 0000000..160fd86 --- /dev/null +++ b/test/darkleaf/di/test_utils.clj @@ -0,0 +1,8 @@ +(ns darkleaf.di.test-utils) + +(defmacro catch-some [& body] + `(try + ~@body + nil + (catch Exception ex# + ex#))) diff --git a/test/darkleaf/di/tutorial/y_graceful_stop_test.clj b/test/darkleaf/di/tutorial/y_graceful_stop_test.clj index fa4a0eb..440663e 100644 --- a/test/darkleaf/di/tutorial/y_graceful_stop_test.clj +++ b/test/darkleaf/di/tutorial/y_graceful_stop_test.clj @@ -5,7 +5,8 @@ {:nextjournal.clerk/visibility {:result :hide}} (:require [clojure.test :as t] - [darkleaf.di.core :as di])) + [darkleaf.di.core :as di] + [darkleaf.di.test-utils :refer [catch-some]])) ;; The DI tries to stop components that are already started ;; if another component fails while it is starting. @@ -30,9 +31,7 @@ on-stop-dep-ex (ex-info "on stop dep" {}) registry {::on-start-root-ex on-start-root-ex ::on-stop-dep-ex on-stop-dep-ex} - ex (try - (di/start `root registry) - (catch Exception ex - ex))] + ex (-> (di/start `root registry) + catch-some)] (t/is (= on-start-root-ex (ex-cause ex))) (t/is (= [on-stop-dep-ex] (vec (.getSuppressed ex))))))