X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fsuite.lisp;h=8fd22182c0aaa8512f0c077293f970ed7148d819;hb=08b391a6ecfb01d739fabaedad8557c21971b197;hp=bf1cc100b6721fcee7541e4cb98a3913b11d6af1;hpb=660083a151da6492d44a5e21113d2c6064ea7817;p=fiveam.git diff --git a/src/suite.lisp b/src/suite.lisp index bf1cc10..8fd2218 100644 --- a/src/suite.lisp +++ b/src/suite.lisp @@ -1,6 +1,6 @@ -;; -*- lisp -*- +;;;; -*- Mode: Lisp; indent-tabs-mode: nil -*- -(in-package :it.bese.FiveAM) +(in-package :it.bese.fiveam) ;;;; * Test Suites @@ -16,7 +16,9 @@ ;;;; ** Creating Suits -(defmacro def-suite (name &key description in default-test-args) +(defvar *suites* (make-hash-table :test 'eql)) + +(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 @@ -24,13 +26,15 @@ 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. -DEFAULT-TEST-ARGS, if provided, will ba passed to the TEST forms -defined in this suite." +DESCRIPTION is just a string. + +FIXTURE is the fixture argument (exactly like the :fixture argument to +def-test) to pass to tests in this suite." `(eval-when (:compile-toplevel :load-toplevel :execute) (make-suite ',name ,@(when description `(:description ,description)) - ,@(when in `(:in ',in)) - ,@(when default-test-args `(:default-test-args ,default-test-args))) + ,@(when in-p `(:in ',in)) + ,@(when fixture-p `(:fixture ',fixture))) ',name)) (defmacro def-suite* (name &rest def-suite-args) @@ -38,28 +42,40 @@ defined in this suite." (def-suite ,name ,@def-suite-args) (in-suite ,name))) -(defun make-suite (name &key description in default-test-args) +(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) *suite*) fixture) "Create a new test suite object. -Overides any existing suite named NAME." - (let ((suite (make-instance 'test-suite :name name :default-test-args default-test-args))) +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)) - (loop for i in (ensure-list in) - for in-suite = (get-test i) - do (progn - (when (null in-suite) - (cerror "Create a new suite named ~A." "Unknown suite ~A." i) - (setf (get-test in-suite) (make-suite i) - in-suite (get-test in-suite))) - (setf (gethash name (tests in-suite)) suite))) + (setf (gethash name *suites*) suite) + (loop for i in (ensure-list parent-suite) + for in-suite = (get-test i) + do (progn + (when (null in-suite) + (cerror "Create a new suite named ~A." "Unknown suite ~A." i) + (setf (get-test in-suite) (make-suite i) + in-suite (get-test in-suite))) + (setf (gethash name (tests in-suite)) suite))) (setf (get-test name) suite) suite)) +(defun list-all-suites () + (loop for suite being the hash-value in *suites* + collect suite)) + ;;;; ** Managing the Current Suite -(defvar *suite* (setf (get-test 'NIL) - (make-suite 'NIL :description "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) @@ -71,33 +87,35 @@ See also: DEF-SUITE *SUITE*" `(eval-when (:compile-toplevel :load-toplevel :execute) (%in-suite ,suite-name))) -(defmacro in-suite* (suite-name &key in) +(defmacro in-suite* (suite-name &key (in nil in-p)) "Just like in-suite, but silently creates missing suites." - `(%in-suite ,suite-name :in ,in :fail-on-error nil)) + `(%in-suite ,suite-name + ,@(when in-p `(:in ,in)) + :fail-on-error nil)) -(defmacro %in-suite (suite-name &key (fail-on-error t) in) - (with-unique-names (suite) +(defmacro %in-suite (suite-name &key (fail-on-error t) (in nil in-p)) + (with-gensyms (suite) `(progn - (if-bind ,suite (get-test ',suite-name) - (setf *suite* ,suite) - (progn - (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)))) + (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 ,@(when in-p `(:in ',in))) + *suite* (get-test ',suite-name)))) ',suite-name))) ;; Copyright (c) 2002-2003, Edward Marco Baringer -;; All rights reserved. -;; +;; All rights reserved. +;; ;; Redistribution and use in source and binary forms, with or without ;; modification, are permitted provided that the following conditions are ;; met: -;; +;; ;; - Redistributions of source code must retain the above copyright ;; notice, this list of conditions and the following disclaimer. -;; +;; ;; - Redistributions in binary form must reproduce the above copyright ;; notice, this list of conditions and the following disclaimer in the ;; documentation and/or other materials provided with the distribution. @@ -105,7 +123,7 @@ See also: DEF-SUITE *SUITE*" ;; - Neither the name of Edward Marco Baringer, nor BESE, nor the names ;; of its contributors may be used to endorse or promote products ;; derived from this software without specific prior written permission. -;; +;; ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR