X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fsuite.lisp;h=a74f7edee06065d1a0293eefb372308b3d1af066;hb=4b85e1a17c80d4c55bd7511dd8a90954a455ecd6;hp=9aab2cc39055cf3438f753db498a802b1afde674;hpb=2733dc1598c592d6b1c411b81b67033279725e56;p=fiveam.git diff --git a/src/suite.lisp b/src/suite.lisp index 9aab2cc..a74f7ed 100644 --- a/src/suite.lisp +++ b/src/suite.lisp @@ -21,35 +21,47 @@ (defmacro def-suite (name &key description (in nil in-p) (fixture nil fixture-p)) "Define a new test-suite named NAME. -IN (a symbol), if provided, causes this suite te be nested in the -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. +NAME:: + The symbol naming the test. -DESCRIPTION is just a string. +DESCRIPTION:: + A string describing the contents/purpose of this suite. -FIXTURE is the fixture argument (exactly like the :fixture argument to -def-test) to pass to tests in this suite." +IN (a symbol):: + If provided, causes this suite te be nested in the suite named by + `IN`. If `IN` is `NIL`, as opposed to not being passed at all, the + new suite will not be a part of any existing suite. + +FIXTURE:: + Whatever value is passed here will be passed, unevaluated, to all + tests defined in this suite. + +[NOTE] +This macro is built on top of `make-suite` and it, just like `make-suite`, +will overrwrite any existing suite named `NAME`." `(eval-when (:compile-toplevel :load-toplevel :execute) - (setf (gethash ',name *suites*) - (make-suite ',name - ,@(when description `(:description ,description)) - ,@(when in-p `(:in ',in)) - ,@(when fixture-p `(:fixture ',fixture)))) + (make-suite ',name + ,@(when description `(:description ,description)) + ,@(when in-p `(:in ',in)) + ,@(when fixture-p `(:fixture ',fixture))) ',name)) -(defmacro def-suite* (name &rest def-suite-args) - `(progn - (def-suite ,name ,@def-suite-args) - (in-suite ,name))) +(defun remove-from-suites (test-name) + (when (get-test test-name) + ;; if this suite alruady exists, and its :IN some other suite, remove it. + (dolist (s (list-all-suites)) + (when (gethash test-name (tests s)) + (remhash test-name (tests s)))))) -(defun make-suite (name &key description ((:in parent-suite)) fixture) +(defun make-suite (name &key description ((:in parent-suite) *suite*) fixture) "Create a new test suite object. Overrides any existing suite named NAME." + (remove-from-suites name) (let ((suite (make-instance 'test-suite :name name :fixture fixture))) (when description (setf (description suite) description)) + (setf (gethash name *suites*) suite) (loop for i in (ensure-list parent-suite) for in-suite = (get-test i) do (progn @@ -63,37 +75,30 @@ Overrides any existing suite named NAME." (defun list-all-suites () (loop for suite being the hash-value in *suites* - collect suite)) + collect suite)) ;;;; ** Managing the Current Suite -(defvar *suite* (setf (get-test 'NIL) - (make-suite 'NIL :description "Default global suite")) +(defvar *suite* (setf (get-test 'T) (make-suite 'T :description "Default global suite" :in nil)) "The current test suite object") (defmacro in-suite (suite-name) - "Set the *suite* special variable so that all tests defined + "Set the `*suite*` special variable so that all tests defined after the execution of this form are, unless specified otherwise, -in the test-suite named SUITE-NAME. +in the test-suite named `SUITE-NAME`. -See also: DEF-SUITE *SUITE*" +See also: `DEF-SUITE` and `*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) +(defmacro %in-suite (suite-name &rest def-suite-args) (with-gensyms (suite) `(progn (if-let (,suite (get-test ',suite-name)) (setf *suite* ,suite) (progn - (when ,fail-on-error - (cerror "Create a new suite named ~A." - "Unknown suite ~A." ',suite-name)) - (setf (get-test ',suite-name) (make-suite ',suite-name :in ',in) + (cerror "Create a new suite named ~A." "Unknown suite ~A." ',suite-name) + (setf (get-test ',suite-name) (make-suite ',suite-name ,@def-suite-args) *suite* (get-test ',suite-name)))) ',suite-name)))