X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=assert.lisp;h=fa2f100e92a216cf3bec1e0a4872b301e8e564e6;hb=53e193feda5d4cb757ef13d622fac03cf99178a2;hp=8307e2fbfd82cb68ab5824e4f81cdaffd7a3fcd7;hpb=318cda1a328e9d99af2270c73cb13262e485a1ff;p=xlunit.git diff --git a/assert.lisp b/assert.lisp index 8307e2f..fa2f100 100644 --- a/assert.lisp +++ b/assert.lisp @@ -2,42 +2,42 @@ ;;;; ************************************************************************* ;;;; FILE IDENTIFICATION ;;;; -;;;; Name: assert.lisp +;;;; ID: $Id: assert.lisp,v 1.4 2003/08/04 16:13:58 kevin Exp $ ;;;; Purpose: Assert functions for XLUnit -;;;; Author: Kevin Rosenberg ;;;; -;;;; $Id: assert.lisp,v 1.1 2003/08/04 12:01:54 kevin Exp $ ;;;; ************************************************************************* (in-package #:xlunit) -;;; Assertions - -(define-condition test-failure-condition (simple-condition) +(define-condition assertion-failed (simple-condition) ((msg :initform nil :initarg :msg :accessor msg)) (:documentation "Base class for all test failures.")) -(defun failure (format-str &rest args) +(defun failure-msg (msg &optional format-str &rest args) "Signal a test failure and exit the test." - (signal 'test-failure-condition + (signal 'assertion-failed + :msg msg :format-control format-str :format-arguments args)) -(defmacro test-assert (test &optional msg) - `(unless ,test - (failure "Test assertion: ~s" ',test))) +(defun failure (format-str &rest args) + "Signal a test failure and exit the test." + (apply #'failure-msg nil format-str args)) (defun assert-equal (v1 v2 &optional msg) (unless (equal v1 v2) - (failure "Test equal: ~s ~s" v1 v2))) + (failure-msg msg "Test equal: ~S ~S" v1 v2))) -(defun assert-true (v &optional msg) - (unless v - (failure "Test true: ~s [~A]" v (if msg msg "")))) +(defun assert-eql (v1 v2 &optional msg) + (unless (eql v1 v2) + (failure-msg msg "Test eql: ~S ~S" v1 v2))) -(defun assert-false (v &optional msg) - (when v - (failure "Test false ~A" (if msg msg "")))) +(defmacro assert-true (v &optional msg) + `(unless ,v + (failure-msg msg "Not true: ~S" ',v))) +(defmacro assert-false (v &optional msg) + `(when ,v + (failure-msg msg "Not false: ~S" ',v)))