File tree Expand file tree Collapse file tree 6 files changed +27
-11
lines changed
resources/clj-kondo.exports/org.clj-commons/slingshot/clj_kondo/clj_commons/slingshot
src/clj_commons/slingshot Expand file tree Collapse file tree 6 files changed +27
-11
lines changed Original file line number Diff line number Diff line change 1- {:paths [" src" ]
1+ {:paths [" src" " resources " ]
22 :deps {org.clojure/clojure {:mvn/version " 1.8.0" }}
33
44 :aliases
Original file line number Diff line number Diff line change 1313 (api/vector-node [selector (api/token-node nil )])
1414 exprs))]))
1515 (seq? catchee-sexpr)
16- (api/list-node
17- (list* catch (api/token-node 'Exception) (api/token-node '_e#)
18- (api/list-node
19- (list (api/token-node 'fn)
20- (api/vector-node [(api/token-node '%)])
21- catchee))
22- exprs))
16+ (let [[v & exprs] exprs]
17+ (api/list-node
18+ (list* catch (api/token-node 'Exception) v
19+ (api/list-node
20+ (list (api/token-node 'fn)
21+ (api/vector-node [(api/token-node '%)])
22+ catchee))
23+ exprs)))
2324 :else catch-node)))
2425
2526(defn try+ [{:keys [node]}]
Original file line number Diff line number Diff line change 2222 (pr-str e#) '~selector)})
2323 e#))))
2424
25+ (defmacro thrown+?
26+ " (is (thrown+? selector expr))"
27+ [_selector _expr]
28+ (throw (IllegalStateException.
29+ " thrown+? must be used inside an 'is' form" )))
30+
2531(defmethod assert-expr 'thrown+-with-msg? [msg form]
2632 ; ; (is (thrown+-with-msg? s re expr))
2733 ; ; Asserts that evaluating expr throws an object that matches
4753 :actual (format " thrown+-with-msg?: %s did not match %s"
4854 (pr-str e#) '~selector)})
4955 e#))))
56+
57+ (defmacro thrown+-with-msg?
58+ " (is (thrown+-with-msg? selector pattern expr))"
59+ [_selector _pattern _expr]
60+ (throw (IllegalStateException.
61+ " thrown+-with-msg? must be used inside an 'is' form" )))
Original file line number Diff line number Diff line change 11(ns clj-commons.slingshot.support-test
22 (:require
33 [clj-commons.slingshot :refer [throw+ try+]]
4- [clj-commons.slingshot.support :refer :all ]
4+ [clj-commons.slingshot.support :refer [*catch-hook* *throw-hook* parse-try+
5+ resolve-local stack-trace wrap]]
56 [clojure.test :refer [deftest is]]))
67
78(deftest test-parse-try+
5455(deftest test-resolve-local
5556 (let [a 4 ]
5657 (is (= 4 (resolve-local a)))
58+ #_{:clj-kondo/ignore [:unresolved-symbol ]}
5759 (is (nil? (resolve-local b)))))
5860
5961(deftest test-wrap
8082 (is (= (set (keys @test-hooked))
8183 (set [:object :message :cause :stack-trace ])))
8284 (is (= " throw-hook-string" (:object @test-hooked))))
83- (binding [*throw-hook* (fn [x ] 42 )]
85+ (binding [*throw-hook* (fn [_ ] 42 )]
8486 (is (= (throw+ " something" ) 42 ))))
8587
8688(def catch-hooked (atom nil ))
Original file line number Diff line number Diff line change 11(ns clj-commons.slingshot.test-test
22 (:require
33 [clj-commons.slingshot :refer [throw+]]
4- [clj-commons.slingshot.test]
4+ [clj-commons.slingshot.test :refer [thrown+? thrown+-with-msg?] ]
55 [clojure.test :refer [deftest is]]))
66
77(deftest test-slingshot-test-macros
Original file line number Diff line number Diff line change 8181 (try (throw exception-1)
8282 (catch Exception e [:class-exception e])))))
8383 (testing " IllegalArgumentException thrown by clojure/core"
84+ #_{:clj-kondo/ignore [:type-mismatch ]}
8485 (is (= :class-iae (first (mega-try (str/replace " foo" 1 1 )))))))
8586
8687 (testing " catch by java class generically"
You can’t perform that action at this time.
0 commit comments