aboutsummaryrefslogtreecommitdiff
path: root/src/clojure/contrib/test_is.clj
diff options
context:
space:
mode:
Diffstat (limited to 'src/clojure/contrib/test_is.clj')
-rw-r--r--src/clojure/contrib/test_is.clj26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/clojure/contrib/test_is.clj b/src/clojure/contrib/test_is.clj
index 8374b772..9ea0edcc 100644
--- a/src/clojure/contrib/test_is.clj
+++ b/src/clojure/contrib/test_is.clj
@@ -49,12 +49,13 @@
;; need to recompile functions after changing a macro definition.
-(ns clojure.contrib.test-is)
+(ns clojure.contrib.test-is
+ (:import (java.io PrintWriter)))
(def
#^{:doc "PrintWriter to which test results are printed; defaults to
- System.err."}
- *test-out* (. System err))
+ Standard Output."}
+ *test-out* (PrintWriter. *out*))
;;; PRIVATE
@@ -195,6 +196,25 @@
(failure (str "expected " ~(pr-str form) " to throw " ~class
", but threw " e#) ~message)))))
+(defmacro all-true
+ "Convenience macro; every body expression is tested with 'is'."
+ [& body]
+ `(do ~@(map (fn [expr] (list 'is expr))
+ body)))
+
+(defmacro each=
+ "Convenience macro for doing a bunch of equality tests. Same as
+ doing (is (= ...)) on each pair.
+
+ (each= (test-expr-1) expected-value1
+ (test-expr-2) expected-value2
+ (test-expr-3) expected-value3)
+ "
+ [& forms]
+ `(all-true
+ ~@(map (fn [[expr expected]] (list '= expr expected))
+ (partition 2 forms))))
+
(defn print-results
"Prints a summary of the results from test-ns to *test-out*."
[r]