Skip to content

Commit

Permalink
Rewrite test to test exception object
Browse files Browse the repository at this point in the history
Co-authored-by: KGOH <[email protected]>
  • Loading branch information
slaughtlaught and KGOH committed Dec 20, 2024
1 parent d8c302b commit ba20534
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/darkleaf/di/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,8 @@

(defn- check-nil-component! [component var]
(if (nil? component)
(throw (ex-info (str "nil component " var) {}))
(throw (ex-info (str "nil component " var)
{:type ::nil-component}))
component))

(defn- var->0-component [variable]
Expand Down
20 changes: 16 additions & 4 deletions test/darkleaf/di/component_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,25 @@
(:import
(clojure.lang ExceptionInfo)))

(defmacro catch-cause-data [& body]
`(try ~@body
(catch clojure.lang.ExceptionInfo e#
(mapv :data (:via (Throwable->map e#))))))

(defn nil-component
{::di/kind :component}
[]
nil)

(defn nil-component-1-arity
{::di/kind :component}
[_]
nil)

(t/deftest nil-component-test
(t/is (thrown-with-msg?
ExceptionInfo
#"\Anil component #'darkleaf.di.component-test/nil-component\z"
(di/start `nil-component))))
(t/is (= [{:stack [`nil-component ::di/implicit-root]}
{:type ::di/nil-component}]
(catch-cause-data (di/start `nil-component))))
(t/is (= [{:stack [`nil-component-1-arity ::di/implicit-root]}
{:type ::di/nil-component}]
(catch-cause-data (di/start `nil-component-1-arity)))))

0 comments on commit ba20534

Please sign in to comment.