aboutsummaryrefslogtreecommitdiff
path: root/src/clojure/contrib/test_is.clj
diff options
context:
space:
mode:
authorStuart Sierra <mail@stuartsierra.com>2008-11-17 01:26:53 +0000
committerStuart Sierra <mail@stuartsierra.com>2008-11-17 01:26:53 +0000
commitfacfbecd912d043d464237185c726882f429398f (patch)
treee43b367be839738d67ddb04ca2551e0ca2d6c9ef /src/clojure/contrib/test_is.clj
parent76bc4f1f19f85b246963b3da1eece3b5400820a4 (diff)
test_is.clj: *test-out* defaults to *out*; added each= and all-true
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]