| 1 |
;;;; -*- Mode: Lisp; Syntax: Common-Lisp; indent-tabs-mode: nil -*- |
| 2 |
;;;; vim: set filetype=lisp tabstop=8 shiftwidth=2 expandtab: |
| 3 |
|
| 4 |
;;;; Author: Daniel Kochmański |
| 5 |
;;;; Created: 2016-11-09 |
| 6 |
;;;; Contains: PACKAGE extension tests |
| 7 |
;;;; Easter: Trump won the election today, we're doomed... |
| 8 |
|
| 9 |
(in-package :cl-test) |
| 10 |
|
| 11 |
(suite 'package-ext) |
| 12 |
|
| 13 |
(defmacro with-fresh-package (name &body body) |
| 14 |
`(progn |
| 15 |
(defpackage ,name) |
| 16 |
,@body |
| 17 |
(ext:unlock-package ',name) |
| 18 |
(delete-package ',name))) |
| 19 |
|
| 20 |
(eval-when (:compile-toplevel :load-toplevel :execute) |
| 21 |
(ignore-errors (require :package-locks))) |
| 22 |
|
| 23 |
|
| 24 |
;; package locks |
| 25 |
|
| 26 |
#+package-locks |
| 27 |
(test package-locks.trivial |
| 28 |
(is-true (ext:package-locked-p "CL")) |
| 29 |
(is-false (ext:package-locked-p "CL-USER"))) |
| 30 |
|
| 31 |
#+package-locks |
| 32 |
(test package-locks.coerce |
| 33 |
(is-true (ext:package-locked-p :CL)) |
| 34 |
(is-true (ext:package-locked-p (find-package "CL"))) |
| 35 |
(is-true (ext:package-locked-p "CL")) |
| 36 |
(signals error (ext:package-locked-p "CL1")) |
| 37 |
(signals error (ext:package-locked-p :CL1)) |
| 38 |
(signals error (ext:package-locked-p 'CL1)) |
| 39 |
(signals error (ext:package-locked-p 3))) |
| 40 |
|
| 41 |
#+package-locks |
| 42 |
(test package-locks.lock/unlock |
| 43 |
(defpackage test-pack-locks) |
| 44 |
(finishes (ext:unlock-package 'test-pack-locks)) |
| 45 |
(is-false (ext:package-locked-p 'test-pack-locks)) |
| 46 |
(finishes (ext:lock-package 'test-pack-locks)) |
| 47 |
(is-true (ext:package-locked-p 'test-pack-locks)) |
| 48 |
(signals package-error (delete-package 'test-pack-locks)) |
| 49 |
(ext:unlock-package 'test-pack-locks) |
| 50 |
(finishes (delete-package 'test-pack-locks))) |
| 51 |
|
| 52 |
#+package-locks |
| 53 |
(test package-locks.intern-locked/without-package-locks |
| 54 |
(with-fresh-package test-pack |
| 55 |
(ext:lock-package 'test-pack) |
| 56 |
(signals package-error (intern "BAH" 'test-pack)) |
| 57 |
(ext:unlock-package 'test-pack) |
| 58 |
(finishes (intern "BAH" 'test-pack)) |
| 59 |
(ext:lock-package 'test-pack) |
| 60 |
(ext:without-package-locks |
| 61 |
(is-true (ext:package-locked-p 'test-pack)) |
| 62 |
(finishes (intern "BAH2" 'test-pack))) |
| 63 |
(signals package-error (intern "BAH3" 'test-pack)))) |
| 64 |
|
| 65 |
#+package-locks |
| 66 |
(test package-locks.with-unlocked-packages |
| 67 |
(with-fresh-package test-pack |
| 68 |
(with-fresh-package test-pack2 |
| 69 |
(with-fresh-package test-pack3 |
| 70 |
(ext:lock-package 'test-pack) |
| 71 |
(ext:lock-package 'test-pack2) |
| 72 |
(is-true (ext:package-locked-p 'test-pack)) |
| 73 |
(is-true (ext:package-locked-p 'test-pack2)) |
| 74 |
(is-false (ext:package-locked-p 'test-pack3)) |
| 75 |
(ext:with-unlocked-packages (test-pack test-pack2 test-pack3) |
| 76 |
(is-false (ext:package-locked-p 'test-pack)) |
| 77 |
(is-false (ext:package-locked-p 'test-pack2)) |
| 78 |
(is-false (ext:package-locked-p 'test-pack3))) |
| 79 |
(is-true (ext:package-locked-p 'test-pack)) |
| 80 |
(is-true (ext:package-locked-p 'test-pack2)) |
| 81 |
(is-false (ext:package-locked-p 'test-pack3)) |
| 82 |
|
| 83 |
(signals error |
| 84 |
(ext:with-unlocked-packages (test-pack test-pack2 test-pack3) |
| 85 |
(is-false (ext:package-locked-p 'test-pack)) |
| 86 |
(is-false (ext:package-locked-p 'test-pack2)) |
| 87 |
(is-false (ext:package-locked-p 'test-pack3)) |
| 88 |
(error "bah"))) |
| 89 |
(is-true (ext:package-locked-p 'test-pack)) |
| 90 |
(is-true (ext:package-locked-p 'test-pack2)) |
| 91 |
(is-false (ext:package-locked-p 'test-pack3)))))) |
| 92 |
|
| 93 |
#+package-locks |
| 94 |
(test package-locks.defpackage |
| 95 |
(defpackage test-pack1 (:lock t)) |
| 96 |
(defpackage test-pack2 (:lock nil)) |
| 97 |
(defpackage test-pack3) |
| 98 |
(is-true (ext:package-locked-p :test-pack1)) |
| 99 |
(is-false (ext:package-locked-p :test-pack2)) |
| 100 |
(is-false (ext:package-locked-p :test-pack3)) |
| 101 |
(ext:unlock-package :test-pack1) |
| 102 |
(delete-package :test-pack1) |
| 103 |
(delete-package :test-pack2) |
| 104 |
(delete-package :test-pack3)) |
| 105 |
|
| 106 |
|
| 107 |
;; package local nicknames |
| 108 |
|
| 109 |
#+package-local-nicknames |
| 110 |
(test package-local-nicknames.interface |
| 111 |
(defpackage test-pack1 (:local-nicknames ("L" #:CL))) |
| 112 |
(defpackage test-pack2 (:local-nicknames ("L" #:TEST-PACK1))) |
| 113 |
(defpackage test-pack3 |
| 114 |
(:lock t) |
| 115 |
(:local-nicknames ("L1" #:TEST-PACK1) |
| 116 |
("L2" #:TEST-PACK2))) |
| 117 |
|
| 118 |
(is (= 1 (length (ext:package-local-nicknames :test-pack1)))) |
| 119 |
(is (= 1 (length (ext:package-local-nicknames :test-pack2)))) |
| 120 |
(is (= 2 (length (ext:package-local-nicknames :test-pack3)))) |
| 121 |
|
| 122 |
(is (= 2 (length (ext:package-locally-nicknamed-by-list :test-pack1)))) |
| 123 |
(is (= 1 (length (ext:package-locally-nicknamed-by-list :test-pack2)))) |
| 124 |
(is (= 1 (length (ext:package-locally-nicknamed-by-list :cl)))) |
| 125 |
|
| 126 |
(signals package-error (delete-package :test-pack3)) |
| 127 |
(signals package-error (ext:add-package-local-nickname "L0" :cl :test-pack3)) |
| 128 |
|
| 129 |
(is (ext:add-package-local-nickname "L0" :cl :test-pack2)) |
| 130 |
(is (= 2 (length (ext:package-local-nicknames :test-pack2)))) |
| 131 |
(is (= 2 (length (ext:package-locally-nicknamed-by-list :cl)))) |
| 132 |
|
| 133 |
(is (ext:remove-package-local-nickname "L0" :test-pack2)) |
| 134 |
(is (= 1 (length (ext:package-local-nicknames :test-pack2)))) |
| 135 |
(is (= 1 (length (ext:package-locally-nicknamed-by-list :cl)))) |
| 136 |
|
| 137 |
;; check if nicknaming works for real |
| 138 |
(signals simple-error (eval (read-from-string "(L:cons 1 2)"))) |
| 139 |
(let ((*package* (find-package :test-pack1))) |
| 140 |
(is-equal '(1 . 2) (eval (read-from-string "(L:cons 1 2)")))) |
| 141 |
|
| 142 |
;; test-pack3 has a reference to test-pack1, but is locked |
| 143 |
(signals package-error (delete-package :test-pack1)) |
| 144 |
|
| 145 |
(ext:package-lock :test-pack3 nil) |
| 146 |
(finishes (delete-package :test-pack1)) |
| 147 |
(is (= 0 (length (ext:package-local-nicknames :test-pack2)))) |
| 148 |
(is (= 0 (length (ext:package-locally-nicknamed-by-list :cl)))) |
| 149 |
|
| 150 |
(ignore-errors (delete-package :test-pack1)) |
| 151 |
(ignore-errors (delete-package :test-pack2)) |
| 152 |
(ignore-errors (delete-package :test-pack3))) |
| 153 |
|
| 154 |
|
| 155 |
;;; relative-package-names (interface has been removed) |
| 156 |
#+relative-package-names |
| 157 |
(test relative-package-names |
| 158 |
(defpackage eu) |
| 159 |
(defpackage eu.turtleware) |
| 160 |
(defpackage eu.turtleware.pack1) |
| 161 |
(defpackage eu.turtleware.pack2) |
| 162 |
(defpackage eu.turtle.pack1) |
| 163 |
(defpackage eu.turtle.pack2) |
| 164 |
|
| 165 |
(let ((*package* (find-package :eu.turtleware)) |
| 166 |
(parent-package (find-package :eu))) |
| 167 |
(is-eql *package* (eval (read-from-string "(find-package :.)"))) |
| 168 |
(is (eval (read-from-string "(find-package :.pack1)"))) |
| 169 |
(is (eval (read-from-string "(find-package :.pack2)"))) |
| 170 |
(is (null (eval (read-from-string "(find-package :.pack3)")))) |
| 171 |
(is (null (eval (read-from-string "(find-package :..)")))) |
| 172 |
(is-eql parent-package (eval (read-from-string "(find-package :..)"))) |
| 173 |
(is (null (eval (read-from-string "(find-package :....)"))))) |
| 174 |
|
| 175 |
(let ((*package* (find-package :eu.turtleware.pack1)) |
| 176 |
(sibling-package (find-package :eu.turtleware.pack2)) |
| 177 |
(parent-package (find-package :eu.turtleware)) |
| 178 |
(grand-package (find-package :eu))) |
| 179 |
(is-eql *package* (eval (read-from-string "(find-package :.)"))) |
| 180 |
(is (null (eval (read-from-string "(find-package :.pack1)")))) |
| 181 |
(is (null (eval (read-from-string "(find-package :.pack2)")))) |
| 182 |
(is (null (eval (read-from-string "(find-package :.pack3)")))) |
| 183 |
(is-eql parent-package (eval (read-from-string "(find-package :..)"))) |
| 184 |
(is-eql sibling-package (eval (read-from-string "(find-package :..pack2)"))) |
| 185 |
(is-eql grand-package (eval (read-from-string "(find-package :....)"))) |
| 186 |
(is-eql parent-package (eval (read-from-string "(find-package :....turtleware)"))) |
| 187 |
(is-eql sibling-package (eval (read-from-string "(find-package :....turtleware.pack2)")))) |
| 188 |
|
| 189 |
(let ((*package* (find-package :eu.turtle.pack1)) |
| 190 |
(sibling-package (find-package :eu.turtle.pack2))) |
| 191 |
(is-eql *package* (eval (read-from-string "(find-package :.)"))) |
| 192 |
(is-eql nil (eval (read-from-string "(find-package :..)"))) |
| 193 |
(is-eql sibling-package (eval (read-from-string "(find-package :..pack2)")))) |
| 194 |
|
| 195 |
(ignore-errors (delete-package :eu)) |
| 196 |
(ignore-errors (delete-package :eu.turtleware)) |
| 197 |
(ignore-errors (delete-package :eu.turtleware.pack1)) |
| 198 |
(ignore-errors (delete-package :eu.turtleware.pack2)) |
| 199 |
(ignore-errors (delete-package :eu.turtle.pack1)) |
| 200 |
(ignore-errors (delete-package :eu.turtle.pack2))) |