defvar.lsp 1.89 KB
Newer Older
pfdietz's avatar
pfdietz committed
1
;-*- Mode:     Lisp -*-
2 3 4 5
;;;; Author:   Paul Dietz
;;;; Created:  Thu Oct 10 23:21:50 2002
;;;; Contains: Tests for DEFVAR

6

7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55

(defvar *defvar-test-var-1* 100)

(deftest defvar.1
  *defvar-test-var-1*
  100)

(deftest defvar.2
  (documentation '*defvar-test-var-1* 'variable)
  nil)

;;; Show that it's declared special.
(deftest defvar.3
  (flet ((%f () *defvar-test-var-1*))
    (let ((*defvar-test-var-1* 29))
      (%f)))
  29)

(deftest defvar.4
  (values
   (makunbound '*defvar-test-var-2*)
   (defvar *defvar-test-var-2* 200 "Whatever.")
   (documentation '*defvar-test-var-2* 'variable)
   *defvar-test-var-2*)
  *defvar-test-var-2*
  *defvar-test-var-2*
  "Whatever."
  200)

(deftest defvar.5
  (let ((x 0))
    (values
     (makunbound '*defvar-test-var-2*)
     (defvar *defvar-test-var-2* 200 "Whatever.")
     (documentation '*defvar-test-var-2* 'variable)
     *defvar-test-var-2*
     (defvar *defvar-test-var-2* (incf x) "And ever.")
     (documentation '*defvar-test-var-2* 'variable)
     *defvar-test-var-2*
     x
     ))
  *defvar-test-var-2*
  *defvar-test-var-2*
  "Whatever."
  200
  *defvar-test-var-2*
  "And ever."
  200
  0)
56

57
;;; (deftest defvar.error.1
58 59
;;;   (signals-error (defvar) program-error)
;;;   t)
sds's avatar
sds committed
60
;;;
61
;;; (deftest defvar.error.2
62
;;;   (signals-error (defvar *ignored-defvar-name* nil "documentation"
sds's avatar
sds committed
63
;;;                 "illegal extra argument")
64 65
;;;                  program-error)
;;;   t)
66 67

(deftest defvar.error.1
68
  (signals-error (funcall (macro-function 'defvar))
sds's avatar
sds committed
69
                 program-error)
70
  t)
71 72

(deftest defvar.error.2
73
  (signals-error (funcall (macro-function 'defvar)
sds's avatar
sds committed
74 75
                           '(defvar *nonexistent-variable* nil))
                 program-error)
76
  t)
77 78

(deftest defvar.error.3
79
  (signals-error (funcall (macro-function 'defvar)
sds's avatar
sds committed
80 81 82
                           '(defvar *nonexistent-variable* nil)
                           nil nil)
                 program-error)
83
  t)