1 | ;;; rt.lisp |
---|
2 | ;;; |
---|
3 | ;;; Copyright (C) 2003 Peter Graves |
---|
4 | ;;; $Id: rt.lisp,v 1.108 2003-09-03 23:27:37 piso Exp $ |
---|
5 | ;;; |
---|
6 | ;;; This program is free software; you can redistribute it and/or |
---|
7 | ;;; modify it under the terms of the GNU General Public License |
---|
8 | ;;; as published by the Free Software Foundation; either version 2 |
---|
9 | ;;; of the License, or (at your option) any later version. |
---|
10 | ;;; |
---|
11 | ;;; This program is distributed in the hope that it will be useful, |
---|
12 | ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | ;;; GNU General Public License for more details. |
---|
15 | ;;; |
---|
16 | ;;; You should have received a copy of the GNU General Public License |
---|
17 | ;;; along with this program; if not, write to the Free Software |
---|
18 | ;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
19 | |
---|
20 | ;;; Adapted from rt.lsp and ansi-aux.lsp in the GCL ANSI test suite. |
---|
21 | |
---|
22 | #+armedbear |
---|
23 | (require 'defstruct) |
---|
24 | |
---|
25 | #+armedbear |
---|
26 | (require 'loop) |
---|
27 | |
---|
28 | (unless (find-package :regression-test) |
---|
29 | (make-package :regression-test :nicknames '(:rt)) |
---|
30 | (use-package :cl :rt)) |
---|
31 | |
---|
32 | (in-package :rt) |
---|
33 | |
---|
34 | (export '(deftest)) |
---|
35 | |
---|
36 | (defvar *prefix* "/home/peter/gcl/ansi-tests/") |
---|
37 | |
---|
38 | (defvar *compile-tests* nil) |
---|
39 | |
---|
40 | (defvar *passed* 0) |
---|
41 | (defvar *failed* 0) |
---|
42 | |
---|
43 | (defun equalp-with-case (x y) |
---|
44 | (cond |
---|
45 | ((eq x y) t) |
---|
46 | ((consp x) |
---|
47 | (and (consp y) |
---|
48 | (equalp-with-case (car x) (car y)) |
---|
49 | (equalp-with-case (cdr x) (cdr y)))) |
---|
50 | ((and (typep x 'array) |
---|
51 | (= (array-rank x) 0)) |
---|
52 | (equalp-with-case (aref x) (aref y))) |
---|
53 | ((typep x 'vector) |
---|
54 | (and (typep y 'vector) |
---|
55 | (let ((x-len (length x)) |
---|
56 | (y-len (length y))) |
---|
57 | (and (eql x-len y-len) |
---|
58 | (loop |
---|
59 | for e1 across x |
---|
60 | for e2 across y |
---|
61 | always (equalp-with-case e1 e2)))))) |
---|
62 | ((and (typep x 'array) |
---|
63 | (typep y 'array) |
---|
64 | (not (equal (array-dimensions x) |
---|
65 | (array-dimensions y)))) |
---|
66 | nil) |
---|
67 | ((typep x 'array) |
---|
68 | (and (typep y 'array) |
---|
69 | (let ((size (array-total-size x))) |
---|
70 | (loop for i from 0 below size |
---|
71 | always (equalp-with-case (row-major-aref x i) |
---|
72 | (row-major-aref y i)))))) |
---|
73 | (t (eql x y)))) |
---|
74 | |
---|
75 | (defmacro deftest (name &rest body) |
---|
76 | (format t "Test ~s~%" `,name) |
---|
77 | (finish-output) |
---|
78 | (let* ((p body) |
---|
79 | (properties |
---|
80 | (loop while (keywordp (first p)) |
---|
81 | unless (cadr p) |
---|
82 | do (error "Poorly formed deftest: ~A~%" |
---|
83 | (list* 'deftest name body)) |
---|
84 | append (list (pop p) (pop p)))) |
---|
85 | (form (pop p)) |
---|
86 | (values p)) |
---|
87 | (let* ((aborted nil) |
---|
88 | (r (handler-case (multiple-value-list |
---|
89 | (if *compile-tests* |
---|
90 | (funcall (compile nil `(lambda () ,form))) |
---|
91 | (eval `,form))) |
---|
92 | (error (c) (setf aborted t) (list c)))) |
---|
93 | (passed (and (not aborted) (equalp-with-case r `,values)))) |
---|
94 | (unless passed |
---|
95 | (format t " Expected value: ~s~%" |
---|
96 | (if (= (length `,values) 1) |
---|
97 | (car `,values) |
---|
98 | `,values)) |
---|
99 | (format t " Actual value: ~s~%" |
---|
100 | (if (= (length r) 1) |
---|
101 | (car r) |
---|
102 | r)) |
---|
103 | (finish-output)) |
---|
104 | (if passed (incf *passed*) (incf *failed*))))) |
---|
105 | |
---|
106 | (unless (find-package :cl-test) |
---|
107 | (make-package :cl-test) |
---|
108 | (use-package "COMMON-LISP" :cl-test)) |
---|
109 | |
---|
110 | (in-package :cl-test) |
---|
111 | (use-package :rt) |
---|
112 | |
---|
113 | (defvar *compiled-and-loaded-files* nil) |
---|
114 | |
---|
115 | (defun compile-and-load (filename &key force) |
---|
116 | (let* ((pathname (concatenate 'string rt::*prefix* filename)) |
---|
117 | (former-data (assoc pathname *compiled-and-loaded-files* |
---|
118 | :test #'equal)) |
---|
119 | (source-write-time (file-write-date pathname))) |
---|
120 | (unless (and (not force) |
---|
121 | former-data |
---|
122 | (>= (cadr former-data) source-write-time)) |
---|
123 | (if former-data |
---|
124 | (setf (cadr former-data) source-write-time) |
---|
125 | (push (list pathname source-write-time) *compiled-and-loaded-files*)) |
---|
126 | (load pathname)))) |
---|
127 | |
---|
128 | (in-package :cl-user) |
---|
129 | |
---|
130 | (defun do-tests (&rest args) |
---|
131 | (let ((rt::*passed* 0) (rt::*failed* 0) |
---|
132 | (suffix ".lsp") |
---|
133 | (tests (or args (list "abs" |
---|
134 | "acons" |
---|
135 | "adjoin" |
---|
136 | "and" |
---|
137 | "append" |
---|
138 | "apply" |
---|
139 | "aref" |
---|
140 | "array" |
---|
141 | "array-as-class" |
---|
142 | "array-dimension" |
---|
143 | "array-dimensions" |
---|
144 | "array-displacement" |
---|
145 | "array-in-bounds-p" |
---|
146 | "array-misc" |
---|
147 | "array-rank" |
---|
148 | "array-row-major-index" |
---|
149 | "array-t" |
---|
150 | "array-total-size" |
---|
151 | "arrayp" |
---|
152 | "assoc" |
---|
153 | "assoc-if" |
---|
154 | "assoc-if-not" |
---|
155 | "atom" |
---|
156 | "bit" |
---|
157 | "bit-vector" |
---|
158 | "bit-vector-p" |
---|
159 | "block" |
---|
160 | "boundp" |
---|
161 | "butlast" |
---|
162 | "call-arguments-limit" |
---|
163 | "case" |
---|
164 | "catch" |
---|
165 | "ccase" |
---|
166 | "ceiling" |
---|
167 | "char-compare" |
---|
168 | "char-schar" |
---|
169 | "character" |
---|
170 | "cl-symbols" |
---|
171 | "coerce" |
---|
172 | "complement" |
---|
173 | "concatenate" |
---|
174 | "cond" |
---|
175 | "cons" |
---|
176 | "cons-test-01" |
---|
177 | "cons-test-03" |
---|
178 | "cons-test-05" |
---|
179 | "consp" |
---|
180 | "constantly" |
---|
181 | "constantp" |
---|
182 | "copy-alist" |
---|
183 | "copy-list" |
---|
184 | "copy-seq" |
---|
185 | "copy-symbol" |
---|
186 | "copy-tree" |
---|
187 | "count" |
---|
188 | "count-if" |
---|
189 | "count-if-not" |
---|
190 | "ctypecase" |
---|
191 | "cxr" |
---|
192 | "defconstant" |
---|
193 | "defmacro" |
---|
194 | "defparameter" |
---|
195 | "defun" |
---|
196 | "defvar" |
---|
197 | "destructuring-bind" |
---|
198 | "ecase" |
---|
199 | "elt" |
---|
200 | "endp" |
---|
201 | "epsilons" |
---|
202 | "eql" |
---|
203 | "equal" |
---|
204 | "equalp" |
---|
205 | "error" |
---|
206 | "etypecase" |
---|
207 | "eval" |
---|
208 | "evenp" |
---|
209 | "every" |
---|
210 | "expt" |
---|
211 | "fboundp" |
---|
212 | "fceiling" |
---|
213 | "fdefinition" |
---|
214 | "ffloor" |
---|
215 | "fill" |
---|
216 | "fill-pointer" |
---|
217 | "fill-strings" |
---|
218 | "find" |
---|
219 | "find-if" |
---|
220 | "find-if-not" |
---|
221 | "flet" |
---|
222 | "floor" |
---|
223 | "fmakunbound" |
---|
224 | "fround" |
---|
225 | "ftruncate" |
---|
226 | "funcall" |
---|
227 | "function" |
---|
228 | "function-lambda-expression" |
---|
229 | "functionp" |
---|
230 | "gcd" |
---|
231 | "gensym" |
---|
232 | "get-properties" |
---|
233 | "getf" |
---|
234 | "handler-bind" |
---|
235 | "handler-case" |
---|
236 | "hash-table" |
---|
237 | "identity" |
---|
238 | "if" |
---|
239 | "intersection" |
---|
240 | "iteration" |
---|
241 | "keywordp" |
---|
242 | "labels" |
---|
243 | "lambda" |
---|
244 | "lambda-list-keywords" |
---|
245 | "lambda-parameters-limit" |
---|
246 | "last" |
---|
247 | "ldiff" |
---|
248 | "length" |
---|
249 | "let" |
---|
250 | "list" |
---|
251 | "list-length" |
---|
252 | "listp" |
---|
253 | "loop" |
---|
254 | "loop1" |
---|
255 | "loop2" |
---|
256 | "loop3" |
---|
257 | "loop4" |
---|
258 | "loop5" |
---|
259 | "loop6" |
---|
260 | "loop7" |
---|
261 | "loop8" |
---|
262 | "loop9" |
---|
263 | "loop10" |
---|
264 | "loop11" |
---|
265 | "loop12" |
---|
266 | "loop13" |
---|
267 | "loop14" |
---|
268 | "loop15" |
---|
269 | "loop16" |
---|
270 | "loop17" |
---|
271 | "make-array" |
---|
272 | "make-list" |
---|
273 | "make-sequence" |
---|
274 | "make-string" |
---|
275 | "make-symbol" |
---|
276 | "map" |
---|
277 | "map-into" |
---|
278 | "mapc" |
---|
279 | "mapcan" |
---|
280 | "mapcar" |
---|
281 | "mapcon" |
---|
282 | "mapl" |
---|
283 | "maplist" |
---|
284 | "max" |
---|
285 | "member" |
---|
286 | "member-if" |
---|
287 | "member-if-not" |
---|
288 | "merge" |
---|
289 | "min" |
---|
290 | "minus" |
---|
291 | "minusp" |
---|
292 | "mismatch" |
---|
293 | "multiple-value-bind" |
---|
294 | "multiple-value-call" |
---|
295 | "multiple-value-list" |
---|
296 | "multiple-value-prog1" |
---|
297 | "multiple-value-setq" |
---|
298 | "nbutlast" |
---|
299 | "nconc" |
---|
300 | "nil" |
---|
301 | "nintersection" |
---|
302 | "not-and-null" |
---|
303 | "notany" |
---|
304 | "notevery" |
---|
305 | "nreconc" |
---|
306 | "nreverse" |
---|
307 | "nset-difference" |
---|
308 | "nset-exclusive-or" |
---|
309 | "nstring-capitalize" |
---|
310 | "nstring-downcase" |
---|
311 | "nstring-upcase" |
---|
312 | "nsublis" |
---|
313 | "nsubst" |
---|
314 | "nsubst-if" |
---|
315 | "nsubst-if-not" |
---|
316 | "nsubstitute" |
---|
317 | "nsubstitute-if" |
---|
318 | "nsubstitute-if-not" |
---|
319 | "nth" |
---|
320 | "nth-value" |
---|
321 | "nthcdr" |
---|
322 | "number-comparison" |
---|
323 | "nunion" |
---|
324 | "oddp" |
---|
325 | "oneminus" |
---|
326 | "oneplus" |
---|
327 | "or" |
---|
328 | "packages" |
---|
329 | "pairlis" |
---|
330 | "places" |
---|
331 | "plus" |
---|
332 | "plusp" |
---|
333 | "pop" |
---|
334 | "position" |
---|
335 | "position-if" |
---|
336 | "position-if-not" |
---|
337 | "prog" |
---|
338 | "prog1" |
---|
339 | "prog2" |
---|
340 | "progn" |
---|
341 | "progv" |
---|
342 | "psetf" |
---|
343 | "psetq" |
---|
344 | "push" |
---|
345 | "pushnew" |
---|
346 | "rassoc" |
---|
347 | "rassoc-if" |
---|
348 | "rassoc-if-not" |
---|
349 | "rational" |
---|
350 | "rationalize" |
---|
351 | "reduce" |
---|
352 | "remf" |
---|
353 | "remove" |
---|
354 | "remove-duplicates" |
---|
355 | "replace" |
---|
356 | "rest" |
---|
357 | "return" |
---|
358 | "revappend" |
---|
359 | "reverse" |
---|
360 | "rotatef" |
---|
361 | "round" |
---|
362 | "row-major-aref" |
---|
363 | "rplaca" |
---|
364 | "rplacd" |
---|
365 | "sbit" |
---|
366 | "search-bitvector" |
---|
367 | "search-list" |
---|
368 | "search-string" |
---|
369 | "search-vector" |
---|
370 | "set-difference" |
---|
371 | "set-exclusive-or" |
---|
372 | "shiftf" |
---|
373 | "simple-array" |
---|
374 | "simple-array-t" |
---|
375 | "simple-bit-vector" |
---|
376 | "simple-bit-vector-p" |
---|
377 | "simple-vector-p" |
---|
378 | "some" |
---|
379 | "sort" |
---|
380 | "special-operator-p" |
---|
381 | "string" |
---|
382 | "string-capitalize" |
---|
383 | "string-comparisons" |
---|
384 | "string-downcase" |
---|
385 | "string-left-trim" |
---|
386 | "string-right-trim" |
---|
387 | "string-trim" |
---|
388 | "string-upcase" |
---|
389 | "sublis" |
---|
390 | "subseq" |
---|
391 | "subsetp" |
---|
392 | "subst" |
---|
393 | "subst-if" |
---|
394 | "subst-if-not" |
---|
395 | "substitute" |
---|
396 | "substitute-if" |
---|
397 | "substitute-if-not" |
---|
398 | "subtypep" |
---|
399 | "svref" |
---|
400 | "symbol-name" |
---|
401 | "t" |
---|
402 | "tagbody" |
---|
403 | "tailp" |
---|
404 | "times" |
---|
405 | "tree-equal" |
---|
406 | "truncate" |
---|
407 | "typecase" |
---|
408 | "union" |
---|
409 | "unless" |
---|
410 | "unwind-protect" |
---|
411 | "values" |
---|
412 | "values-list" |
---|
413 | "vector" |
---|
414 | "vector-pop" |
---|
415 | "vector-push" |
---|
416 | "vector-push-extend" |
---|
417 | "vectorp" |
---|
418 | "when" |
---|
419 | "zerop")))) |
---|
420 | (dolist (test tests) |
---|
421 | (load (concatenate 'string rt::*prefix* test suffix))) |
---|
422 | (format t "~A tests: ~A passed, ~A failed~%" |
---|
423 | (+ rt::*passed* rt::*failed*) |
---|
424 | rt::*passed* |
---|
425 | rt::*failed*) |
---|
426 | (format t "*compile-tests* was ~A~%" rt::*compile-tests*)) |
---|
427 | (values)) |
---|
428 | |
---|
429 | (defun do-all-tests (&optional (compile-tests t)) |
---|
430 | (let ((rt::*compile-tests* compile-tests)) |
---|
431 | (time (do-tests)))) |
---|
432 | |
---|
433 | #+armedbear |
---|
434 | (when (and (find-package "JVM") |
---|
435 | (fboundp 'jvm::jvm-compile)) |
---|
436 | (mapcar #'jvm::jvm-compile '(sys::list-remove-duplicates* |
---|
437 | sys::vector-remove-duplicates* |
---|
438 | remove-duplicates |
---|
439 | union |
---|
440 | nunion |
---|
441 | intersection |
---|
442 | nintersection |
---|
443 | subsetp |
---|
444 | copy-tree))) |
---|
445 | |
---|
446 | (load (concatenate 'string rt::*prefix* "char-aux.lsp")) |
---|
447 | (load (concatenate 'string rt::*prefix* "cl-symbols-aux.lsp")) |
---|
448 | (load (concatenate 'string rt::*prefix* "cl-symbol-names.lsp")) |
---|
449 | (load (concatenate 'string rt::*prefix* "ansi-aux-macros.lsp")) |
---|
450 | (load (concatenate 'string rt::*prefix* "universe.lsp")) |
---|
451 | (load (concatenate 'string rt::*prefix* "ansi-aux.lsp")) |
---|
452 | (load (concatenate 'string rt::*prefix* "array-aux.lsp")) |
---|
453 | (load (concatenate 'string rt::*prefix* "subseq-aux.lsp")) |
---|
454 | (load (concatenate 'string rt::*prefix* "cons-aux.lsp")) |
---|
455 | (load (concatenate 'string rt::*prefix* "numbers-aux.lsp")) |
---|
456 | (load (concatenate 'string rt::*prefix* "string-aux.lsp")) |
---|
457 | |
---|
458 | #+armedbear |
---|
459 | (when (and (find-package "JVM") |
---|
460 | (fboundp 'jvm::jvm-compile)) |
---|
461 | (mapcar #'jvm::jvm-compile '(rt::equalp-with-case |
---|
462 | cl-test::make-scaffold-copy |
---|
463 | cl-test::check-scaffold-copy |
---|
464 | cl-test::is-intersection))) |
---|