Removed the default-test-args slot from test-suite.
[fiveam.git] / src / suite.lisp
index 64223e0..c09c071 100644 (file)
@@ -6,7 +6,7 @@
 
 ;;;; Test suites allow us to collect multiple tests into a single
 ;;;; object and run them all using asingle name. Test suites do not
-;;;; affect teh way test are run northe way the results are handled,
+;;;; affect the way test are run nor the way the results are handled,
 ;;;; they are simply a test organizing group.
 
 ;;;; Test suites can contain both tests and other test suites. Running
   "Define a new test-suite named NAME.
 
 IN (a symbol), if provided, causes this suite te be nested in the
-suite named by IN."
+suite named by IN. NB: This macro is built on top of make-suite,
+as such it, like make-suite, will overrwrite any existing suite
+named NAME."
   `(progn
      (make-suite ',name
-                ,@(when description `(:description ,description))
-                ,@(when in `(:in ',in)))
+                 ,@(when description `(:description ,description))
+                 ,@(when in `(:in ',in)))
      ',name))
 
+(defmacro def-suite* (name &rest def-suite-args)
+  `(progn
+     (def-suite ,name ,@def-suite-args)
+     (in-suite ,name)))
+
 (defun make-suite (name &key description in)
-  "Create a new test suite object."
+  "Create a new test suite object.
+
+Overides any existing suite named NAME."
   (let ((suite (make-instance 'test-suite :name name)))
     (when description
       (setf (description suite) description))
@@ -55,14 +64,23 @@ after the execution of this form are, unless specified otherwise,
 in the test-suite named SUITE-NAME.
 
 See also: DEF-SUITE *SUITE*"
+  `(eval-when (:compile-toplevel :load-toplevel :execute)
+     (%in-suite ,suite-name)))
+
+(defmacro in-suite* (suite-name &key in)
+  "Just like in-suite, but silently creates missing suites."
+  `(%in-suite ,suite-name :in ,in :fail-on-error nil))
+
+(defmacro %in-suite (suite-name &key (fail-on-error t) in)
   (with-unique-names (suite)
     `(progn
        (if-bind ,suite (get-test ',suite-name)
            (setf *suite* ,suite)
           (progn
-            (cerror "Create a new suite named ~A."
-                    "Unkown suite ~A." ',suite-name)
-            (setf (get-test ',suite-name) (make-suite ',suite-name)
+            (when ,fail-on-error
+               (cerror "Create a new suite named ~A."
+                       "Unkown suite ~A." ',suite-name))
+            (setf (get-test ',suite-name) (make-suite ',suite-name :in ',in)
                   *suite* (get-test ',suite-name))))
        ',suite-name)))