X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fsuite.lisp;h=972e1f659df9be82d2f318aba1cb3ef42e741911;hb=b76fc6a27dc451c7f2f88eb9a1f028228530af6c;hp=64223e06d1b0419872e208ab89a2bea8d9de5e7b;hpb=1454981ac5f4f7ea8fe741a8125efbf0b09497ea;p=fiveam.git diff --git a/src/suite.lisp b/src/suite.lisp index 64223e0..972e1f6 100644 --- a/src/suite.lisp +++ b/src/suite.lisp @@ -1,12 +1,12 @@ -;; -*- lisp -*- +;;;; -*- Mode: Lisp; indent-tabs-mode: nil -*- -(in-package :it.bese.FiveAM) +(in-package :it.bese.fiveam) ;;;; * Test Suites ;;;; 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 @@ -20,33 +20,42 @@ "Define a new test-suite named NAME. IN (a symbol), if provided, causes this suite te be nested in the -suite named by IN." - `(progn +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." + `(eval-when (:compile-toplevel :load-toplevel :execute) (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. + +Overrides any existing suite named NAME." (let ((suite (make-instance 'test-suite :name name))) (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))) + 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)) ;;;; ** Managing the Current Suite (defvar *suite* (setf (get-test 'NIL) - (make-suite 'NIL :description "Global Suite")) + (make-suite 'NIL :description "Global Suite")) "The current test suite object") (defmacro in-suite (suite-name) @@ -55,27 +64,36 @@ after the execution of this form are, unless specified otherwise, in the test-suite named SUITE-NAME. See also: DEF-SUITE *SUITE*" - (with-unique-names (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-gensyms (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) - *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 :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. @@ -83,7 +101,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