1 ;;; -*- Mode: Lisp; Package: Maxima; Syntax: Common-Lisp; Base: 10 -*- ;;;;
2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3 ;;; The data in this file contains enhancements. ;;;;;
5 ;;; Copyright (c) 1984,1987 by William Schelter,University of Texas ;;;;;
6 ;;; All rights reserved ;;;;;
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9 ;;; (c) Copyright 1982 Massachusetts Institute of Technology ;;;
10 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13 (macsyma-module mload
)
15 (defun load-and-tell (filename)
16 (loadfile filename t
;; means this is a lisp-level call, not user-level.
19 (defun errset-namestring (x)
21 (errset (pathname x
))))
23 (defmfun $filename_merge
(&rest file-specs
)
24 (when (or (null file-specs
) (cddr file-specs
))
25 (wna-err '$filename_merge
))
26 (setq file-specs
(mapcar #'macsyma-namestring-sub file-specs
))
27 (pathname (if (null (cdr file-specs
))
29 (merge-pathnames (cadr file-specs
) (car file-specs
)))))
31 (defun macsyma-namestring-sub (user-object)
32 (if (pathnamep user-object
) user-object
34 (cond ((and (atom user-object
) (not (symbolp user-object
)))
36 ((atom user-object
) ;hence a symbol in view of the
37 (print-invert-case (fullstrip1 user-object
))) ; first clause
39 (fullstrip (cdr user-object
)))
41 (merror (intl:gettext
"filename_merge: unexpected argument: ~M") user-object
))))
42 (namestring-try (errset-namestring system-object
)))
43 (if namestring-try
(car namestring-try
)
44 ;; know its small now, so print on same line.
45 (merror (intl:gettext
"filename_merge: unexpected argument: ~:M") user-object
)))))
47 ;; Returns the truename corresponding to a stream, or nil (for non-file streams).
48 ;; Previously we used (subtypep (type-of stream) 'file-stream) to determine whether
49 ;; a stream is a file stream, but this doesn't work on GCL.
50 (defun get-stream-truename (stream)
55 (defmfun $batchload
(filename-or-stream &aux
(*mread-prompt
* ""))
56 (declare (special *mread-prompt
*))
57 (if (streamp filename-or-stream
)
58 (batchload-stream filename-or-stream
)
60 ((filename ($file_search1 filename-or-stream
'((mlist) $file_search_maxima
))))
61 (with-open-file (in-stream filename
)
62 (batchload-stream in-stream
)))))
64 (defun batchload-stream (in-stream &key autoloading-p
)
69 (stream-truename (get-stream-truename in-stream
))
72 (setq $load_pathname
(cl:namestring stream-truename
))
73 (format nil
"~A" in-stream
)))
74 ;; If we arrived here from autoloading, call MEVAL instead of MEVAL*
75 ;; since MEVAL* is intended to be called from the interpreter top level;
76 ;; MEVAL* modifies global state, resetting VARLIST and calling CLEARSIGN.
77 (meval-fcn (symbol-function (if autoloading-p
'meval
'meval
*)))
79 (declare (special *prompt-on-read-hang
*))
81 (format t
(intl:gettext
"~&read and interpret ~A~&") in-stream-string-rep
))
85 (setq expr
(let (*prompt-on-read-hang
*) (mread in-stream nil
)))
87 do
(funcall meval-fcn
(third expr
)))
88 in-stream-string-rep
)))
90 ;;returns appropriate error or existing pathname.
91 ;; the second argument is a maxima list of variables
92 ;; each of which contains a list of paths. This is
93 ;; so users can correct the variable..
94 (defmfun $file_search1
(name search-lists
&aux lis
)
96 (setq name
(namestring name
)))
97 (setq lis
(apply '$append
(mapcar 'symbol-value
(cdr search-lists
))))
98 (let ((res ($file_search name lis
)))
100 (merror (intl:gettext
"file_search1: ~M not found in ~A.")
102 (string-trim "[]" ($sconcat search-lists
))))))
104 (defmfun $load
(filename)
105 "This is the generic file loading function.
106 LOAD(filename) will either BATCHLOAD or LOADFILE the file,
107 depending on whether the file contains Macsyma, Lisp, or Compiled
108 code. The file specifications default such that a compiled file
109 is searched for first, then a lisp file, and finally a macsyma batch
110 file. This command is designed to provide maximum utility and
111 convenience for writers of packages and users of the macsyma->lisp
114 (if (or (stringp filename
) (symbolp filename
) (pathnamep filename
))
116 ($file_search1 filename
117 '((mlist) $file_search_maxima $file_search_lisp
)))
119 (setq type
($file_type searched-for
))
122 ($batchload searched-for
))
124 ;; do something about handling errors
125 ;; during loading. Foobar fail act errors.
126 (load-and-tell searched-for
))
128 ;; UNREACHABLE MESSAGE: DEFAULT TYPE IS '$OBJECT (SEE $FILE_TYPE BELOW)
129 (merror "Maxima bug: Unknown file type ~M" type
)))
131 (merror "load: argument must be a string, symbol, or pathname; found: ~M" filename
)))
133 (defmvar $file_type_lisp
134 (list '(mlist) "l" "lsp" "lisp"))
136 (defmvar $file_type_maxima
137 (list '(mlist) "mac" "mc" "demo" "dem" "dm1" "dm2" "dm3" "dmt" "wxm"))
139 (defmfun $file_type
(fil)
140 (let ((typ ($pathname_type fil
)))
142 ((member typ
(cdr $file_type_lisp
) :test
#'string
=)
144 ((member typ
(cdr $file_type_maxima
) :test
#'string
=)
149 (defmfun $pathname_directory
(path)
150 (let ((pathname (pathname path
)))
151 (namestring (make-pathname :directory
(pathname-directory pathname
)))))
153 (defmfun $pathname_name
(path)
154 (let ((pathname (pathname path
)))
155 (pathname-name pathname
)))
157 (defmfun $pathname_type
(path)
158 (let ((pathname (pathname path
)))
159 (pathname-type pathname
)))
162 (defvar *macsyma-startup-queue
* nil
)
164 (declaim (special *mread-prompt
*))
166 ;;;; batch & demo search hacks
168 (defmfun $batch
(filename-or-stream &optional
(demo :batch
)
169 &aux tem
(possible '(:demo
:batch
:test
)))
170 "giving a second argument makes it use demo mode, ie pause after evaluation
171 of each command line"
173 ;; Try to get rid of testsuite failures on machines that are low on RAM.
176 ((setq tem
(member ($mkey demo
) possible
:test
#'eq
))
177 (setq demo
(car tem
)))
178 (t (format t
(intl:gettext
"batch: second argument must be 'demo', 'batch' or 'test'; found: ~A, assumed 'batch'~%") demo
)))
179 (if (streamp filename-or-stream
)
180 (batch-stream filename-or-stream demo
)
182 ((filename ($file_search1 filename-or-stream
184 '((mlist) $file_search_demo
)
185 '((mlist) $file_search_maxima
)))))
188 (test-batch filename nil
:show-all t
)) ;; NEED TO ACCEPT INPUT STREAM HERE TOO
190 (with-open-file (in-stream filename
)
191 (batch-stream in-stream demo
)))))))
193 (defun batch-stream (in-stream demo
)
194 (let ($load_pathname
)
197 (stream-truename (get-stream-truename in-stream
))
198 (in-stream-string-rep
200 (setq $load_pathname
(cl:namestring stream-truename
))
201 (format nil
"~A" in-stream
))))
202 (format t
(intl:gettext
"~%read and interpret ~A~%") in-stream-string-rep
)
203 (catch 'macsyma-quit
(continue :stream in-stream
:batch-or-demo-flag demo
))
205 in-stream-string-rep
)))
207 ;; When either a or b are special float values (NaN or +/-Inf), return true iff
208 ;; a and b are the both NaN or both +Inf or both -Inf.
209 ;; Note that float_approx_equal(NaN, NaN) returns true.
211 ;; When a and b to finite, nonzero floats, return true iff
213 ;; |a - b| <= float_approx_equal_tolerance * min(2^n, 2^m)
215 ;; where a = af * 2^m, |af| < 1, and m is an integer (similarly for b).
216 ;; See Knuth, "The Art of Computer Programming" (3rd ed.), Vol. 2, Sec. 4.2.2, Eq. 24, page 233.
218 ;; Note that Eq. 24 isn't well-defined for a or b equal to zero.
219 ;; To make progress, let's consider the limit as b --> 0,
220 ;; therefore n --> -inf. For any finite a, that means that min(2^n, 2^m) = 2^n
221 ;; and therefore |a - b| --> |a|, but to pass the test,
222 ;; |a| must be less than or equal to float_approx_equal_tolerance * 2^n --> 0.
223 ;; Therefore the test fails for all nonzero, finite a, when b = 0.
224 ;; i.e. when either a or b is zero but not both, return false.
226 ;; Note also that if a < 0 and b > 0 or vice versa, the test must fail:
227 ;; without loss of generality assume |a| > |b|. Then n <= m and min(2^n, 2^m) = 2^n.
228 ;; Now |a - b| = |a| + |b| since a and b are different signs.
229 ;; Then |a - b| / min(2^n, 2^m) = |a/min(2^n, 2^m)| + |b/min(2^n, 2^m)| = |af|*2^m/2^n + |bf| >= |af| + |bf| > 1.
230 ;; So unless float_approx_equal_tolerance is unusually large, the test must fail.
232 ;; Otherwise, either a or b is not a float, so return false.
234 (defmvar $float_approx_equal_tolerance
(* 8 +flonum-epsilon
+))
236 (defmfun $float_approx_equal
(a b
)
237 (setq a
(if (floatp a
) a
($float a
)))
238 (setq b
(if (floatp b
) b
($float b
)))
247 ((> (abs a
) most-positive-double-float
) (= a b
))
248 ((> (abs b
) most-positive-double-float
) nil
)
250 ((= a
0d0
) (= b
0d0
))
255 ;; Implement test without involving floating-point arithmetic,
256 ;; to avoid errors which could occur with extreme values.
257 (multiple-value-bind (a-significand a-expt a-sign
)
259 (declare (ignore a-significand
))
260 (multiple-value-bind (b-significand b-expt b-sign
)
262 (declare (ignore b-significand
))
263 (when (or (= a-sign b-sign
)
264 (>= $float_approx_equal_tolerance
1d0
))
265 (multiple-value-bind (a-b-significand a-b-expt
)
266 (integer-decode-float (abs (- a b
)))
267 (multiple-value-bind (tol-significand tol-expt
)
268 (integer-decode-float $float_approx_equal_tolerance
)
269 (or (< a-b-expt
(+ tol-expt
(min a-expt b-expt
)))
270 (and (= a-b-expt
(+ tol-expt
(min a-expt b-expt
)))
271 (<= a-b-significand tol-significand
))))))))))))
273 ;; Big float version of float_approx_equal. But for bfloat_approx_equal, the tolerance isn't
274 ;; user settable; instead, it is 32 / 2^fpprec. The factor of 32 is too large, I suppose. But
275 ;; the test suite gives a few errors with a factor of 16. These errors might be due to
276 ;; float / big float comparisons.
278 (defmfun $bfloat_approx_equal
(a b
)
279 (setq a
(if ($bfloatp a
) a
($bfloat a
)))
280 (setq b
(if ($bfloatp b
) b
($bfloat b
)))
285 (setq bits
(min (third (first a
)) (third (first b
))))
286 (setq m
(* 32 (expt 2 (- bits
)) (min (expt 2 (- (car (last a
)) 1)) (expt 2 (- (car (last b
)) 1)))))
287 (setq m
(if (rationalp m
) (div (numerator m
) (denominator m
)) m
))
288 (eq t
(mgqp m
(take '(mabs) (sub a b
)))))))
291 ;; The first argument 'f' is the expected result; the second argument
292 ;; 'g' is the output of the test. By explicit evaluation, the expected
293 ;; result *can* be a CL array, CL hashtable, or a taylor polynomial. Such
294 ;; a test would look something like (yes, it's a silly test)
297 ;; ''(taylor(x,x,0,2)
299 (defun approx-alike (f g
)
301 (cond ((floatp f
) (and (floatp g
) ($float_approx_equal f g
)))
303 (($bfloatp f
) (and ($bfloatp g
) ($bfloat_approx_equal f g
)))
306 (approx-alike 0 (sub (ratdisrep f
) (ratdisrep g
))))
309 (and (stringp g
) (string= f g
)))
313 (equal (array-dimensions f
) (array-dimensions g
))
314 (approx-alike ($listarray f
) ($listarray g
))))
317 (and (hash-table-p g
) (approx-alike ($listarray f
) ($listarray g
))))
320 (and (atom g
) (equal f g
)))
322 ((op-equalp f
'lambda
)
323 (and (op-equalp g
'lambda
)
324 (approx-alike-list (mapcar #'(lambda (s) (simplifya s nil
)) (margs f
))
325 (mapcar #'(lambda (s) (simplifya s nil
)) (margs g
)))))
328 (and ($ratp g
) (approx-alike (ratdisrep f
) (ratdisrep g
))))
330 ;; maybe we don't want this.
331 ((op-equalp f
'mquote
)
332 (approx-alike (second f
) g
))
334 ;; I'm pretty sure that (mop f) and (mop g) won't signal errors, but
335 ;; let's be extra careful.
337 ((and (consp f
) (consp (car f
)) (consp g
) (consp (car g
))
338 (or (approx-alike (mop f
) (mop g
))
339 (and (symbolp (mop f
)) (symbolp (mop g
))
340 (approx-alike ($nounify
(mop f
)) ($nounify
(mop g
)))))
341 (eq ($subvarp f
) ($subvarp g
))
342 (approx-alike-list (margs f
) (margs g
))))
346 (defun approx-alike-list (p q
)
347 (cond ((null p
) (null q
))
349 (t (and (approx-alike (first p
) (first q
)) (approx-alike-list (rest p
) (rest q
))))))
351 (defun simple-equal-p (f g
)
352 (approx-alike (simplifya f nil
) (simplifya g nil
)))
354 (defun batch-equal-check (expected result
)
355 (let ((answer (catch 'macsyma-quit
(simple-equal-p expected result
))))
356 (if (eql answer
'maxima-error
) nil answer
)))
358 (defvar *collect-errors
* t
)
360 ;; Execute the code in FILENAME as a batch file. If EXPECTED-ERRORS
361 ;; is non-NIL, it is a list of numbers denoting which tests in this
362 ;; file are expected to fail. OUT specifies the stream where any
363 ;; output goes (defaulting to *standard-output*). SHOW-EXPECTED is
364 ;; non-NIL if the expected results should also be printed. SHOW-ALL
365 ;; is non-NIL if all tests (including expected failures) should be
366 ;; shown. Finally, SHOWTIME is non-NIL if the execution time should
369 ;; This function returns four values:
371 ;; 2. NIL or a Maxima list of test numbers that failed
372 ;; 3. NIL or a Maxima list of test numbers that were expected to
373 ;; fail but actually passed.
374 ;; 4. Total number of tests in the file
375 (defun test-batch (filename expected-errors
376 &key
(out *standard-output
*) (show-expected nil
)
377 (show-all nil
) (showtime nil
))
400 (test-start-run-time 0)
401 (test-end-run-time 0)
402 (test-start-real-time 0)
403 (test-end-real-time 0))
405 (cond (*collect-errors
*
407 (if (streamp *collect-errors
*) *collect-errors
*
409 (open (alter-pathname filename
:type
"ERR") :direction
:output
:if-exists
:supersede
)
410 (file-error () nil
))))
412 (format t
(intl:gettext
"~%batch: write error log to ~a") error-log
)
413 (format error-log
(intl:gettext
"~%/* Maxima error log from tests in ~A") filename
)
414 (format error-log
" */~2%"))))
418 (setq strm
(open filename
:direction
:input
))
419 (setq start-real-time
(get-internal-real-time))
420 (setq start-run-time
(get-internal-run-time))
421 (while (not (eq 'eof
(setq expr
(mread strm
'eof
))))
423 (setq problem-lineinfo
(second (first expr
)))
424 (setq problem-lineno
(if (and (consp problem-lineinfo
) (integerp (first problem-lineinfo
)))
425 (1+ (first problem-lineinfo
))))
427 (setf tmp-output
(make-string-output-stream))
428 (setf save-output
*standard-output
*)
429 (setf *standard-output
* tmp-output
)
433 (setq test-start-run-time
(get-internal-run-time))
434 (setq test-start-real-time
(get-internal-real-time))
436 (setq result
(meval* `(($errcatch
) ,(third expr
)))))
437 (setq result
(if ($emptyp result
) 'error-catch
(second result
)))
438 (setq test-end-run-time
(get-internal-run-time))
439 (setq test-end-real-time
(get-internal-real-time))
441 (setf *standard-output
* save-output
))
443 (setq next
(mread strm
'eof
))
444 (if (eq next
'eof
) (merror (intl:gettext
"batch: missing expected result in test script.")))
446 (setq next-result
(third next
))
447 (let* ((correct (batch-equal-check next-result result
))
448 (expected-error (member i expected-errors
))
449 (pass (or correct expected-error
)))
450 (when (or show-all
(not pass
) (and correct expected-error
)
451 (and expected-error show-expected
))
452 (format out
(intl:gettext
"~%********************** Problem ~A~A***************")
453 i
(if problem-lineno
(format nil
" (line ~S) " problem-lineno
) " "))
454 (format out
(intl:gettext
"~%Input:~%"))
455 (displa (third expr
))
456 (format out
(intl:gettext
"~%~%Result:~%"))
457 (format out
"~a" (get-output-stream-string tmp-output
))
459 (when (eq showtime
'$all
)
460 (format out
(intl:gettext
"~%Time: ~,3F sec (~,3F elapsed)")
461 (float (/ (- test-end-run-time test-start-run-time
)
462 internal-time-units-per-second
))
463 (float (/ (- test-end-real-time test-start-real-time
)
464 internal-time-units-per-second
)))))
465 (cond ((and correct expected-error
)
466 (push i unexpected-pass
)
468 (intl:gettext
"~%... Which was correct, but was expected ~
469 to be wrong due to a known bug in~% Maxima or ~A.~%")
470 (lisp-implementation-type)))
472 (if show-all
(format t
(intl:gettext
"~%... Which was correct.~%"))))
473 ((and (not correct
) expected-error
)
474 (when (or show-all show-expected
)
476 (intl:gettext
"~%This is a known error in Maxima or in ~A. ~
477 The correct result is:~%")
478 (lisp-implementation-type))
479 (displa next-result
)))
480 (t (format t
(intl:gettext
"~%This differed from the expected result:~%"))
481 (push i all-differences
)
483 (cond ((and *collect-errors
* error-log
)
484 (format error-log
(intl:gettext
"/* Problem ~A~A*/~%")
485 i
(if problem-lineno
(format nil
" (line ~S) " problem-lineno
) " "))
486 (mgrind (third expr
) error-log
)
487 (list-variable-bindings (third expr
) error-log
)
488 (format error-log
";~%")
489 (format error-log
(intl:gettext
"/* Erroneous Result?:~%"))
490 (mgrind result error-log
) (format error-log
" */ ")
492 (format error-log
(intl:gettext
"/* Expected result: */~%"))
493 (mgrind next-result error-log
)
494 (format error-log
";~%~%"))))))))
496 (setq end-run-time
(get-internal-run-time))
497 (setq end-real-time
(get-internal-real-time))
499 (or (streamp *collect-errors
*)
502 ((n-expected-errors (length expected-errors
))
503 (expected-errors-trailer
504 (if (= n-expected-errors
0)
506 (format nil
(intl:gettext
" (not counting ~a expected errors)") n-expected-errors
)))
508 (format nil
(intl:gettext
" using ~,3F seconds (~,3F elapsed).~%")
509 (float (/ (- end-run-time start-run-time
) internal-time-units-per-second
))
510 (float (/ (- end-real-time start-real-time
) internal-time-units-per-second
)))
512 (cond ((null all-differences
)
513 (format t
(intl:gettext
"~a/~a tests passed~a~%~A")
514 (- num-problems n-expected-errors
) (- num-problems n-expected-errors
)
515 expected-errors-trailer
517 (when unexpected-pass
518 (multiple-value-bind (plural was-were
)
519 (if (> (length unexpected-pass
) 1)
522 (format t
(intl:gettext
"~%The following ~A problem~A passed but ~A expected to fail: ~A~%")
523 (length unexpected-pass
) plural was-were
(reverse unexpected-pass
))))
526 `((mlist) ,@(reverse unexpected-pass
))
529 (format t
(intl:gettext
"~%~a/~a tests passed~a~%~A")
530 (- num-problems n-expected-errors
(length all-differences
)) (- num-problems n-expected-errors
) expected-errors-trailer
532 (let ((s (if (> (length all-differences
) 1) "s" "")))
533 (format t
(intl:gettext
"~%The following ~A problem~A failed: ~A~%")
534 (length all-differences
) s
(reverse all-differences
)))
535 (when unexpected-pass
536 (multiple-value-bind (plural was-were
)
537 (if (> (length unexpected-pass
) 1)
540 (format t
(intl:gettext
"~%The following ~A problem~A passed but ~A expected to fail: ~A~%")
541 (length unexpected-pass
) plural was-were
(reverse unexpected-pass
))))
543 `((mlist) ,@(reverse all-differences
))
544 `((mlist) ,@(reverse unexpected-pass
))
547 ;;to keep track of global values during the error:
548 (defun list-variable-bindings (expr &optional str
&aux tem
)
549 (loop for v in
(cdr ($listofvars expr
))
550 when
(member v $values
:test
#'equal
)
551 collecting
(setq tem
`((mequal) ,v
,(meval* v
)))
553 do
(cond (str (format str
",")(mgrind tem str
)))))
556 ;; name = foo or foo.type or dir/foo.type or dir/foo
557 ;; the empty parts are filled successively from defaults in templates in
558 ;; the path. A template may use multiple {a,b,c} constructions to indicate
559 ;; multiple possibilities. eg foo.l{i,}sp or foo.{dem,dm1,dm2}
560 (defmfun $file_search
(name &optional paths
)
561 (if (and (symbolp name
)
562 (char= (char (symbol-name name
) 0) #\$
))
563 (setq name
(subseq (print-invert-case name
) 1)))
564 (if (symbolp name
) (setf name
(string name
)))
565 (if (file-exists-p name
) (return-from $file_search name
))
566 (or paths
(setq paths
($append $file_search_lisp $file_search_maxima
568 (atomchk paths
'$file_search t
)
569 (new-file-search (string name
) (cdr paths
)))
571 ;; Returns T if NAME exists and it does not appear to be a directory.
572 ;; Note that Clisp throws an error from PROBE-FILE if NAME exists
573 ;; and is a directory; hence the use of IGNORE-ERRORS.
575 (defun file-exists-p (name)
576 (let ((foo (ignore-errors (probe-file name
))))
577 (if foo
(not (apparently-a-directory-p foo
)))))
579 (defun apparently-a-directory-p (path)
580 (eq (pathname-name path
) nil
))
582 ;; We keep these here in case we want to optimize the search. To
583 ;; speed things up, we might want to support search lists like
584 ;; "share/**/*.{mac,wxm,mc}" so that we only descend the directory
585 ;; once. Then we would take the list of paths and try to match the
586 ;; one with the given extensions.
588 ;; Currently, the search list is ["share/**/*.mac", "share/**/*.wxm",
589 ;; "share/**/*.mc"]. Thus to find "foo.mc", we end up doing a
590 ;; directory 3 times.
592 (defun new-file-search (name template
)
593 (cond ((file-exists-p name
))
595 (let ((lis (loop for w in
(split-string template
"{}")
596 when
(null (position #\
, w
))
599 collect
(split-string w
","))))
600 (new-file-search1 name
"" lis
)))
603 (loop for v in template
604 when
(setq temp
(new-file-search name v
))
605 do
(return temp
))))))
608 (defun new-file-search1 (name begin lis
)
610 (let ((file (namestring ($filename_merge begin name
))))
611 (if (file-exists-p file
) file nil
)))
613 (new-file-search1 name
615 ($sconcat begin
(car lis
)) (car lis
))
617 (t (loop for v in
(car lis
) with tem
618 when
(setq tem
(new-file-search1 name begin
(cons v
(cdr lis
))))
621 (defvar *debug-new-file-search
* nil
)
623 ;; Search for a file named NAME. If the file exists, return it.
624 ;; Otherwise, TEMPLATE is a list of wildcard paths to be searched for
625 ;; the NAME. Each entry in TEMPLATE should be a Lisp wildcard
627 (defun new-file-search (name template
)
628 (cond ((file-exists-p name
))
630 (let ((filename (pathname name
)))
631 (dolist (path template
)
632 (let ((pathnames (directory (merge-pathnames filename path
))))
633 (when *debug-new-file-search
*
634 (format *debug-io
* "wildpath ~S~%" (merge-pathnames filename path
)))
636 ;; We MUST sort the results in alphabetical order
637 ;; because that's how the old search paths were
639 (setf pathnames
(sort pathnames
#'string
< :key
#'namestring
))
640 (when *debug-new-file-search
*
641 (format *debug-io
* "pathname = ~S~%" pathnames
))
642 ;; If more than one path is returned, print a warning
643 ;; that we're selecting the first file. Print all
644 ;; the matches too so the user knows.
645 (unless (= 1 (length pathnames
))
648 "More than one file matches. Selecting the first file from:~
650 (mapcar #'namestring pathnames
))))
651 (return-from new-file-search
(namestring (first pathnames
))))))))))
653 (defun save-linenumbers (&key
(c-lines t
) d-lines
(from 1) (below $linenum
) a-list
655 &aux input-symbol
($linel
79))
656 (cond ((null a-list
) (setq a-list
(loop for i from from below below collecting i
))))
657 (with-open-file (st file
:direction
:output
)
658 (format st
"/* -*- Mode: MACSYMA; Package: MACSYMA -*- */")
659 (format st
"~%~% /* ~A */ ~%"
661 (multiple-value-list (get-decoded-time)))))
662 (format nil
"~a:~a:~a" (car tem
) (cadr tem
) (caadr tem
))))
663 (loop for i in a-list
664 when
(and c-lines
(boundp (setq input-symbol
(intern (format nil
"$~A~A" '#:c i
)))))
666 (format st
"~% C~3A; " i
)
667 (mgrind (symbol-value input-symbol
) st
)
670 (boundp (setq input-symbol
(intern (format nil
"$~A~A" '#:d i
)))))
672 (format st
"~% D~3A: " i
)
673 (mgrind (symbol-value input-symbol
) st
)
677 (defmfun $printfile
(file)
678 (setq file
($file_search1 file
'((mlist) $file_search_usage
)))
679 (with-open-file (st file
)
682 while
(setq tem
(read-char st nil
'eof
))
684 (if (eq tem
'eof
) (return t
))
688 (defun disable-some-lisp-warnings ()
689 ;; Suppress warnings about redefining functions;
690 ;; it appears that only Clisp and SBCL emit these warnings
691 ;; (ECL, GCL, CMUCL, and Clozure CL apparently do not).
692 ;; Such warnings are generated by the autoload mechanism.
693 ;; I guess it is plausible that we could also avoid the warnings by
694 ;; reworking autoload to not trigger them. I don't have enough
695 ;; motivation to attempt that right now.
697 (setq sb-ext
:*muffled-warnings
* '(or sb-kernel
:redefinition-with-defun
sb-kernel:uninteresting-redefinition
))
699 (declaim (sb-ext:muffle-conditions sb-ext
:compiler-note
))
701 (setq custom
:*suppress-check-redefinition
* t
)
703 ;; Suppress compiler output messages.
704 ;; These include the "0 errors, 0 warnings" message output from Clisp,
705 ;; and maybe other messages from other Lisps.
706 (setq *compile-verbose
* nil
))
708 (defun enable-some-lisp-warnings ()
709 ;; SB-KERNEL:UNINTERESTING-REDEFINITION appears to be the default value.
711 (setq sb-ext
:*muffled-warnings
* 'sb-kernel
:uninteresting-redefinition
)
713 (declaim (sb-ext:unmuffle-conditions sb-ext
:compiler-note
))
715 (setq custom
:*suppress-check-redefinition
* nil
)
716 (setq *compile-verbose
* t
))
718 (defun simple-remove-dollarsign (x)
719 "Like stripdollar, but less heavy. Intended for use with the
720 testsuite implementation."
722 (subseq (maxima-string x
) 1)
725 (defun intersect-tests (tests)
726 ;; If TESTS is non-NIL, we assume it's a Maxima list of (maxima)
727 ;; strings naming the tests we want to run. They must match the
728 ;; file names in $testsuite_files. We ignore any items that aren't
729 ;; in $testsuite_files.
730 (mapcar #'simple-remove-dollarsign
733 ;; Using INTERSECTION would be convenient, but
734 ;; INTERSECTION can return the result in any
735 ;; order, and we'd prefer that the order of the
736 ;; tests be preserved. CMUCL and CCL returns the
737 ;; intersection in reverse order. Clisp produces
738 ;; the original order. Fortunately, this doesn't
739 ;; have to be very fast, so we do it very naively.
740 (dolist (test (mapcar #'simple-remove-dollarsign
(cdr tests
)))
741 (let ((matching-test (find test
(cdr $testsuite_files
)
743 (maxima-string (if (listp x
)
748 (push matching-test results
))))
751 (cdr $testsuite_files
)))))
753 (defun print-testsuite-summary (errs unexpected-pass error-count total-count
)
755 ((problem-summary (x)
756 ;; We want to print all the elements in the list.
757 (let ((*print-length
* nil
)
758 (s (if (> (length (rest x
)) 1) "s" "")))
761 " ~a problem~a:~% ~a~%")
764 (sort (rest x
) #'<)))))
768 "~%~%No unexpected errors found out of ~:d tests.~%")
770 (format t
(intl:gettext
"~%Error summary:~%")))
772 (format t
(intl:gettext
"Error(s) found:~%"))
773 (mapcar #'problem-summary
(reverse errs
)))
774 (when unexpected-pass
775 (format t
(intl:gettext
"Tests that were expected to fail but passed:~%"))
776 (mapcar #'problem-summary
(reverse unexpected-pass
)))
780 "~&~:d test~p failed out of ~:d total tests.~%")
785 (defun validate-given-tests (tests share-tests-p
)
786 ;; Check the test names and print out some warnings if it
787 ;; doesn't exist, or if it does and is part of the share test
788 ;; suite, but share_tests was not set.
789 (dolist (test (mapcar #'simple-remove-dollarsign
793 (cond ((and (not share-tests-p
)
794 (find test
(cdr $share_testsuite_files
)
796 (maxima-string (if (listp x
)
800 (mwarning test
"is a share test, but share_tests was not set"))
801 ((not (find test
(cdr $testsuite_files
)
803 (maxima-string (if (listp x
)
807 (mwarning "Unknown test: " test
)))))
809 (defmfun $run_testsuite
(&key tests display_all display_known_bugs share_tests time debug
)
810 "Run the testsuite. Options are
811 tests List of tests to run
812 display_all Display output from each test entry
813 display_known_bugs Include tests that are known to fail.
814 time Display time to run each test entry
815 share_tests Whether to include the share testsuite or not
816 debug Set to enable some debugging prints.
818 (enable-some-lisp-warnings)
822 (format t
"Testsuite run for ~a ~a:~%"
823 (lisp-implementation-type) (lisp-implementation-version))
824 ;; Allow only T and NIL for display_known_bugs and display_all
825 (unless (member display_known_bugs
'(t nil
))
826 (merror (intl:gettext
"run_testsuite: display_known_bugs must be true or false; found: ~M") display_known_bugs
))
827 (unless (member display_all
'(t nil
))
828 (merror (intl:gettext
"run_testsuite: display_all must be true or false; found: ~M") display_all
))
829 (unless (member time
'(t nil $all
))
830 (merror (intl:gettext
"run_testsuite: time must be true, false, or all; found: ~M") time
))
832 (unless (member share_tests
'(t nil $only
))
833 (merror (intl:gettext
"run_testsuite: share_tests must be true, false or only: found ~M") share_tests
))
835 (setq *collect-errors
* nil
)
837 (multiple-value-bind (desired-tests desired-search-path
)
841 (values $testsuite_files $file_search_tests
))
843 ;; Append the share files and concatenate the search paths
844 ;; for tests and maxima so we can find both sets of tests.
845 (values ($append $testsuite_files $share_testsuite_files
)
846 ;; Is there a better way to do this?
849 (rest $file_search_tests
)
850 (rest $file_search_maxima
))))
852 ;; Only the share test files
853 (values $share_testsuite_files $file_search_maxima
)))
854 (let* (($testsuite_files desired-tests
)
855 ($file_search_tests desired-search-path
)
857 (tests-to-run (intersect-tests (cond ((consp tests
) tests
)
858 (tests (list '(mlist) tests
)))))
866 (validate-given-tests tests share_tests
)
869 (let (($stringdisp t
))
870 (mformat t
"$testsuite_files = ~M~%" $testsuite_files
)
871 (mformat t
"$file_search_tests = ~M~%" $file_search_tests
)))
873 (let (($stringdisp t
))
874 (mformat t
"tests-to-run = ~M~%" tests-to-run
)))
877 (mwarning "No tests to run")
878 (return-from $run_testsuite
'$done
))
882 (loop with errs
= 'nil
883 with unexpected-pass
= nil
884 for testentry in tests-to-run
885 do
(if (atom testentry
)
887 (setf test-file testentry
)
888 (setf expected-failures nil
))
890 (setf test-file
(second testentry
))
891 (setf expected-failures
892 ;; Support the expected failures list in
895 ;; ((mlist) "test" 1 2 3)
896 ;; ((mlist) "test" ((mlist) 1 2 3))
898 ;; The first is the old style whereas the
899 ;; second is the new style. We support
900 ;; the old style for backward
902 (if (consp (caddr testentry
))
905 (setf test-file-path
($file_search test-file $file_search_tests
))
907 (intl:gettext
"Running tests in ~a: ")
908 (if (symbolp test-file
)
909 (subseq (print-invert-case test-file
) 1)
912 (format t
(intl:gettext
"(~A) ") test-file-path
))
916 (multiple-value-setq (filename diff upass test-count
)
917 (test-batch test-file-path
918 expected-failures
:show-expected display_known_bugs
919 :show-all display_all
:showtime time
))
920 (incf total-count test-count
)
921 (when (or (rest diff
) (rest upass
))
922 (incf error-count
(length (rest diff
)))
924 (push (list* filename
(rest diff
))
927 (push (list* filename
(rest upass
))
930 (setq error-break-file
(format nil
"~a" test-file
))
931 (push (list error-break-file
"error break")
934 (intl:gettext
"~%Caused an error break: ~a")
936 ;; If the test failed because we
937 ;; couldn't find the file, make a note of
939 (unless test-file-path
940 (format t
(intl:gettext
": test file not found.")))
943 (print-testsuite-summary errs unexpected-pass error-count total-count
))))
944 (time (testsuite))))))
945 (disable-some-lisp-warnings)