test-utilities.script 13.1 KB
Newer Older
1
;;; -*- Lisp -*-
2

3
4
5
(assert
 (every #'directory-pathname-p
  (list
6
7
8
   (make-pathname* :name nil :type "" :directory '(:absolute "tmp"))
   (make-pathname* :name "" :directory '(:absolute "tmp"))
   (make-pathname* :type "" :directory '(:absolute "tmp"))
9
10
;; CLHS 19.2.2.2.3 says we can't portably specify :unspecific here,
;; and some implementations will enforce it.
11
12
13
   (make-pathname* :type *unspecific-pathname-type* :directory '(:absolute "tmp"))
   (make-pathname* :name *unspecific-pathname-type* :directory '(:absolute "tmp"))
   (make-pathname* :name *unspecific-pathname-type* :directory '(:absolute "tmp")))))
14
15
16
(assert
 (every (complement #'directory-pathname-p)
  (list
17
18
   (make-pathname* :name "foo" :type nil :directory '(:absolute "tmp"))
   (make-pathname* :name nil :type "bar" :directory '(:absolute "tmp")))))
19
;; These are funky and non portable, omit from tests:
20
21
;; (make-pathname* :name "." :type nil :directory '(:absolute "tmp"))
;; (make-pathname* :name "." :type "" :directory '(:absolute "tmp"))
22
23
24
25
26
27
28
29
30
31
32
33
(macrolet ((ts (x y)
             `(assert-equal (multiple-value-list (split-unix-namestring-directory-components ,@x))
                            ',y)))
  (ts ("" :ensure-directory t) (:relative nil nil nil))
  (ts (""  :ensure-directory nil) (:relative nil nil nil))
  (ts ("/" :ensure-directory t) (:absolute nil nil nil))
  (ts ("/" :ensure-directory nil) (:absolute nil nil nil))
  (ts ("/aa/ba" :ensure-directory t) (:absolute ("aa" "ba") nil nil))
  (ts ("/aa/ba" :ensure-directory nil) (:absolute ("aa") "ba" nil)))
(assert (version-satisfies (asdf-version) (asdf-version)))
(assert (version-satisfies (asdf-version) "3.0"))
(assert (version-satisfies (asdf-version) "2.0"))
34
35
36
(assert (version-satisfies (find-system :test-asdf) "666"))
(handler-case (version-satisfies (find-system :test-asdf) "666")
  (simple-warning (c)
37
    (assert (search "Requested version ~S but ~S has no version" (simple-condition-format-control c))))
38
39
  (:no-error (x)
    (error "version-satisfies must warn when given component without version")))
40
41
(assert (version<= "2.0" (asdf-version)))
(assert (not (version-satisfies (asdf-version) "666")))
42
(assert-pathnames-equal
43
 (split-native-pathnames-string (join-namestrings '("foo" "bar")))
44
 '(#p"foo" #p"bar"))
45
(assert-pathnames-equal
46
 (split-native-pathnames-string (join-namestrings '("foo" "bar")) :ensure-directory t)
47
 '(#p"foo/" #p"bar/"))
48
(assert-pathnames-equal
49
 (split-native-pathnames-string (join-namestrings '("/foo" "/bar")) :want-absolute t)
50
 '(#p"/foo" #p"/bar"))
51
(assert-pathnames-equal
52
 (split-native-pathnames-string (join-namestrings '("/foo" "/bar"))
53
                                :want-absolute t :ensure-directory t)
54
 '(#p"/foo/" #p"/bar/"))
55
56
57
58
59
60
61
(assert-equal
 (mapcar 'location-function-p
         '((:function f)
           (:function (lambda (path absolute-source)
                        (declare (ignore absolute-source))
                        path))
           (function previous-isnt-keyword)
62
63
           (:function f too many arguments)))
 '(t t nil nil))
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79

(initialize-source-registry '())

#|
(unless (find-system :swank nil)
  (leave-test "Cannot find SWANK" 0))

(load-system :swank)
;;(setq swank-loader::*fasl-directory* (resolve-output "slime/"))
;;(ensure-directories-exist swank-loader::*fasl-directory*)
;;(DBG :foo swank-loader::*fasl-directory*)
(swank-loader:init)
|#

(defparameter *ok-symbols*
  '(;; slots names
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
    asdf/action:accept
    asdf/action:action
    asdf/action:done-p
    asdf/action:stamp
    asdf/bundle:prologue-code
    asdf/bundle:build-args
    asdf/bundle:epilogue-code
    asdf/bundle:name-suffix
    asdf/component:absolute-pathname
    asdf/component:around-compile
    asdf/component:author
    asdf/component:children
    asdf/component:children-by-name
    asdf/component:components
    asdf/component:components-by-name
    asdf/component:default-component-class
96
97
    ;; the following is here only for backward compatibility; should be in
    ;; asdf/system. [2014/02/20:rpg]
98
    asdf/component:defsystem-depends-on
99
100
101
102
103
104
105
106
107
108
109
110
111
    asdf/component:description
    asdf/component:%encoding
    asdf/component:if-feature
    asdf/component:inline-methods
    asdf/component:in-order-to
    asdf/component:licence
    asdf/component:long-description
    asdf/component:maintainer
    asdf/component:name
    asdf/component:operation-times
    asdf/component:parent
    asdf/component:properties
    asdf/component:relative-pathname
112
    asdf/component:sideway-dependencies
113
114
    asdf/component:version
    asdf/lisp-action:flags
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
115
    asdf/operation:feature
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
116
    asdf/operation:original-initargs
117
118
119
120
121
122
123
124
125
126
127
128
    asdf/plan:index
    asdf/plan:forced
    asdf/plan:forced-not
    asdf/plan:planned-action-count
    asdf/plan:planned-output-action-count
    asdf/plan:planned-p
    asdf/plan:total-action-count
    asdf/plan:visited-actions
    asdf/plan:visiting-action-set
    asdf/plan:visiting-action-list
    asdf/system:bug-tracker
    asdf/system:build-pathname
129
    asdf/system:system-defsystem-depends-on
130
<<<<<<< HEAD
131
    asdf/system:system-depends-on
132
133
=======
>>>>>>> Fix for launchpad bug 1247662.
134
    asdf/system:system-weakly-depends-on
135
136
137
138
139
    asdf/system:entry-point
    asdf/system:homepage
    asdf/system:long-name
    asdf/system:mailto
    asdf/system:source-control
140
    ;; restarts
141
142
143
144
145
    asdf/action:accept
    asdf/find-component:retry
    asdf/find-system:coerce-entry-to-directory
    asdf/find-system:remove-entry-from-registry
    asdf/lisp-action:try-recompiling
146
    ;; types
147
    asdf/bundle:user-system
148
    #+sbcl uiop/lisp-build:sb-grovel-unknown-constant-condition
149
    ;; on some implementations only
150
    asdf/bundle:bundle-system
151
    asdf/bundle:register-pre-built-system
152
    asdf/bundle:static-library
153
154
155
156
    uiop/os:parse-file-location-info
    uiop/os:parse-windows-shortcut
    uiop/os:read-little-endian
    uiop/os:read-null-terminated-string
157
    ;; backward compatibility upgrade only
158
    asdf/backward-internals:make-sub-operation
159
160
    asdf/backward-interface:on-failure
    asdf/backward-interface:on-warnings
161
162
    asdf/find-system:contrib-sysdef-search
    asdf/find-system:sysdef-find-asdf
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
    ))

(defun defined-symbol-p (symbol)
  (or (boundp symbol)
      (fboundp symbol)
      (macro-function symbol)
      (find-class symbol nil)))

(defun fishy-exported-symbols (package &optional (ok-symbols *ok-symbols*))
  (loop :for symbol :being :the external-symbols :of package
        :unless (or
                 (defined-symbol-p symbol)
                 ;;(symbol-call :swank :classify-symbol symbol)
                 (member symbol ok-symbols))
          :collect symbol))

(defun fishy-asdf-exported-symbols ()
  (remove-duplicates
   (loop :for package :in (list-all-packages)
         :when (and (string-prefix-p "ASDF/" (package-name package))
                    (not (equal (package-name package) "ASDF/COMMON-LISP")))
           :nconc (fishy-exported-symbols package))
   :from-end t))

(assert-equal nil (fishy-asdf-exported-symbols))
188
189

(delete-package* :asdf-test-package-1)
190
191
192
193
194
195

(ensure-directories-exist (subpathname *build-directory* "deleteme/a/b/c/"))
(ensure-directories-exist (subpathname *build-directory* "deleteme/a/b/d/"))
(ensure-directories-exist (subpathname *build-directory* "deleteme/a/b/e/"))
(register-directory *asdf-directory*)
(register-directory *uiop-directory*)
196
197
198
199
200
201
202
203
(let ((new-file (subpathname *build-directory* "deleteme/a/1.x")))
  (when (probe-file new-file)
    (delete-file new-file))
  (copy-file (system-source-file :uiop) new-file))
(let ((new-file (subpathname *build-directory* "deleteme/a/b/2")))
  (when (probe-file new-file)
    (delete-file new-file))
  (copy-file (system-source-file :uiop) new-file))
204
205
206
207
208
(assert (directory-exists-p (subpathname *build-directory* "deleteme/a/b/c/")))
(assert (directory-exists-p (subpathname *build-directory* "deleteme/a/b/d/")))
(assert (directory-exists-p (subpathname *build-directory* "deleteme/a/b/e/")))
(assert (probe-file* (subpathname *build-directory* "deleteme/a/1.x")))
(assert (probe-file* (subpathname *build-directory* "deleteme/a/b/2")))
209
(DBG "check to make sure DIRECTORY-FILES doesn't list subdirectories")
210
211
(let ((directory-a (directory-files (subpathname *build-directory* "deleteme/a/")))
      (directory-b (directory-files (subpathname *build-directory* "deleteme/a/b/"))))
212
213
214
  (assert-pathnames-equal directory-a (list (subpathname *build-directory* "deleteme/a/1.x")))
  (assert-pathnames-equal directory-b (list (subpathname *build-directory* "deleteme/a/b/2"))))
(DBG "check to make sure SUBDIRECTORIES does list subdirectories")
215
216
(let ((directory-a (subdirectories (subpathname *build-directory* "deleteme/a/")))
      (directory-b (subdirectories (subpathname *build-directory* "deleteme/a/b/"))))
217
218
219
220
221
222
  (assert-pathnames-equal directory-a (list (subpathname *build-directory* "deleteme/a/b/")))
  (assert-pathnames-equal
   (sort directory-b #'string< :key #'(lambda (x) (car (last (pathname-directory x)))))
   (list (subpathname *build-directory* "deleteme/a/b/c/")
	 (subpathname *build-directory* "deleteme/a/b/d/")
	 (subpathname *build-directory* "deleteme/a/b/e/"))))
223
224
225
226
227
228
229
230
231
(delete-empty-directory (subpathname *build-directory* "deleteme/a/b/e/"))
(assert (not (directory-exists-p (subpathname *build-directory* "deleteme/a/b/e/"))))
(delete-directory-tree (subpathname *build-directory* "deleteme/")
                       :validate (lambda (x) (and (<= 5 (length (pathname-directory x)))
                                                  (subpathp x *build-directory*))))
(assert (not (directory-exists-p (subpathname *build-directory* "deleteme/a/b/c/"))))
(assert (not (directory-exists-p (subpathname *build-directory* "deleteme/a/b/d/"))))
(assert (not (probe-file* (subpathname *build-directory* "deleteme/a/1.x"))))
(assert (not (probe-file* (subpathname *build-directory* "deleteme/a/b/2"))))
232
233
234
235
236

#+(and sbcl sb-unicode) (assert +non-base-chars-exist-p+)
#+(or clozure (and sbcl (not sb-unicode))) (assert (not +non-base-chars-exist-p+))

(assert (base-string-p (make-string 10 :element-type 'base-char)))
237
238
(assert-equal "abcd" (strcat "a" nil "bc" "d"))
(assert-equal "abcd" (reduce/strcat '("a" nil "bc" "d")))
239

240
(defparameter *last-char-code* (1- (or #+allegro excl:real-char-code-limit char-code-limit)))
241
242
243
(defparameter *last-char* (code-char *last-char-code*))
(defparameter *last-char-string* (string *last-char*))

244
245
#-non-base-chars-exist-p
(progn
246
  (assert (base-string-p (make-string 10 :element-type 'character)))
247
  (assert (typep *last-char* 'base-char)))
248
249

(defun basify (s) (coerce s 'base-string))
250
(defun unbasify (s) (coerce s '(array character (*)))) ; on ECL, literals are base strings (!)
251
252

#+non-base-chars-exist-p
253
254
(progn
  (assert (not (base-string-p *last-char-string*)))
255
  (assert (not (base-string-p (make-string 10 :element-type 'character))))
256
  (assert (not (base-string-p (unbasify "abc"))))
257
  (assert (base-string-p (basify "abc")))
258
  (assert (base-string-p (strcat "a" nil #\b (unbasify "cd"))))
259
  (assert (base-string-p (reduce/strcat (mapcar 'basify '("a" "b" nil "cd")))))
260
  (assert (base-string-p (strcat (basify "ab") (basify "cd"))))
261
  (assert (not (base-string-p (strcat (basify "ab") #\c *last-char* (unbasify "d")))))
262
  (assert (base-string-p (strcat (basify "ab") #\c #\d))))
263

264
265
(assert-pathname-equal *test-directory* (getcwd))

266
267
268
269
270
271
(assert-equal +crlf+ (map 'string 'code-char '(13 10)))
(assert-equal +lf+ (map 'string 'code-char '(10)))
(assert-equal +cr+ (map 'string 'code-char '(13)))
(defparameter acrlf (strcat "a" +crlf+))
(defparameter blf (strcat "b" +lf+))
(defparameter ccr (strcat "c" +cr+))
272
273
274
275
276
277
278
279
280
281
282
283
(macrolet ((ts (x y z)
             `(progn
                (assert-equal (list ,x ,y) (multiple-value-list (stripln ,z)))
                (assert-equal (strcat ,x ,y) ,z))))
  (ts "a" +crlf+ acrlf)
  (ts "b" +lf+ blf)
  (ts "c" +cr+ ccr)
  (ts acrlf +crlf+ (strcat acrlf +crlf+))
  (ts blf +cr+ (strcat blf +cr+))
  (ts "c" +crlf+ (strcat ccr +lf+))
  (ts (strcat acrlf "b") +lf+ (strcat acrlf blf)))

284
(DBG :wtf-s)
285
(with-temporary-file (:stream s :direction :io :prefix "LEP")
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
  (println "Hello, World" s)
  (file-position s 0)
  (assert-equal (read-line s) "Hello, World"))

(DBG :wtf-p)
(let ((pn
        (with-temporary-file (:pathname pn :direction :output :prefix "LEP")
          (assert-equal (read-file-lines pn) ())
          pn)))
  (assert (not (probe-file pn))))

(DBG :wtf-s-p)
(let ((pn
        (with-temporary-file (:stream s :pathname p :keep t :direction :io :prefix "LEP")
          (println "Hello, World" s)
          (DBG :wsp s p (probe-file p))
          p)))
  (assert-equal (read-file-lines pn) '("Hello, World"))
  (delete-file pn))
305
306
307
308
309
310
311
312
313
314
315
316
317

(DBG :ensure-gethash)
(let ((h (make-hash-table :test 'equal)))
  (assert-equal (multiple-value-list (gethash 1 h 2)) '(2 nil))
  (assert-equal (multiple-value-list (ensure-gethash 1 h 2)) '(2 nil))
  (assert-equal (multiple-value-list (gethash 1 h 2)) '(2 t))
  (assert-equal (multiple-value-list (ensure-gethash 1 h 3)) '(2 t))
  (assert-equal (multiple-value-list (ensure-gethash 1 h '(error "foo"))) '(2 t))
  (signals parse-error (ensure-gethash 2 h '(error parse-error)))
  (assert-equal (multiple-value-list (gethash 3 h nil)) '(nil nil))
  (assert-equal (multiple-value-list (ensure-gethash 3 h nil)) '(nil nil))
  (assert-equal (multiple-value-list (gethash 3 h 4)) '(nil t))
  (assert-equal (multiple-value-list (ensure-gethash 3 h 5)) '(nil t)))