errors-data-and-control-flow-3.lsp 11.8 KB
Newer Older
pfdietz's avatar
pfdietz committed
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 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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Tue Jun 14 07:00:58 2005
;;;; Contains: Tests of non-ANSI exceptions sutation from CLHS section 5, part 3
(in-package :ba-test)

(compile-and-load "ba-aux.lsp")

;;; CASE

(def-error-test case.1 (case . 1))
(def-error-test case.2 (case nil . 1))
(def-error-test case.3 (case nil (nil . 1)))
(def-error-test case.4 (case 'x nil))
(def-error-test case.5 (case 'x ((nil . x) 1)))
(def-error-test case.6 (case))

;;; CCASE

(def-error-test ccase.1 (ccase . 1))
(def-error-test ccase.2 (let ((x nil)) (ccase x . 1)))
(def-error-test ccase.3 (let ((x nil)) (ccase x (nil . 1))))
(def-error-test ccase.4 (let ((x 'x)) (ccase x nil)))
(def-error-test ccase.5 (let ((x 'x)) (ccase x ((nil . x) 1))))
(def-error-test ccase.6 (ccase 1 (1 nil))) ;; 1 is not a place!
(def-error-test ccase.7 (ccase))

;;; ECASE

(def-error-test ecase.1 (ecase . 1))
(def-error-test ecase.2 (ecase nil . 1))
(def-error-test ecase.3 (ecase nil (nil . 1)))
(def-error-test ecase.4 (ecase 'x nil))
(def-error-test ecase.5 (ecase 'x ((nil . x) 1)))
(def-error-test ecase.6 (ecase))

;;; TYPECASE

(def-error-test typecase.1 (typecase))
(def-error-test typecase.2 (typecase . :foo))
(def-error-test typecase.3 (typecase 'x . #\X))
(def-error-test typecase.4 (typecase 'x (#.(gensym) t)))
(def-error-test typecase.5 (typecase 'x (symbol . :foo)))
(def-error-test typecase.6 (typecase 'x . :foo))
(def-error-test typecase.7 (typepcase 'x (t . :foo)))
(def-error-test typecase.8 (typepcase 'x (otherwise . :foo)))

;;; CTYPECASE

(def-error-test ctypecase.1 (ctypecase))
(def-error-test ctypecase.2 (ctypecase . :foo))
(def-error-test ctypecase.3 (let ((x 'x)) (ctypecase x . #\X)))
(def-error-test ctypecase.4 (let ((x 'x)) (ctypecase x (#.(gensym) t))))
(def-error-test ctypecase.5 (let ((x 'x)) (ctypecase x (symbol . :foo))))
(def-error-test ctypecase.6 (let ((x 'x)) (ctypecase x . :foo)))
(def-error-test ctypecase.7 (let ((x 'x)) (ctypecase x (t . :foo))))
(def-error-test ctypecase.8 (let ((x 'x)) (ctypecase x (otherwise . :foo))))
(def-error-test ctypecase.9 (ctypecase 1 (integer :bad)))

;;; ETYPECASE

(def-error-test etypecase.1 (etypecase))
(def-error-test etypecase.2 (etypecase . :foo))
(def-error-test etypecase.3 (etypecase 'x . #\X))
(def-error-test etypecase.4 (etypecase 'x (#.(gensym) t)))
(def-error-test etypecase.5 (etypecase 'x (symbol . :foo)))
(def-error-test etypecase.6 (etypecase 'x . :foo))

;;; MULTIPLE-VALUE-BIND

(def-error-test multiple-value-bind.1 (multiple-value-bind))
(def-error-test multiple-value-bind.2 (multiple-value-bind .
sds's avatar
sds committed
73
                                          #.(1+ most-positive-fixnum)))
pfdietz's avatar
pfdietz committed
74 75 76 77 78 79 80 81 82 83
(def-error-test multiple-value-bind.3 (multiple-value-bind (x)))
(def-error-test multiple-value-bind.4 (multiple-value-bind (x . y) 1 x))
(def-error-test multiple-value-bind.5 (multiple-value-bind (x) . :foo))
(def-error-test multiple-value-bind.6 (multiple-value-bind (x) nil . :bar))
(def-error-test multiple-value-bind.7
  (multiple-value-bind (x) nil "doc string" . 1))
(def-error-test multiple-value-bind.8
  (multiple-value-bind (x) nil (declare) . 1))
(def-error-test multiple-value-bind.9
  (multiple-value-bind (x) 1 (declare (type symbol x)) x))
84 85 86 87
(def-error-test multiple-value-bind.10
  (multiple-value-bind (x) 1 nil (declare) nil))
(def-error-test multiple-value-bind.11
  (multiple-value-bind (x) 1 "foo" "bar" (declare) nil))
pfdietz's avatar
pfdietz committed
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122

;;; MULTIPLE-VALUE-CALL

(def-error-test multiple-value-call.1 (multiple-value-call))
(def-error-test multiple-value-call.2 (multiple-value-call . :x))
(def-error-test multiple-value-call.3 (multiple-value-call 'list . :x))
(def-error-test multiple-value-call.4 (multiple-value-call 'list 1 . :x))
(def-all-error-test multiple-value-call.5 'function-designator-p
  '(multiple-value-call x nil))
(def-error-test multiple-value-call.6 (multiple-value-call (gensym)))

;;; MULTIPLE-VALUE-LIST

(def-error-test multiple-value-list.1 (multiple-value-list))
(def-error-test multiple-value-list.2 (multiple-value-list . 1))
(def-error-test multiple-value-list.3 (multiple-value-list 1 . 2))
(def-error-test multiple-value-list.4 (multiple-value-list 1 2))

;;; MULTIPLE-VALUE-PROG1

(def-error-test multiple-value-prog1.1 (multiple-value-prog1))
(def-error-test multiple-value-prog1.2 (multiple-value-prog1 . 1))
(def-error-test multiple-value-prog1.3 (multiple-value-prog1 :x . :y))

;;; MULTIPLE-VALUE-SETQ

(def-error-test multiple-value-setq.1 (multiple-value-setq))
(def-error-test multiple-value-setq.2 (let (x) (multiple-value-setq (x)) x))
(def-error-test multiple-value-setq.3
  (let (x y) (multiple-value-setq (x . y) nil (list x y))))
(def-all-error-test multiple-value-setq.4 'symbolp
  #'(lambda (x) `(multiple-value-setq (,x) nil)))
(def-all-error-test multiple-value-setq.5 (constantly nil)
  #'(lambda (x) `(multiple-value-setq (,x) nil))
  :vals cl-test::*cl-constant-symbols*)
pfdietz's avatar
pfdietz committed
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210

;;; VALUES

(def-all-error-test values.1 'listp #'(lambda (x) (cons 'values x)))
(def-all-error-test values.2 'listp #'(lambda (x) (list* 'values 1 x)))

;;; NTH-VALUE

(def-error-test nth-value.1 (nth-value))
(def-error-test nth-value.2 (nth-value 0))
(def-error-test nth-value.3 (nth-value 1 '(a b c) 2))
(def-all-error-test nth-value.4 (constantly nil) #'(lambda (x) `(nth-value ',x)))
(def-all-error-test nth-value.5 (constantly nil) #'(lambda (x) `(nth-value . ,x)))
(def-all-error-test nth-value.6 (constantly nil) #'(lambda (x) `(nth-value 0 . ,x)))
(def-all-error-test nth-value.7 'integerp #'(lambda (x) `(nth-value ',x nil)))
(def-error-test nth-value.8 (nth-value -1 'x))
(def-all-error-test nth-value.9 'null #'(lambda (x) `(nth-value 0 'a . ,x)))

;;; PROG

(def-error-test prog.1 (prog))
(def-all-error-test prog.2 'listp #'(lambda (x) `(prog . ,x)))
(def-all-error-test prog.3 'listp #'(lambda (x) `(prog ,x)))
(def-all-error-test prog.4 'listp #'(lambda (x) `(prog () . ,x)))
(def-all-error-test prog.5 (typef '(or symbol cons))  #'(lambda (x) `(prog (,x))))
(def-all-error-test prog.6 'listp #'(lambda (x) `(prog (v . ,x))))
(def-all-error-test prog.7 'listp #'(lambda (x) `(prog ((v . ,x)))))
(def-error-test prog.8 (prog ((x nil nil))))
(def-all-error-test prog.9 'null #'(lambda (x) `(prog ((v nil . ,x)))))

;;; PROG*

(def-error-test prog*.1 (prog*))
(def-all-error-test prog*.2 'listp #'(lambda (x) `(prog* . ,x)))
(def-all-error-test prog*.3 'listp #'(lambda (x) `(prog* ,x)))
(def-all-error-test prog*.4 'listp #'(lambda (x) `(prog* () . ,x)))
(def-all-error-test prog*.5 (typef '(or symbol cons))  #'(lambda (x) `(prog* (,x))))
(def-all-error-test prog*.6 'listp #'(lambda (x) `(prog* (v . ,x))))
(def-all-error-test prog*.7 'listp #'(lambda (x) `(prog* ((v . ,x)))))
(def-error-test prog*.8 (prog* ((x nil nil))))
(def-all-error-test prog*.9 'null #'(lambda (x) `(prog* ((v nil . ,x)))))

;;; PROG1

(def-error-test prog1.1 (prog1))
(def-all-error-test prog1.2 #'listp #'(lambda (x) `(prog1 . ,x)))
(def-all-error-test prog1.3 #'listp #'(lambda (x) `(prog1 nil . ,x)))

;;; PROG2

(def-error-test prog2.1 (prog2))
(def-all-error-test prog2.2 #'listp #'(lambda (x) `(prog2 . ,x)))
(def-error-test prog2.3 (prog2 t))
(def-all-error-test prog2.4 #'listp #'(lambda (x) `(prog2 nil . ,x)))
(def-all-error-test prog2.5 #'listp #'(lambda (x) `(prog2 'a 'b . ,x)))
(def-all-error-test prog2.6 #'listp #'(lambda (x) `(prog2 'a 'b nil . ,x)))

;;; PROGN

(def-all-error-test progn.1 'listp #'(lambda (x) `(progn . ,x)))
(def-all-error-test progn.2 'listp #'(lambda (x) `(progn nil . ,x)))
(def-all-error-test progn.3 'listp #'(lambda (x) `(progn 'a 'b . ,x)))

;;; DEFINE-MODIFY-MACRO

(def-error-test define-modify-macro.1 (define-modify-macro))
(def-error-test define-modify-macro.2 (define-modify-macro #.(gensym)))
(def-all-error-test define-modify-macro.3 'symbolp #'(lambda (x) `(define-modify-macro ,x ())))
(def-all-error-test define-modify-macro.4 'listp #'(lambda (x) `(define-modify-macro #.(gensym) ,x)))
(def-all-error-test define-modify-macro.5 'listp #'(lambda (x) `(define-modify-macro #.(gensym) () . ,x)))
(def-all-error-test define-modify-macro.6 'symbolp #'(lambda (x) `(define-modify-macro #.(gensym) () ,x)))
(def-all-error-test define-modify-macro.7 'stringp #'(lambda (x) `(define-modify-macro #.(gensym) () #.(gensym) ,x)))
(def-all-error-test define-modify-macro.8 'listp #'(lambda (x) `(define-modify-macro #.(gensym) () #.(gensym) . ,x)))
(def-all-error-test define-modify-macro.9 'listp #'(lambda (x) `(define-modify-macro #.(gensym) () #.(gensym) "foo" . ,x)))
(def-all-error-test define-modify-macro.10 (constantly nil)
  #'(lambda (x) `(define-modify-macro #.(gensym) () #.(gensym) "foo" ,x)))

;;; DEFSETF

(def-error-test defsetf.1 (defsetf))
(def-error-test defsetf.2 (defsetf #.(gensym)))
(def-all-error-test defsetf.3 'listp #'(lambda (x) `(defsetf ,x)))
(def-all-error-test defsetf.4 'listp #'(lambda (x) `(defsetf #.(gensym) . ,x)))
(def-all-error-test defsetf.5 'listp #'(lambda (x) `(defsetf #.(gensym) #.(gensym) . ,x)))
(def-all-error-test defsetf.6 'stringp #'(lambda (x) `(defsetf #.(gensym) #.(gensym) ,x)))
(def-all-error-test defsetf.7 'null #'(lambda (x) `(defsetf #.(gensym) #.(gensym) "foo" . ,x)))
(def-all-error-test defsetf.8 (constantly nil) #'(lambda (x) `(defsetf #.(gensym) #.(gensym) "foo" ,x)))
(def-all-error-test defsetf.9 (typef '(or list symbol)) #'(lambda (x) `(defsetf #.(gensym) ,x)))
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265

;;; Need long form defsetf error tests

;;; FIXME: add tests for defsetf-lambda-lists

(def-all-error-test defsetf.10 'symbolp #'(lambda (x)  `(defsetf #.(gensym) (#1=#.(gensym)) (,x) #1#)))
(def-all-error-test defsetf.11 'listp #'(lambda (x) `(defsetf #.(gensym) (#.(gensym)) ., x)))
(def-all-error-test defsetf.12 'listp #'(lambda (x) `(defsetf #.(gensym) (#.(gensym)) , x)))
(def-all-error-test defsetf.13 'listp #'(lambda (x) `(defsetf #.(gensym) (#.(gensym)) (a . ,x))))

(def-error-test defsetf.14 (defsetf #.(gensym) () () nil (declare (optimize)) nil))
(def-error-test defsetf.15 (defsetf #.(gensym) () () "foo" "bar" (declare (optimize)) nil))

;;; FIXME -- Add tests for DEFINE-SETF-EXPANDER

(def-error-test get-setf-expansion.1 (get-setf-expansion))
(def-all-error-test get-setf-expansion.2 'listp #'(lambda (x) `(get-setf-expansion . ,x)))
(def-all-error-test get-setf-expansion.3 (typef '(or list symbol))
  #'(lambda (x) `(get-setf-expansion ,x)))

;;; FIXME -- figure out how to test for invalid environment objects
;;;   Must make an assumption about what can be an environment

;;; SETF tests

(def-all-error-test setf.1 (constantly nil) #'(lambda (x) `(setf ,x)))
(def-all-error-test setf.2 'listp #'(lambda (x) `(setf . ,x)))
(def-all-error-test setf.3 'listp #'(lambda (x) `(setf ,x nil)))
(def-all-error-test setf.4 'listp #'(lambda (x) `(let (a) (setf a . ,x))))

;;; PSETF tests

(def-all-error-test psetf.1 (constantly nil) #'(lambda (x) `(psetf ,x)))
(def-all-error-test psetf.2 'listp #'(lambda (x) `(psetf . ,x)))
(def-all-error-test psetf.3 'listp #'(lambda (x) `(psetf ,x nil)))
(def-all-error-test psetf.4 'listp #'(lambda (x) `(let (a) (psetf a . ,x))))

;;; SHIFTF tests

(def-error-test shiftf.1 (shiftf))
(def-all-error-test shiftf.2 'listp #'(lambda (x) `(shiftf . ,x)))
(def-all-error-test shiftf.3 (constantly nil) #'(lambda (x) `(shiftf ,x)))
(def-all-error-test shiftf.4 'listp #'(lambda (x) `(let (a) (shiftf a . ,x))))
(def-all-error-test shiftf.5 'listp #'(lambda (x) `(shiftf ,x nil)))
(def-all-error-test shiftf.6 'listp #'(lambda (x) `(let (a b) (shiftf a b . ,x))))
(def-all-error-test shiftf.7 'listp #'(lambda (x) `(let (a) (shiftf ,x a nil))))
(def-all-error-test shiftf.8 'listp #'(lambda (x) `(let (a) (shiftf a ,x nil))))

;;; ROTATEF tests

(def-all-error-test rotatef.1 'listp #'(lambda (x) `(rotatef . ,x)))
(def-all-error-test rotatef.2 'listp #'(lambda (x) `(rotatef ,x)))
(def-all-error-test rotatef.3 'listp #'(lambda (x) `(let (a) (rotatef a ,x))))
(def-all-error-test rotatef.4 'listp #'(lambda (x) `(let (a) (rotatef a . ,x))))
(def-all-error-test rotatef.5 'listp #'(lambda (x) `(let (a) (rotatef ,x a))))