Skip to content

Commit

Permalink
component test
Browse files Browse the repository at this point in the history
  • Loading branch information
darkleaf committed Dec 22, 2024
1 parent 3daa516 commit 7735ee6
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions test/darkleaf/di/component_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,29 @@
(:import
(clojure.lang ExceptionInfo)))

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

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

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

(t/deftest nil-value-component-test
(t/is (= [{:type ::di/build-obj-fail
:stack [`nil-value-component ::di/implicit-root]}
{:type ::di/nil-value-component}]
(catch-cause-data (di/start `nil-value-component))))
(t/is (= [{:type ::di/build-obj-fail
:stack [`nil-value-component-1-arity ::di/implicit-root]}
{:type ::di/nil-value-component}]
(catch-cause-data (di/start `nil-value-component-1-arity)))))
(t/deftest nil-value-component-0-arity-test
(let [ex (try-catch (di/start `nil-value-component-0-arity))]
(t/is (= "An error during component build" (-> ex ex-message)))
(t/is (= "A component fn can't return nil" (-> ex ex-cause ex-message)))))

(t/deftest nil-value-component-1-arity-test
(let [ex (try-catch (di/start `nil-value-component-1-arity))]
(t/is (= "An error during component build" (-> ex ex-message)))
(t/is (= "A component fn can't return nil" (-> ex ex-cause ex-message)))))

0 comments on commit 7735ee6

Please sign in to comment.