source: trunk/j/src/org/armedbear/lisp/rt.lisp @ 3603

Last change on this file since 3603 was 3603, checked in by piso, 20 years ago

integer-length

File size: 17.8 KB
Line 
1;;; rt.lisp
2;;;
3;;; Copyright (C) 2003 Peter Graves
4;;; $Id: rt.lisp,v 1.114 2003-09-08 01:46:09 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(in-package :cl-user)
107
108(intern "==>" "CL-USER")
109
110(defvar *compiled-and-loaded-files* nil)
111
112(defun compile-and-load (filename &key force)
113  (let* ((pathname (concatenate 'string rt::*prefix* filename))
114         (former-data (assoc pathname *compiled-and-loaded-files*
115           :test #'equal))
116   (source-write-time (file-write-date pathname)))
117    (unless (and (not force)
118     former-data
119     (>= (cadr former-data) source-write-time))
120      (if former-data
121    (setf (cadr former-data) source-write-time)
122          (push (list pathname source-write-time) *compiled-and-loaded-files*))
123      (load pathname))))
124
125(defpackage :cl-test
126  (:use :cl :regression-test)
127  (:nicknames)
128  (:shadow #:handler-case #:handler-bind)
129  (:import-from "COMMON-LISP-USER" #:compile-and-load "==>")
130  (:export #:random-from-seq #:random-case #:coin #:random-permute))
131
132(load (concatenate 'string rt::*prefix* "ansi-aux-macros.lsp"))
133
134(defun do-tests (&rest args)
135  (let ((rt::*passed* 0) (rt::*failed* 0)
136        (suffix ".lsp")
137        (tests (or args (list "abs"
138                              "acons"
139                              "adjoin"
140                              "and"
141                              "append"
142                              "apply"
143                              "aref"
144                              "array"
145                              "array-as-class"
146                              "array-dimension"
147                              "array-dimensions"
148                              "array-displacement"
149                              "array-in-bounds-p"
150                              "array-misc"
151                              "array-rank"
152                              "array-row-major-index"
153                              "array-t"
154                              "array-total-size"
155                              "arrayp"
156                              "ash"
157                              "assoc"
158                              "assoc-if"
159                              "assoc-if-not"
160                              "atom"
161                              "bit"
162                              "bit-vector"
163                              "bit-vector-p"
164                              "block"
165                              "boundp"
166                              "butlast"
167                              "call-arguments-limit"
168                              "case"
169                              "catch"
170                              "ccase"
171                              "ceiling"
172                              "char-compare"
173                              "char-schar"
174                              "character"
175                              "cl-symbols"
176                              "coerce"
177                              "complement"
178                              "concatenate"
179                              "cond"
180                              "cons"
181                              "cons-test-01"
182                              "cons-test-03"
183                              "cons-test-05"
184                              "consp"
185                              "constantly"
186                              "constantp"
187                              "copy-alist"
188                              "copy-list"
189                              "copy-seq"
190                              "copy-symbol"
191                              "copy-tree"
192                              "count"
193                              "count-if"
194                              "count-if-not"
195                              "ctypecase"
196                              "cxr"
197                              "defconstant"
198                              "defmacro"
199                              "defparameter"
200                              "defun"
201                              "defvar"
202                              "destructuring-bind"
203                              "divide"
204                              "ecase"
205                              "elt"
206                              "endp"
207                              "epsilons"
208                              "eql"
209                              "equal"
210                              "equalp"
211                              "error"
212                              "etypecase"
213                              "eval"
214                              "evenp"
215                              "every"
216                              "expt"
217                              "fboundp"
218                              "fceiling"
219                              "fdefinition"
220                              "ffloor"
221                              "fill"
222                              "fill-pointer"
223                              "fill-strings"
224                              "find"
225                              "find-if"
226                              "find-if-not"
227                              "flet"
228                              "floor"
229                              "fmakunbound"
230                              "fround"
231                              "ftruncate"
232                              "funcall"
233                              "function"
234                              "function-lambda-expression"
235                              "functionp"
236                              "gcd"
237                              "gensym"
238                              "get-properties"
239                              "getf"
240                              "handler-bind"
241                              "handler-case"
242                              "hash-table"
243                              "identity"
244                              "if"
245                              "integer-length"
246                              "intersection"
247                              "iteration"
248                              "keywordp"
249                              "labels"
250                              "lambda"
251                              "lambda-list-keywords"
252                              "lambda-parameters-limit"
253                              "last"
254                              "ldiff"
255                              "length"
256                              "let"
257                              "list"
258                              "list-length"
259                              "listp"
260                              "loop"
261                              "loop1"
262                              "loop2"
263                              "loop3"
264                              "loop4"
265                              "loop5"
266                              "loop6"
267                              "loop7"
268                              "loop8"
269                              "loop9"
270                              "loop10"
271                              "loop11"
272                              "loop12"
273                              "loop13"
274                              "loop14"
275                              "loop15"
276                              "loop16"
277                              "loop17"
278                              "make-array"
279                              "make-list"
280                              "make-sequence"
281                              "make-string"
282                              "make-symbol"
283                              "map"
284                              "map-into"
285                              "mapc"
286                              "mapcan"
287                              "mapcar"
288                              "mapcon"
289                              "mapl"
290                              "maplist"
291                              "max"
292                              "member"
293                              "member-if"
294                              "member-if-not"
295                              "merge"
296                              "min"
297                              "minus"
298                              "minusp"
299                              "mismatch"
300                              "multiple-value-bind"
301                              "multiple-value-call"
302                              "multiple-value-list"
303                              "multiple-value-prog1"
304                              "multiple-value-setq"
305                              "nbutlast"
306                              "nconc"
307                              "nil"
308                              "nintersection"
309                              "not-and-null"
310                              "notany"
311                              "notevery"
312                              "nreconc"
313                              "nreverse"
314                              "nset-difference"
315                              "nset-exclusive-or"
316                              "nstring-capitalize"
317                              "nstring-downcase"
318                              "nstring-upcase"
319                              "nsublis"
320                              "nsubst"
321                              "nsubst-if"
322                              "nsubst-if-not"
323                              "nsubstitute"
324                              "nsubstitute-if"
325                              "nsubstitute-if-not"
326                              "nth"
327                              "nth-value"
328                              "nthcdr"
329                              "number-comparison"
330                              "nunion"
331                              "oddp"
332                              "oneminus"
333                              "oneplus"
334                              "or"
335                              "packages"
336                              "pairlis"
337                              "parse-integer"
338                              "places"
339                              "plus"
340                              "plusp"
341                              "pop"
342                              "position"
343                              "position-if"
344                              "position-if-not"
345                              "prog"
346                              "prog1"
347                              "prog2"
348                              "progn"
349                              "progv"
350                              "psetf"
351                              "psetq"
352                              "push"
353                              "pushnew"
354                              "rassoc"
355                              "rassoc-if"
356                              "rassoc-if-not"
357                              "rational"
358                              "rationalize"
359                              "reduce"
360                              "remf"
361                              "remove"
362                              "remove-duplicates"
363                              "replace"
364                              "rest"
365                              "return"
366                              "revappend"
367                              "reverse"
368                              "rotatef"
369                              "round"
370                              "row-major-aref"
371                              "rplaca"
372                              "rplacd"
373                              "sbit"
374                              "search-bitvector"
375                              "search-list"
376                              "search-string"
377                              "search-vector"
378                              "set-difference"
379                              "set-exclusive-or"
380                              "shiftf"
381                              "signum"
382                              "simple-array"
383                              "simple-array-t"
384                              "simple-bit-vector"
385                              "simple-bit-vector-p"
386                              "simple-vector-p"
387                              "some"
388                              "sort"
389                              "special-operator-p"
390                              "string"
391                              "string-capitalize"
392                              "string-comparisons"
393                              "string-downcase"
394                              "string-left-trim"
395                              "string-right-trim"
396                              "string-trim"
397                              "string-upcase"
398                              "sublis"
399                              "subseq"
400                              "subsetp"
401                              "subst"
402                              "subst-if"
403                              "subst-if-not"
404                              "substitute"
405                              "substitute-if"
406                              "substitute-if-not"
407                              "subtypep"
408                              "svref"
409                              "symbol-name"
410                              "t"
411                              "tagbody"
412                              "tailp"
413                              "times"
414                              "tree-equal"
415                              "truncate"
416                              "typecase"
417                              "union"
418                              "unless"
419                              "unwind-protect"
420                              "values"
421                              "values-list"
422                              "vector"
423                              "vector-pop"
424                              "vector-push"
425                              "vector-push-extend"
426                              "vectorp"
427                              "when"
428                              "zerop"))))
429    (dolist (test tests)
430      (load (concatenate 'string rt::*prefix* test suffix)))
431    (format t "~A tests: ~A passed, ~A failed~%"
432            (+ rt::*passed* rt::*failed*)
433            rt::*passed*
434            rt::*failed*)
435    (format t "*compile-tests* was ~A~%" rt::*compile-tests*))
436  (values))
437
438(defun do-all-tests (&optional (compile-tests t))
439  (let ((rt::*compile-tests* compile-tests))
440    (time (do-tests))))
441
442#+armedbear
443(when (and (find-package "JVM")
444           (fboundp 'jvm::jvm-compile))
445  (mapcar #'jvm::jvm-compile '(sys::list-remove-duplicates*
446                               sys::vector-remove-duplicates*
447                               remove-duplicates
448                               union
449                               nunion
450                               intersection
451                               nintersection
452                               subsetp
453                               copy-tree)))
454
455(load (concatenate 'string rt::*prefix* "char-aux.lsp"))
456(load (concatenate 'string rt::*prefix* "cl-symbols-aux.lsp"))
457(load (concatenate 'string rt::*prefix* "cl-symbol-names.lsp"))
458(load (concatenate 'string rt::*prefix* "universe.lsp"))
459(load (concatenate 'string rt::*prefix* "ansi-aux.lsp"))
460(load (concatenate 'string rt::*prefix* "array-aux.lsp"))
461(load (concatenate 'string rt::*prefix* "subseq-aux.lsp"))
462(load (concatenate 'string rt::*prefix* "cons-aux.lsp"))
463(load (concatenate 'string rt::*prefix* "numbers-aux.lsp"))
464(load (concatenate 'string rt::*prefix* "string-aux.lsp"))
465
466#+armedbear
467(when (and (find-package "JVM")
468           (fboundp 'jvm::jvm-compile))
469  (mapcar #'jvm::jvm-compile '(rt::equalp-with-case
470                               cl-test::make-scaffold-copy
471                               cl-test::check-scaffold-copy
472                               cl-test::is-intersection)))
Note: See TracBrowser for help on using the repository browser.