Dropped is-equal and is-string=, added is-every
[fiveam.git] / src / check.lisp
index 06c9bba..5244704 100644 (file)
@@ -165,6 +165,18 @@ Wrapping the TEST form in a NOT simply preducse a negated reason string."
      (format *test-dribble* "s")
      (add-result 'test-skipped :reason (format nil ,@reason))))
 
+(defmacro is-every (predicate &body clauses)
+  "The input is either a list of lists, or a list of pairs. Generates (is (,predicate ,expr ,value))
+   for each pair of elements or (is (,predicate ,expr ,value) ,@reason) for each list."
+  `(progn
+    ,@(if (every #'consp clauses)
+          (loop for (expected actual &rest reason) in clauses
+                collect `(is (,predicate ,expected ,actual) ,@reason))
+          (progn
+            (assert (evenp (list-length clauses)))
+            (loop for (expr value) on clauses by #'cddr
+                  collect `(is (,predicate ,expr ,value)))))))
+
 (defmacro is-true (condition &rest reason-args)
   "Like IS this check generates a pass if CONDITION returns true
   and a failure if CONDITION returns false. Unlike IS this check
@@ -207,13 +219,13 @@ not evaluated."
                                                   :test-expr ',condition)
                                       (return-from ,block-name t))))
            (block nil
-             ,@body
-             (process-failure
-              :reason ,(if reason-control
-                           `(format nil ,reason-control ,@reason-args)
-                           `(format nil "Failed to signal a ~S" ',condition))
-              :test-expr ',condition)
-             (return-from ,block-name nil)))))))
+             ,@body))
+         (process-failure
+          :reason ,(if reason-control
+                       `(format nil ,reason-control ,@reason-args)
+                       `(format nil "Failed to signal a ~S" ',condition))
+          :test-expr ',condition)
+         (return-from ,block-name nil)))))
 
 (defmacro finishes (&body body)
   "Generates a pass if BODY executes to normal completion. In