Hi All

This is a little script to producing nicer errors from asserts and pre/post 
conditions in your clojure code.  Examples below, gist includes a readme 
with some notes.  I think the pre/post conditions are the biggest win.

Can anyone tell me how to do a similar "assert patch" technique for my 
clojurescript projects while debugging.

https://gist.github.com/olivergeorge/386ff4a559197dd794c1



(let [a 111] (assert (= 1 a)))

*AssertionError Assert failed: (= 1 a) => false*
* where a is 111*
  user/eval28652 (figwheel.clj:1)



(let [heart 1 diamond 2] (assert (> heart diamond) "Hearts should trump 
diamonds"))

*AssertionError Assert failed: Hearts should trump diamonds*
*(> heart diamond) => false*
* where heart is 1*
* where diamond is 2*
  user/eval28778 (figwheel.clj:1)



(let [x 1 y 2 z (range 1000)] (assert (> x 1)))

*AssertionError Assert failed: (> x 1) => false*
* where x is 1*
  user/eval28842 (figwheel.clj:1)



(defn pos-adder [a b]
  {:pre [(pos? a) (number? b)]
   :post [(pos? %)]}
  (+ a b))
=> #'user/pos-adder

(pos-adder 1 2)
=> 3

(pos-adder -1 2)

*AssertionError Assert failed: (pos? a) => false*
* where a is -1*
  user/pos-adder (figwheel.clj:1)


(pos-adder 1 -2)

*AssertionError Assert failed: (pos? %) => false*
* where % is -1*
  user/pos-adder (figwheel.clj:1)


(pos-adder 1 "notnum")

*AssertionError Assert failed: (number? b) => false*
* where b is notnum*
  user/pos-adder (figwheel.clj:1)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to