r5450: *** empty log message ***
[xlunit.git] / assert.lisp
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; ID:       $Id: assert.lisp,v 1.2 2003/08/04 12:16:13 kevin Exp $
6 ;;;; Purpose:  Assert functions for XLUnit
7 ;;;;
8 ;;;; *************************************************************************
9
10 (in-package #:xlunit)
11
12
13 ;;; Assertions
14
15 (define-condition test-failure-condition (simple-condition) 
16   ((msg :initform nil :initarg :msg :accessor msg))
17   (:documentation "Base class for all test failures."))
18
19
20 (defun failure (format-str &rest args)
21   "Signal a test failure and exit the test."
22   (signal 'test-failure-condition
23           :format-control format-str
24           :format-arguments args))
25
26 (defmacro test-assert (test &optional msg)
27   `(unless ,test
28     (failure "Test assertion: ~s" ',test)))
29
30 (defun assert-equal (v1 v2 &optional msg)
31   (unless (equal v1 v2)
32     (failure "Test equal: ~s ~s" v1 v2)))
33
34 (defun assert-true (v &optional msg)
35   (unless v
36     (failure "Test true: ~s [~A]" v (if msg msg ""))))
37
38 (defun assert-false (v &optional msg)
39   (when v
40     (failure "Test false ~A" (if msg msg ""))))
41