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