assert.lsp 1.61 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Tue Jan 28 06:48:19 2003
;;;; Contains: Tests of ASSERT

(in-package :cl-test)

(deftest assert.1
  (assert t)
  nil)

(deftest assert.2
  (assert t ())
  nil)

;;; I am assuming that when no places are given to ASSERT,
;;; it doesn't invoke any interactive handler.

(deftest assert.3
  (let ((x nil))
    (handler-bind
     ((error #'(lambda (c)
		 (setq x 17)
		 (let ((r (find-restart 'continue c)))
		   (when r (invoke-restart r))))))
26
27
     (assert x)
     x))
28
29
  17)

30
31
32
33
34
35
36
37
38
39
40
(deftest assert.3a
  (let ((x nil))
    (handler-bind
     ((error #'(lambda (c)
		 (setq x 17)
		 (continue c))))
     (assert x)
     x))
  17)


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
;;; I don't yet know how to test the interactive version of ASSERT
;;; that is normally invoked when places are given.

;;; Tests of the syntax (at least)

(deftest assert.4
  (let (x)
    (assert t (x)))
  nil)

(deftest assert.5
  (let ((x (cons 'a 'b)))
    (assert t ((car x) (cdr x))))
  nil)

(deftest assert.6
  (let ((x (vector 'a 'b 'c)))
    (assert t ((aref x 0) (aref x 1) (aref x 2))
	    "Vector x has value: ~A." x))
  nil)

62
63
64
65
66
67
68
69
70
(deftest assert.7
  (let ((x nil))
    (handler-bind
     ((simple-error #'(lambda (c)
			(setq x 17)
			(continue c))))
     (assert x () 'simple-error)
     x))
  17)
71

72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
(deftest assert.8
  (let ((x 0))
    (handler-bind
     ((type-error #'(lambda (c)
			(incf x)
			(continue c))))
     (assert (> x 5) () 'type-error)
     x))
  6)

(deftest assert.9
  (let ((x 0))
    (handler-bind
     ((type-error #'(lambda (c) (declare (ignore c))
			(incf x)
			(continue))))
     (assert (> x 5) () 'type-error)
     x))
  6)