This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-03-23
Channels
- # announcements (7)
- # babashka (40)
- # babashka-sci-dev (74)
- # beginners (74)
- # calva (31)
- # cider (11)
- # clj-kondo (22)
- # cljs-dev (1)
- # cljsrn (1)
- # clojure (70)
- # clojure-brasil (3)
- # clojure-dev (12)
- # clojure-europe (39)
- # clojure-nl (2)
- # clojure-norway (15)
- # clojure-uk (9)
- # clojurescript (69)
- # community-development (2)
- # conjure (1)
- # core-async (3)
- # cursive (1)
- # data-science (1)
- # datalevin (13)
- # datomic (17)
- # emacs (42)
- # events (1)
- # fulcro (16)
- # graphql (9)
- # helix (1)
- # holy-lambda (14)
- # honeysql (2)
- # hugsql (3)
- # hyperfiddle (5)
- # kaocha (10)
- # lsp (41)
- # luminus (5)
- # malli (7)
- # meander (3)
- # membrane (47)
- # off-topic (23)
- # podcasts (2)
- # polylith (34)
- # rdf (4)
- # re-frame (2)
- # releases (2)
- # remote-jobs (1)
- # ring (16)
- # shadow-cljs (111)
- # spacemacs (6)
- # test-check (2)
- # tools-deps (19)
How to expect an exception cleanly with RCF?
(defn π£ [] (/ 1 0))
(rcf/tests
(ex-message (clojure.test/is (thrown? ArithmeticException (π£))))
:= "Divide by zero")
Done this way, my expectation leaks on both sides of :=
.Some experiments. But still, parts of the expectation appears on LHS.
(catch-a :message (π£)) := "Divide by zero"
(ns test
(:require [clojure.test :as test]
[hyperfiddle.rcf :refer [tests]]))
(defn π£ [] (/ 1 0))
(defmacro catch-a [k & body]
`(try ~@body
(ex-info "Expected something thrown!" {}) ; don't throw it!
(catch Exception e#
(~k (first (:via (Throwable->map e#)))))))
(tests
(+ 1 2) := 3
(ex-message (test/is (thrown? ArithmeticException (π£))))
:= "Divide by zero"
;;(catch-a :message 1) := 1
(catch-a :message (π£)) := (catch-a :message (π£))
(catch-a :message (π£)) := "Divide by zero"
(catch-a :type (π£)) := (catch-a :type (π£))
;;(catch-a :type (π£)) := java.lang.ArithmeticException ; <>!?
;;
)
The current version of RCF doesnβt provide a way to expect exceptions.
We are working on a version where we could leverage clojure.test/assert-expr
. It already defines thrown?
so weβll get exception handling for free.
Here is the feature request:
https://github.com/hyperfiddle/rcf/issues/47
The next version of RCF has much better facilities for adding features like this, no public release ETA but we are using it internally
Thanks to both of you. In the meantime we don't mind doing the kind of things above. We're slowly ramping up on RCF usage. π
Some experiments. But still, parts of the expectation appears on LHS.
(catch-a :message (π£)) := "Divide by zero"
(ns test
(:require [clojure.test :as test]
[hyperfiddle.rcf :refer [tests]]))
(defn π£ [] (/ 1 0))
(defmacro catch-a [k & body]
`(try ~@body
(ex-info "Expected something thrown!" {}) ; don't throw it!
(catch Exception e#
(~k (first (:via (Throwable->map e#)))))))
(tests
(+ 1 2) := 3
(ex-message (test/is (thrown? ArithmeticException (π£))))
:= "Divide by zero"
;;(catch-a :message 1) := 1
(catch-a :message (π£)) := (catch-a :message (π£))
(catch-a :message (π£)) := "Divide by zero"
(catch-a :type (π£)) := (catch-a :type (π£))
;;(catch-a :type (π£)) := java.lang.ArithmeticException ; <>!?
;;
)
The current version of RCF doesnβt provide a way to expect exceptions.
We are working on a version where we could leverage clojure.test/assert-expr
. It already defines thrown?
so weβll get exception handling for free.
Here is the feature request:
https://github.com/hyperfiddle/rcf/issues/47