Permalink
Browse files

Better test errors on (= x y), x ≠ y.

  • Loading branch information...
1 parent 2f315e4 commit 191794b172b6a063d429e47bfd439ddbdbd4d88f Arlen Christian Mart Cuss committed Dec 3, 2012
Showing with 15 additions and 3 deletions.
  1. +15 −3 lib/boot.rg
View
@@ -375,6 +375,18 @@
{:passed @*tests-passed*
:failed @*tests-failed*})))
+(defn check-code [check]
+ (if (and (seq? check)
+ (= (first check) '=)
+ (= (count check) 3))
+ (let [[_ l r] check]
+ `(let [l# ~l
+ r# ~r]
+ (if (= l# r#)
+ {:result true}
+ {:result false, :error `(~'~'= ~r# ~'~r)})))
+ {:error nil, :result check}))
+
(defn format-actual [check]
(if (and (seq? check)
(= (first check) 'not)
@@ -384,16 +396,16 @@
(defmacro is [check]
`(let [result# (try
- {:error nil, :result ~check}
+ ~(check-code check)
(catch Exception e#
{:error e#, :result false}))]
- (if (not (get result# :result))
+ (if (not (:result result#))
(do
(swap! *tests-failed* conj (conj *test-level* (pr-str '~check)))
(puts "FAIL in ???")
(puts "expected: " ~(pr-str check))
(let [actual#
- (let [error# (get result# :error)]
+ (let [error# (:error result#)]
(if error#
error#
(format-actual '~check)))]

0 comments on commit 191794b

Please sign in to comment.