source: trunk/tests/ansi-tests/ccl.lsp @ 11429

Last change on this file since 11429 was 11429, checked in by gz, 12 years ago

add regression test

File size: 31.4 KB
Line 
1;;;-*-Mode: LISP; Package: CL-TEST -*-
2;;;
3;;;   Copyright (C) 2008 Clozure Associates
4
5(in-package :cl-test)
6
7(defvar *test-source-file-counter* 0)
8
9(defun test-source-file (format-string &rest format-args)
10  (let ((file (format nil "temp~s.dat" (incf *test-source-file-counter*))))
11    (with-open-file (s file :direction :output :if-exists :supersede)
12      (apply #'format s format-string format-args)
13      (terpri s)
14      (truename s))))
15
16(defun test-compile (lambda-or-file &rest args &key hide-warnings (safety 1) &allow-other-keys)
17  ;; Compile in a more-or-less standard environment
18  (let ((*error-output* (if hide-warnings (make-broadcast-stream) *error-output*))
19        (ccl::*nx-speed* 1)
20        (ccl::*nx-space* 1)
21        (ccl::*nx-safety* safety)
22        (ccl::*nx-cspeed* 1)
23        (ccl::*nx-debug* 1))
24    (remf args :hide-warnings)
25    (remf args :safety)
26    (if (consp lambda-or-file)
27      (apply #'compile nil lambda-or-file args)
28      (apply #'compile-file lambda-or-file args))))
29
30;;; CCL-specific regression tests, for CCL-specific behavior.
31
32(deftest ccl.40199  ;; fixed in r9116 and r9121
33    (when (equalp (let ((*print-pretty* t))
34                    (format nil "~a" (make-array nil :initial-element 0)))
35                  "#0A0")
36      :good)
37  :good)
38
39(deftest ccl.40492 ;; fixed in r9134 and r9131
40    (let (obj (slot (gensym)))
41      (eval `(defclass ccl.40492 ()
42               ((,slot :accessor ,slot :initform :good))))
43      (setq obj (make-instance 'ccl.40492))
44      (ccl::%snap-reader-method (symbol-function slot))
45      (unwind-protect
46           (let ((*trace-output* (make-broadcast-stream))) ;; don't care about trace output
47             (ccl:trace-function slot)
48             (funcall slot obj))
49        (eval `(untrace ,slot))))
50  :good)
51
52(deftest ccl.40207  ;; fixed in r9163 and r9165
53  (progn
54    (fmakunbound 'cl-test::ccl.40207-fn)
55    ;; Check that these compile-time errors don't abort compilation.
56    (let* ((test (test-source-file "(defun cl-test::ccl.40207-fn ()
57                                     (and (typep (lambda (x) (setq x)) 'function)
58                                          (typep (lambda (x) (setf x)) 'function)
59                                          (typep (lambda (((foo))) foo) 'function)
60                                          :good))")))
61      (test-compile test :hide-warnings t :break-on-program-errors nil :load t)
62      (funcall 'cl-test::ccl.40207-fn)))
63  :good)
64
65(deftest ccl.40927  ;; fixed in r9183 and r9184
66    (let ((s (make-string-output-stream))
67          (line1 "Line1
68")
69          (line2 "Line2"))
70      (count #\Newline (format nil "~a~&~a" line1 line2)))
71  1)
72
73(defstruct ccl.40055 (a 0 :type integer))
74
75(deftest ccl.40055 ;; fixed in r9237 and r9240
76    (locally
77        (declare (optimize (safety 3)))
78      (and (signals-error (make-ccl.40055 :a nil) type-error)
79           (signals-error (setf (ccl.40055-a (make-ccl.40055)) nil) type-error)))
80  t)
81
82
83(deftest ccl.bug#235
84    (handler-case
85        (test-compile `(lambda (x)
86                         (make-array x :element-type ',(gensym))))
87      (warning (c)
88        (when (typep c 'ccl::compiler-warning)
89          (ccl::compiler-warning-warning-type c))))
90  :unknown-type-declaration)
91
92
93(defclass ccl.bug#285 () ())
94
95(defmethod initialize-instance ((c ccl.bug#285) &rest args)
96  (declare (optimize (safety 3)))
97  (apply #'call-next-method c args))
98
99(deftest ccl.bug#285
100    (typep (make-instance 'ccl.bug#285) 'ccl.bug#285)
101  t)
102
103(deftest ccl.bug#286
104    (and (test-compile '(lambda ()
105                         (typep nil '(or ccl.bug#286-unknown-type-1 null)))
106                       :hide-warnings t)
107         (test-compile '(lambda ()
108                         (ccl:require-type nil '(or ccl.bug#286-unknown-type-2 null)))
109                       :hide-warnings t)
110         :no-crash)
111  :no-crash)
112
113
114(deftest ccl.bug#287
115    (progn
116      (defmethod ccl.bug#287 (x) x)
117      (trace ccl.bug#287)
118      (let ((*trace-output* (make-broadcast-stream))) ;; don't care about trace output
119        (prog1
120            (ccl.bug#287 :no-crash)
121          (untrace))))
122  :no-crash)
123
124
125(deftest ccl.41226
126    (let ((file (test-source-file "(defmacro ccl.41226 (x) (eq (caar x)))")))
127      (handler-case
128          (test-compile file :hide-warnings t :break-on-program-errors nil)
129        ;; Might still signal due to macros being implicitly eval-when compile.
130        ;; Ok so long as it's not the make-load-form error (which is not a program-error).
131        (program-error () nil))
132      :no-crash)
133  :no-crash)
134
135(deftest ccl.bug#288
136    (let ((file (test-source-file "(prog1 (declare (ignore foo)))")))
137      (test-compile file :hide-warnings t :break-on-program-errors nil)
138      :no-crash)
139  :no-crash)
140
141(deftest ccl.bug#288-1 ;; follow-on bug, not really the same
142    (let ((file (test-source-file "(defun cl-test::ccl.bug#288-1-fn ((x integer)) x)")))
143      (test-compile file :hide-warnings t :break-on-program-errors nil :load t)
144      (handler-case
145          (progn (ccl.bug#288-1-fn 17) :no-warnings)
146        (program-error (c) (if (search "(X INTEGER)" (princ-to-string c)) :lambda-list-error c))))
147  :lambda-list-error)
148
149(deftest ccl.40055-1
150    (let ((file (test-source-file "
151
152 (defclass ccl.40055-1-class () ())
153 (eval-when (eval compile load)
154  (defstruct ccl.40055-1-struct (slot nil :type (or ccl.40055-1-class null))))
155 (defun ccl.40055-1-fn ()
156   (make-array 0 :element-type 'ccl.40055-1-struct))
157 ")))
158      (handler-case
159          (progn (test-compile file) :no-warnings)
160        (warning (c) (format nil "~a" c))))
161  :no-warnings)
162
163(deftest ccl.40055-2
164    (let ((file (test-source-file "
165
166 (defclass ccl.40055-2-class () ())
167 (defstruct ccl.40055-2-struct (slot nil :type (or ccl.40055-2-class null)))
168 (defun ccl.40055-2-class-arr ()
169   (make-array 0 :element-type 'ccl.40055-2-class))
170 (defun ccl.40055-2-struct-arr ()
171   (make-array 0 :element-type 'ccl.40055-2-struct))
172 (defun ccl.40055-2-struct-arr-2 ()
173   (make-array 0 :element-type '(or (member 17 32) ccl.40055-2-struct)))
174 (defun ccl.40055-2-fn (x) (setf (ccl.40055-2-struct-slot x) nil))
175 ")))
176      (handler-case
177          (progn (test-compile file :break-on-program-errors nil) :no-warnings)
178        (warning (c) c)))
179  :no-warnings)
180
181
182(deftest ccl.40055-3
183    (let ((file (test-source-file "
184 (defclass ccl.40055-3-class () ())
185 (defun ccl.40055-3-cfn () (require-type nil '(or ccl.40055-3-class null)))
186 (defstruct ccl.40055-3-struct)
187 (defun ccl.40055-3-rfn () (require-type nil '(or ccl.40055-3-struct null)))")))
188      (handler-case
189          (progn (test-compile file :break-on-program-errors nil) :no-warnings)
190        (warning (c) c)))
191  :no-warnings)
192
193(deftest ccl.bug#289
194    (let ((file (test-source-file "
195 (defclass ccl.bug#289-meta (standard-class) ())
196 (defclass ccl.bug#289-class () () (:metaclass ccl.bug#289-meta))")))
197      (test-compile file)
198      :no-crash)
199  :no-crash)
200
201(deftest ccl.bug#295
202    (let ((file (test-source-file "
203  (defun outer-fun ()
204     (defun inner-fun () nil)
205     (inner-fun))")))
206      (handler-case (progn (test-compile file :safety 3) :no-warnings)
207        (warning (c) c)))
208  :no-warnings)
209
210
211(deftest ccl.41836  ;; fixed in r9391
212    (let ((file (test-source-file "
213  (defvar *a* 1)
214  (defvar *b* (load-time-value *a*))")))
215      (handler-case (progn (test-compile file :break-on-program-errors nil) :no-warnings)
216        (warning (c) c)))
217  :no-warnings)
218
219
220(deftest ccl.42698  ;; fixed in r9589/r9590
221    (handler-case (schar "abc" -1) ;; used to crash hard
222      (error () :error))
223  :error)
224
225(deftest ccl.42232-1
226    (let ((file (test-source-file "
227  (defun ccl.42232-1 (foo)
228    (declare (ignore foo))
229    foo)")))
230      (handler-case (progn (test-compile file) :no-warnings)
231        (warning (c) :warning)))
232  :warning)
233
234(deftest ccl.42232-2
235    (let ((file (test-source-file "
236  (defun ccl.42232-2 ()
237    (declare (ignore bar)))")))
238      (handler-case (progn (test-compile file :break-on-program-errors nil) :no-warnings)
239        (warning (c) :warning)))
240  :warning)
241
242(deftest ccl.42830
243    (let ((*standard-output* (make-broadcast-stream)))
244      (defun cl-user::ccl.42830 (stream int colon-p at-sign-p)
245        (declare (ignore at-sign-p colon-p))
246        (check-type int integer)
247        (write int :stream stream))
248      (defun test-ccl.42830 (a b stream)
249        (format stream "~A ~/ccl.42830/" a b))
250      (and (eq (test-ccl.42830 "a" 1 t) nil)
251           (string-equal (test-ccl.42830 "a" 1 nil) "a 1")
252           :no-errors))
253  :no-errors)
254
255
256(deftest ccl.bug#305
257    (let* ((file (test-source-file "
258  (in-package :cl-test)
259  (defclass ccl.bug#305-inner () ((ccl.bug#305-inner-slot :accessor ccl.bug#305-inner-slot)))
260  (macrolet ((generator ()
261               `(defclass ccl.bug#305 (ccl.bug#305-inner)
262                  ,(loop for i from 0 to 600
263                         for slot = (intern (format nil \"CCL.BUG#305-SLOT-~~A\" i) :cl-user)
264                         collect `(,slot :initform ,i)))))
265    (generator))
266  (defmethod initialize-instance :after ((x ccl.bug#305-inner) &key)
267    (setf (ccl.bug#305-inner-slot x) 42))
268  (defun ccl.bug#305-test () (make-instance 'ccl.bug#305))"))
269           (fasl (test-compile file)))
270      (load fasl :verbose nil)
271      (ccl.bug#305-inner-slot (ccl.bug#305-test)))
272  42)
273
274(deftest ccl.42923
275    (progn
276      (fmakunbound 'ccl.42923)
277      (defmethod ccl.42923 ((x (eql 'x)) &key y &allow-other-keys)
278        (list x y) 'x)
279      (defmethod ccl.42923 ((x (eql 'foo)) &key y &allow-other-keys)
280        (list x y) 'foo)
281      (defmethod ccl.42923 ((x (eql 'bar)) &key y z a b c)
282        (list x y z (list a b c)) 'bar)
283      (ccl::maybe-hack-eql-methods #'ccl.42923)
284      (ccl:advise ccl.42923 'advise)
285      (ccl.42923 'foo :y 1 :z 2 :a 1 :b 2 :c 3))
286  foo)
287
288(deftest ccl.bug#252a
289    (let ((pn "bug252.dat"))
290      (delete-file pn)
291      (let ((stream (open pn :direction :output :if-exists :error)))
292        (print "something" stream)
293        (close stream :abort t)
294        (probe-file pn)))
295  nil)
296
297(deftest ccl.bug#252b
298    (let ((pn "bug252.dat"))
299      (delete-file pn)
300      (let ((stream (open pn :direction :output)))
301        (format stream "something~%")
302        (close stream))
303      (let ((stream (open pn :direction :output :if-exists :supersede)))
304        (format stream "other~%")
305        (force-output stream)
306        (close stream :abort t))
307      (with-open-file (stream pn)
308        (let ((line  (read-line stream)))
309          (if (equalp line "something") :something line))))
310  :something)
311
312(deftest ccl.bug#310
313    (remove-duplicates '(1 0 1 1 1 0 0 0 1 0 1 0 1) :end 11)
314  (0 1 0 1))
315
316(deftest ccl.bug#294-1
317  (handler-case
318      (let ((ccl::*nx-safety* 1)) ;; At safety 3, we don't know from EQ...
319        (eval '(defun cl-test::ccl.bug#294-1 (x y)
320                (eq x) y)))
321    (program-error () :program-error))
322  :program-error)
323
324(deftest ccl.bug#294-2
325  (let* ((file (test-source-file
326                "(defun cl-test::ccl.bug#294-2 (x y) (eq x) y)")))
327    (fmakunbound ' cl-test::ccl.bug#294-2)
328    (handler-case (test-compile file :break-on-program-errors t)
329      (program-error () :program-error)))
330  :program-error)
331
332(deftest ccl.buf#294-3
333  (let* ((file (test-source-file
334                "(defun cl-test::ccl.bug#294-3 (x y) (eq x) y)"))
335         (warnings nil))
336    (fmakunbound ' cl-test::ccl.bug#294-3)
337    (list
338     (let ((*error-output* (make-broadcast-stream)))
339       (handler-case
340           (handler-bind ((warning (lambda (c) (setq warnings t))))
341             (test-compile file :break-on-program-errors :defer))
342         (error (c) :error)))
343     warnings))
344  (:error t))
345
346
347(deftest ccl.buf#294-4
348  (let* ((file (test-source-file
349                "(defun cl-test::ccl.bug#294-4 (x y) (eq x) y)"))
350         (warnings nil))
351    (fmakunbound 'cl-test::ccl.bug#294-4)
352    (list
353     (let ((*error-output* (make-broadcast-stream)))
354       (handler-bind ((warning (lambda (c) (setq warnings t))))
355         (test-compile file :break-on-program-errors nil :load t))
356       (handler-case (and (fboundp 'cl-test::ccl.bug#294-4)
357                          (funcall 'cl-test::ccl.bug#294-4 1 2))
358         (program-error (c) :program-error)))
359     warnings))
360  (:program-error t))
361
362(deftest ccl.bug#315
363    (let* ((file (test-source-file
364                  "(defmethod ccl.bug#315-fn ((a sequence))
365                       (reduce #'or a :key #'identity))"))
366           (warning nil))
367      (handler-bind ((warning
368                      (lambda (c)
369                        (let ((s (princ-to-string c)))
370                          (setq warning
371                                (if (and (search "FUNCTION" s) (search "macro OR" s))
372                                  (or warning :macro-or)
373                                  c))))))
374        (test-compile file :hide-warnings t :break-on-program-errors nil :load t))
375      warning)
376  :macro-or)
377
378(deftest ccl.43101a
379    (progn
380      (untrace)
381      (fmakunbound 'ccl.43101a-fun)
382      (defun ccl.43101a-fun (x) x)
383      (trace ccl.43101a-fun)
384      (let ((file (test-source-file "(defun cl-test::ccl.43101a-fun (x) (1+ x))")))
385        (test-compile file :hide-warnings t :load t))
386      (not (equal "" (with-output-to-string (*trace-output*)
387                       (assert (eql (ccl.43101a-fun 4) 5))))))
388  t)
389
390(deftest ccl.43101b
391    (progn
392      (untrace)
393      (fmakunbound 'ccl.43101b-gf)
394      (defmethod ccl.43101b-gf (x) x)
395      (trace ccl.43101b-gf)
396      (let ((file (test-source-file "(defmethod cl-test::ccl.43101b-gf (x) (1+ x))")))
397        (test-compile file :hide-warnings t :load t))
398      (not (equal "" (with-output-to-string (*trace-output*)
399                       (assert (eql (ccl.43101b-gf 4) 5))))))
400  t)
401
402
403
404(deftest ccl.file-stream-typep
405    (with-open-file (f "temp.dat" :direction :output :if-exists :supersede)
406      (funcall (lambda (f) (let ((type (type-of f)))
407                             (and (typep f 'file-stream) (subtypep type 'file-stream) t)))
408               f))
409  t)
410
411
412(deftest ccl.complex-cos
413    (< (imagpart (cos (complex 1 1))) 0)
414  t)
415
416(deftest ccl.space-symbol
417    (let* ((list '(|aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
418                   | | | | | | | | | | | | | | | | | | | | | |
419                   |aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|))
420           (result (read-from-string
421                    (with-output-to-string (s)
422                      (let ((*print-readably* t))
423                        (pprint list s))))))
424      (or (equal list result) result))
425  t)
426
427(deftest ccl.46016
428    (let ((file (test-source-file "
429  (defvar var.46016 nil)
430  (declaim (boolean var.46016))")))
431      (handler-case (progn (test-compile file :load t :break-on-program-errors nil) :no-warnings)
432        (warning (c) :warning)))
433  :no-warnings)
434
435
436#+ccl-0711
437(deftest ccl.47102
438    (handler-case
439        (progn
440          (defclass ccl.47102 () ((slot :allocation :class)))
441          ;; This happens as part of snap-reader-methods optimization
442          (ccl::optimize-make-instance-for-class-cell (gethash 'ccl.47102 ccl::%find-classes%))
443          :no-warnings)
444      (warning (c) :warning))
445  :no-warnings)
446 
447
448(deftest ccl.47762
449    (let ((file (test-source-file
450                  "(defun ccl.47762 ()
451                     (funcall (find-symbol \"TEST.47762a\" \"NO_SUCH_PACKAGE\"))
452                     (funcall (intern \"TEST.47762b\" \"NO_SUCH_PACKAGE-1\")))")))
453      (handler-case
454          (progn (test-compile file :load t) :no-error)
455        (error (c) c)))
456  :no-error)
457
458
459(deftest ccl.bug#254
460  (let ((warnings nil)
461        (test "
462(define-method-combination ccl.bug#254 ()
463         ((around (:around))
464          (before (:before))
465          (primary () :required t)
466          (after (:after)))
467   (:arguments &optional args)
468
469   (flet ((call-methods (methods)
470            (mapcar #'(lambda (method)
471                        `(call-method ,method))
472                    methods)))
473     (let ((form (if (or before after (rest primary))
474                     `(multiple-value-prog1
475                        (progn ,@(call-methods before)
476                               (call-method ,(first primary)
477                                            ,(rest primary)))
478                        ,@(call-methods (reverse after)))
479                     `(call-method ,(first primary)))))
480        `(progn (print ,args)
481       ,(if around
482           `(call-method ,(first around)
483                         (,@(rest around)
484                          (make-method ,form)))
485           form)))))
486"))
487    (handler-bind ((warning (lambda (c)
488                              (push c warnings)
489                              (muffle-warning c))))
490      (test-compile (test-source-file test)))
491    warnings)
492  ())
493
494(defun test-dup-warnings (test1 &optional test2)
495  (let ((warnings nil))
496    (handler-bind ((warning (lambda (c)
497                              (let ((msg (format nil "~a" c)))
498                                (push (if (search "Duplicate" msg :test #'equalp)
499                                        :duplicate-definition
500                                        c) warnings)
501                                (muffle-warning c)))))
502      (if test2
503        (with-compilation-unit ()
504          (test-compile (test-source-file test1) :hide-warnings t)
505          (test-compile (test-source-file test2) :hide-warnings t))
506        (test-compile (test-source-file test1 :hide-warnings t))))
507    warnings))
508
509
510
511(deftest ccl.41334-1
512    (test-dup-warnings
513     "(defun test.ccl-41334-1 (x) x)
514      (defun test.ccl-41334-1 (x) x)")
515  (:duplicate-definition))
516
517
518(deftest ccl.41334-2
519    (test-dup-warnings
520     "(defmethod test.ccl-41334-2 ((x stream)) x)
521      (defmethod test.ccl-41334-2 ((x stream)) x)")
522  (:duplicate-definition))
523
524
525(deftest ccl.41334-3
526    (test-dup-warnings
527     "(defmacro test.ccl-41334-3 (x) x)
528      (defmacro test.ccl-41334-3 (x) x)")
529  (:duplicate-definition))
530
531(deftest ccl.41334-4
532    (test-dup-warnings
533     "(defgeneric test.ccl-41334-4 (x))
534      (defun test.ccl-41334-4 (x) x)")
535  (:duplicate-definition))
536
537
538(deftest ccl.41334-1a
539    (test-dup-warnings
540     "(defun test.ccl-41334-1 (x) x)"
541     "(defun test.ccl-41334-1 (x) x)")
542  (:duplicate-definition))
543
544
545(deftest ccl.41334-2a
546    (test-dup-warnings
547     "(defmethod test.ccl-41334-2 ((x stream)) x)"
548     "(defmethod test.ccl-41334-2 ((x stream)) x)")
549  (:duplicate-definition))
550
551
552(deftest ccl.41334-3a
553    (test-dup-warnings
554     "(defmacro test.ccl-41334-3 (x) x)"
555     "(defmacro test.ccl-41334-3 (x) x)")
556  (:duplicate-definition))
557
558(deftest ccl.41334-4a
559    (test-dup-warnings
560     "(defgeneric test.ccl-41334-4 (x &key foo))"
561     "(defmacro test.ccl-41334-4 (x) x)")
562  (:duplicate-definition))
563
564
565(deftest ccl.41334-5
566    (test-dup-warnings
567     "(defclass test.41334-5 () ((41334-5-slot :accessor test.41334-5-slot)))"
568     "(defmethod (setf test.41334-5-slot) (v (x test.41334-5)) v)")
569  (:duplicate-definition))
570
571
572(deftest ccl.41334-6
573    (test-dup-warnings
574     "(defun test.41334-6 () nil)"
575     "(let ((closed nil))
576        (defun test.41334-6 () closed))")
577  (:duplicate-definition))
578
579(deftest ccl.41334-7
580    (test-dup-warnings
581     "(defun test.41334-7 () nil)"
582     "(unless (fboundp 'test.31334-7)
583        (defun test.41334-7 () t))")
584  nil)
585
586(deftest ccl.41334-8
587    (test-dup-warnings
588     "(defun (setf test.41334-8) (val) val)"
589     "(let ((closed nil))
590         (defun (setf test.41334-8) (val) val closed))")
591  (:duplicate-definition))
592
593(deftest ccl.49321
594    (test-dup-warnings
595     "(defclass ccl.49321 () ((x :initarg :x)))
596      (progn
597         (print 'ccl.49321)
598         (let ((go (defun make-ccl.49321 (&key x) (make-instance 'ccl.49321 :x x))))
599            go))")
600  nil)
601
602#+not-yet
603(deftest ccl.bug#340
604    (labels ((fact (n) (if (zerop n) 1 (* n (fact (1- n))))))
605      (let ((res (format nil "~s" (log (fact 1000) 10.0d0))))
606        (or (string-equal "2567.60464" res :end2 10) res)))
607  t)
608
609(deftest ccl.bug#344
610    (flet ((try (count)
611             (let ((cname (gensym))
612                   (gname (gensym)))
613               (eval `(progn
614                        (defclass ,cname () ())
615                        ,.(loop for n from 1 to count
616                                collect `(defmethod ,gname ((arg0 ,cname) (arg1 (eql ,n)))))))
617               (handler-case (progn (funcall gname (make-instance cname) 1) nil)
618                 (error (c) :error)))))
619      (list (try 46) (try 200)))
620  (nil nil))
621
622
623(deftest ccl.50130
624    ;; The compiler policy hack is just to have a predicatable way to catch the bug.
625    ;; It doesn't have anything to do with causing the bug to happen.
626    (let ((ccl::*default-file-compilation-policy* (ccl::new-compiler-policy :the-typechecks t))
627          (f (test-source-file "(defun cl-test::ccl.50130-fn (arr idx)
628                                  (aref (the (or (vector fixnum) (vector (unsigned-byte 8))) arr) idx))")))
629      (test-compile f :load t)
630      (funcall 'cl-test::ccl.50130-fn (make-array 4 :element-type 'fixnum :initial-element 17) 2))
631  17)
632
633(deftest ccl.50646-bug#378
634    (progn
635      (define-method-combination ccl.50646-method-combination ()
636        ((around (:around)) (primary ()))
637        `(call-method ,(first around) ((make-method (call-method ,(first primary))))))
638      (defgeneric ccl.50646-gf (x) (:method-combination ccl.50646-method-combination))
639      (defmethod ccl.50646-gf ((x integer)) x)
640      (defmethod ccl.50646-gf :around ((x integer)) (call-next-method x))
641      (ccl.50646-gf 23))
642  23)
643
644(deftest ccl.50911
645    (progn
646      (defclass ccl.50911-class () ((slot-a :initarg :a :reader ccl.50911-slot-a)))
647      (ccl::%snap-reader-method #'ccl.50911-slot-a)
648      (ccl:finalize-inheritance (find-class 'ccl.50911-class))
649      (ccl.50911-slot-a (make-instance 'ccl.50911-class :a :test)))
650  :test)
651
652(deftest ccl.50911-a
653    (let ((called 0))
654      (defclass ccl.50911-a () ())
655      (defun ccl.50911-a-fn () (make-instance 'ccl.50911-a))
656      (defmethod initialize-instance ((x ccl.50911-a) &rest keys) keys (incf called))
657      (ccl.50911-a-fn)
658      (defmethod initialize-instance :after ((x ccl.50911-a) &rest keys) keys (incf called))
659      (ccl.50911-a-fn)
660      (ccl::optimize-make-instance-for-class-name 'ccl.50911-a)
661      (ccl.50911-a-fn)
662      called)
663  5)
664
665
666(deftest ccl.bug-misc-init
667    (progn
668      (funcall (lambda () (make-array 1 :element-type '(signed-byte 16) :initial-element -1)))
669      t)
670  t)
671 
672
673;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
674;;; ADVISE
675
676(defun function-to-advise (x) (car x))
677(defun another-function-to-advise (x) (cdr x))
678(defun (setf function-to-advise) (val arg) (setf (car arg) val))
679
680(declaim (notinline function-to-advise
681                    another-function-to-advise
682                    (setf function-to-advise)))
683
684(defvar *advise-var* nil)
685
686
687(deftest advise.1
688  (progn
689    (ccl:unadvise t)
690    (function-to-advise '(a)))
691  a)
692
693(deftest advise.2
694  (progn
695    (ccl:unadvise t)
696    (ccl:advise function-to-advise (return 'advise.2))
697    (function-to-advise '(b)))
698  advise.2)
699
700(deftest advise.3
701  (progn
702    (ccl:unadvise t)
703    (ccl:advise function-to-advise 'advised.3 :when :around :name test)
704    (assert (eq 'advised.3 (function-to-advise '(a))))
705    (prog1 (ccl:advisedp t)
706      (ccl:unadvise t)
707      (assert (null (ccl:advisedp t)))))
708  ((function-to-advise :around test)))
709
710
711(deftest advise.4
712  (progn
713    (ccl:unadvise t)
714    (ccl:advise function-to-advise (return 'advise.4) :name test)
715    (handler-bind ((warning #'muffle-warning))
716      (ccl:advise function-to-advise (return 'readvised) :name test))
717    (prog1 (ccl:advisedp t)
718      (ccl:unadvise t)
719      (assert (null (ccl:advisedp t)))))
720  ((function-to-advise :before test)))
721
722(deftest advise.4a
723  (progn
724    (ccl:unadvise t)
725    (setq *advise-var* '(none))
726    (ccl:advise function-to-advise (push 'advise.4a *advise-var*) :name test)
727    (handler-bind ((warning #'muffle-warning))
728      (ccl:advise function-to-advise (push 'readvise.4a *advise-var*) :name test))
729    (assert (eq (function-to-advise '(c)) 'c))
730    *advise-var*)
731  (readvise.4a none))
732
733(deftest advise.5
734  (progn
735    (ccl:unadvise t)
736    (setq *advise-var* '(none))
737    (ccl:advise (setf function-to-advise) (push 'advise.5 *advise-var*))
738    (prog1 (ccl:advisedp t)
739      (ccl:unadvise t)
740      (assert (null (ccl:advisedp t)))))
741  (((setf function-to-advise) :before nil)))
742
743(deftest advise.6
744  (progn
745    (ccl:unadvise t)
746    (setq *advise-var* '(none))
747    (ccl:advise (setf function-to-advise) (push 'advise.6 *advise-var*))
748    (handler-bind ((warning #'muffle-warning))
749      (ccl:advise (setf function-to-advise) (push 'readvise.6 *advise-var*)))
750    (prog1 (ccl:advisedp t)
751      (ccl:unadvise t)
752      (assert (null (ccl:advisedp t)))))
753  (((setf function-to-advise) :before nil)))
754
755(deftest advise.6a
756  (progn
757    (ccl:unadvise t)
758    (setq *advise-var* '(none))
759    (ccl:advise (setf function-to-advise) (push 'advise.6a *advise-var*) :when :after)
760    (handler-bind ((warning #'muffle-warning))
761      (ccl:advise (setf function-to-advise) (push 'readvise.6a *advise-var*) :when :after))
762    (let ((x (list nil)))
763      (list* (setf (function-to-advise x) 17)
764             (car x)
765             *advise-var*)))
766  (17 17 readvise.6a none))
767
768(deftest advise.7
769  (progn
770    (ccl:unadvise t)
771    (setq *advise-var* '(none))
772    (let ((x (list nil)))
773      (assert (eql (setf (function-to-advise x) 'a) 'a))
774      (assert (equal x '(a)))
775      *advise-var*))
776  (none))
777
778(deftest advise.8
779  (progn
780    (ccl:unadvise t)
781    (setq *advise-var* '(none))
782    (ccl:advise (setf function-to-advise) (push 'advise.8 *advise-var*))
783    (let ((x (list nil)))
784      (assert (eql (setf (function-to-advise x) 'a) 'a))
785      (assert (equal x '(a)))
786      *advise-var*))
787  (advise.8 none))
788
789(deftest advise.9
790  (progn
791    (ccl:unadvise t)
792    (setq *advise-var* '(none))
793    (ccl:advise function-to-advise (push 'advise.9 *advise-var*))
794    (ccl:advise another-function-to-advise (push 'another-advise.9 *advise-var*))
795    (assert (eql (function-to-advise '(b)) 'b))
796    (assert (eql (another-function-to-advise '(c . d)) 'd))
797    (assert (equal *advise-var* '(another-advise.9 advise.9 none)))
798    (prog1
799        (sort (copy-list (ccl:advisedp t))
800              #'(lambda (k1 k2) (string< (princ-to-string k1)
801                                         (princ-to-string k2))))
802      (ccl:unadvise t)))
803  ((another-function-to-advise :before nil) (function-to-advise :before nil)))
804
805(deftest advise.10
806  (progn
807    (ccl:unadvise t)
808    (setq *advise-var* '(none))
809    (assert (null (ccl:advisedp t)))
810    (ccl:advise function-to-advise (push 'advise.10 *advise-var*))
811    (ccl:unadvise function-to-advise)
812    (assert (null (ccl:advisedp t)))
813    (handler-bind ((warning #'muffle-warning)) (ccl:unadvise function-to-advise))
814    (assert (null (ccl:advisedp t)))
815    nil)
816  nil)
817
818(deftest advise.11
819  (progn
820    (ccl:unadvise t)
821    (ccl:advise function-to-advise  (return 17))
822    (ccl:advise another-function-to-advise (return 18))
823    (ccl:unadvise function-to-advise)
824    (ccl:unadvise another-function-to-advise)
825    (ccl:advisedp t))
826  nil)
827
828;;; advising a generic function
829
830(declaim (notinline generic-function-to-advise))
831
832(deftest advise.12
833  (progn
834    (ccl:unadvise t)
835    (setq *advise-var* '(none))
836    (eval '(defgeneric generic-function-to-advise (x y)))
837    (ccl:advise generic-function-to-advise (push 'advise.12 *advise-var*))
838    (prog1 (ccl:advisedp t) (ccl:unadvise t)))
839  ((generic-function-to-advise :before nil)))
840
841(deftest advise.13
842  (progn
843    (ccl:unadvise t)
844    (setq *advise-var* '(none))
845    (eval '(defgeneric generic-function-to-advise (x y)))
846    (ccl:advise generic-function-to-advise (push 'advise.13 *advise-var*))
847    (eval '(defmethod generic-function-to-advise ((x t)(y t)) nil))
848    (prog1 (ccl:advisedp t) (ccl:unadvise t)))
849  ((generic-function-to-advise :before nil)))
850
851(deftest advise.14
852  (progn
853    (ccl:unadvise t)
854    (setq *advise-var* '(none))
855    (eval '(defgeneric generic-function-to-advise (x y)))
856    (ccl:advise generic-function-to-advise (push 'advise.14 *advise-var*))
857    (eval '(defmethod generic-function-to-advise ((x t)(y t)) nil))
858    (assert (null (generic-function-to-advise 'a 'b)))
859    (assert (equal *advise-var* '(advise.14 none)))
860    (prog1
861        (ccl:advisedp t)
862      (ccl:unadvise generic-function-to-advise)
863      (assert (null (ccl:advisedp t)))))
864  ((generic-function-to-advise :before nil)))
865
866(declaim (notinline generic-function-to-advise2))
867
868(deftest advise.15
869  (progn
870    (ccl:unadvise t)
871    (setq *advise-var* '(none))
872    (let* ((gf (eval '(defgeneric generic-function-to-advise2 (x y))))
873           (m (eval '(defmethod generic-function-to-advise2
874                       ((x integer)(y integer))
875                       :foo))))
876      (eval '(defmethod generic-function-to-advise2
877               ((x symbol)(y symbol)) :bar))
878      (assert (eql (generic-function-to-advise2 1 2) :foo))
879      (assert (eql (generic-function-to-advise2 'a 'b) :bar))
880      (ccl:advise generic-function-to-advise2 (push 'advise.15 *advise-var*))
881      (assert (equal (ccl:advisedp t) '((generic-function-to-advise2 :before nil))))
882      (remove-method gf m)
883      (prog1 (ccl:advisedp t) (ccl:unadvise t))))
884  ((generic-function-to-advise2 :before nil)))
885
886
887(deftest advise.16
888  (progn
889    (ccl:unadvise t)
890    (setq *advise-var* '(none))
891    (ccl:advise function-to-advise (push 'advise.16-1 *advise-var*) :name test-1)
892    (ccl:advise function-to-advise (push 'advise.16-2 *advise-var*) :name test-2)
893    (prog1 (cons (function-to-advise '(foo)) *advise-var*) (ccl:unadvise t)))
894  (foo advise.16-1 advise.16-2 none))
895
896(deftest advise.17
897  (progn
898    (ccl:unadvise t)
899    (setq *advise-var* '(none))
900    (untrace)
901    (ccl:advise function-to-advise (push 'advise.17-1 *advise-var*) :name test-1)
902    (trace function-to-advise)
903    (ccl:advise function-to-advise (push 'advise.17-2 *advise-var*) :name test-2)
904    (prog1
905        (list (not (equal "" (with-output-to-string (*trace-output*)
906                               (function-to-advise '(foo)))))
907              *advise-var*
908              (ccl:unadvise function-to-advise :name test-1)
909              (not (equal "" (with-output-to-string (*trace-output*)
910                               (function-to-advise '(bar)))))
911              *advise-var*
912              (untrace)
913              (with-output-to-string (*trace-output*)
914                (function-to-advise '(bar)))
915              *advise-var*)
916      (ccl:unadvise t)
917      (untrace)))
918  (t (advise.17-1 advise.17-2 none) ((function-to-advise :before test-1))
919     t (advise.17-2 advise.17-1 advise.17-2 none) (function-to-advise) ""
920     (advise.17-2 advise.17-2 advise.17-1 advise.17-2 none)))
921
922
923(deftest advise.18
924  (progn
925    (ccl:unadvise t)
926    (setq *advise-var* '(none))
927    (untrace)
928    (fmakunbound 'generic-function-to-advise.18)
929    (eval '(defgeneric generic-function-to-advise.18 (x y)))
930    (eval '(defmethod generic-function-to-advise.18 ((x integer)(y integer)) :foo))
931    (eval '(defmethod generic-function-to-advise.18 ((x symbol)(y symbol)) :bar))
932    (ccl:advise generic-function-to-advise.18 (push 'advise.18-1 *advise-var*) :name test-1)
933    (trace generic-function-to-advise.18)
934    (ccl:advise generic-function-to-advise.18 (push 'advise.18-2 *advise-var*) :name test-2)
935    (prog1
936        (list (not (equal "" (with-output-to-string (*trace-output*)
937                               (assert (eq :bar (generic-function-to-advise.18 'a 'b))))))
938              *advise-var*
939              (ccl:unadvise generic-function-to-advise.18 :name test-1)
940              (not (equal "" (with-output-to-string (*trace-output*)
941                               (assert (eq :foo (generic-function-to-advise.18 1 2))))))
942              *advise-var*
943              (untrace)
944              (with-output-to-string (*trace-output*)
945                (generic-function-to-advise.18 'x 'y))
946              *advise-var*)
947      (ccl:unadvise t)
948      (untrace)))
949  (t (advise.18-1 advise.18-2 none) ((generic-function-to-advise.18 :before test-1))
950     t (advise.18-2 advise.18-1 advise.18-2 none) (generic-function-to-advise.18) ""
951     (advise.18-2 advise.18-2 advise.18-1 advise.18-2 none)))
952
953
Note: See TracBrowser for help on using the repository browser.