Raymond Toy pushed to branch issue-499-defmacro-restart-for-locked-packages at cmucl / cmucl

Commits:

1 changed file:

Changes:

  • tests/defmacro.lisp
    1
    +;;; Tests for defmacro documention and location info
    
    2
    +
    
    3
    +(defpackage :defmacro-tests
    
    4
    +  (:use :cl :lisp-unit))
    
    5
    +
    
    6
    +(in-package "DEFMACRO-TESTS")
    
    7
    +
    
    8
    +(defpackage :test-locked-package
    
    9
    +  (:use :cl))
    
    10
    +
    
    11
    +(define-test issue.499.defmacro-signals-locked-package-error
    
    12
    +  (:tag :issues)
    
    13
    +  (setf (ext:package-definition-lock (find-package :test-locked-package))
    
    14
    +	t)
    
    15
    +  ;; Without a restart-handler, defining a macro in a locked package
    
    16
    +  ;; must signal a package-locked-error.
    
    17
    +  (assert-error 'lisp::package-locked-error
    
    18
    +		(eval '(defmacro test-locked-package::foo (x)
    
    19
    +			`(list ,x)))))
    
    20
    +
    
    21
    +(define-test issue.499.defmacro-continue-restart
    
    22
    +  (:tag :issues)
    
    23
    +  (setf (ext:package-definition-lock (find-package :test-locked-package))
    
    24
    +	t)
    
    25
    +  ;; The continue restart lets the macro definition proceed.
    
    26
    +  (handler-bind
    
    27
    +      ((lisp::package-locked-error
    
    28
    +	 #'(lambda (c)
    
    29
    +	     (declare (ignore c))
    
    30
    +	     (let ((restart (find-restart 'continue)))
    
    31
    +	       (assert-true restart)
    
    32
    +	       (invoke-restart restart)))))
    
    33
    +    (eval '(defmacro test-locked-package::bar (x)
    
    34
    +	    `(list ,x))))
    
    35
    +  ;; After the restart, the macro should be defined and expand
    
    36
    +  ;; correctly.
    
    37
    +  (assert-true (macro-function 'test-locked-package::bar))
    
    38
    +  (assert-equal '(list 42)
    
    39
    +		(macroexpand-1 '(test-locked-package::bar 42))))
    
    40
    +
    
    41
    +(define-test issue.499.defmacro-unlock-restart
    
    42
    +  (:tag :issues)
    
    43
    +  (let ((package (find-package :test-locked-package)))
    
    44
    +    ;; Set the lock just in case
    
    45
    +    (setf (ext:package-definition-lock package) t)
    
    46
    +    (handler-bind
    
    47
    +	((lisp::package-locked-error
    
    48
    +	   #'(lambda (c)
    
    49
    +	       (declare (ignore c))
    
    50
    +	       (let ((restart (find-restart 'lisp::unlock-package)))
    
    51
    +		 (assert-true restart)
    
    52
    +		 (invoke-restart restart)))))
    
    53
    +      (eval '(defmacro test-locked-package::baz (x)
    
    54
    +	      `(list ,x))))
    
    55
    +    ;; Macro should be defined, the package lock should be disabled.
    
    56
    +    (assert-true (macro-function 'test-locked-package::baz))
    
    57
    +    (assert-false (ext:package-definition-lock package))
    
    58
    +    (setf (ext::package-definition-lock package) t)))
    
    59
    +
    
    60
    +(define-test issue.499.unlocked-package-no-error
    
    61
    +  (:tag :issue)
    
    62
    +  (let ((package (find-package :test-locked-package)))
    
    63
    +    (setf (ext:package-definition-lock package) nil)
    
    64
    +    (unwind-protect
    
    65
    +	 (progn
    
    66
    +	   (eval '(defmacro test-locked-package::foobar (x)
    
    67
    +		   `(list ,x)))
    
    68
    +	   (assert-true (macro-function 'test-locked-package::foobar)))
    
    69
    +      (setf (ext:package-definition-lock package) t))))