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"
172 (declare (special $batch_answers_from_file
))
174 ;; Try to get rid of testsuite failures on machines that are low on RAM.
177 ((setq tem
(member ($mkey demo
) possible
:test
#'eq
))
178 (setq demo
(car tem
)))
179 (t (format t
(intl:gettext
"batch: second argument must be 'demo', 'batch' or 'test'; found: ~A, assumed 'batch'~%") demo
)))
180 (if (streamp filename-or-stream
)
181 (batch-stream filename-or-stream demo
)
183 ((filename ($file_search1 filename-or-stream
185 '((mlist) $file_search_demo
)
186 '((mlist) $file_search_maxima
)))))
189 (test-batch filename nil
:show-all t
))
191 (with-open-file (in-stream filename
)
192 (batch-stream in-stream demo
)))))))
194 (defun batch-stream (in-stream demo
)
195 (declare (special $batch_answers_from_file
))
196 (let ($load_pathname
)
199 (stream-truename (get-stream-truename in-stream
))
200 (in-stream-string-rep
202 (setq $load_pathname
(cl:namestring stream-truename
))
203 (format nil
"~A" in-stream
)))
204 (*query-io
* (if $batch_answers_from_file
205 (make-two-way-stream in-stream
(make-string-output-stream)) *query-io
*)))
206 (format t
(intl:gettext
"~%read and interpret ~A~%") in-stream-string-rep
)
207 (catch 'macsyma-quit
(continue :stream in-stream
:batch-or-demo-flag demo
))
209 in-stream-string-rep
)))
211 ;; When either a or b are special float values (NaN or +/-Inf), return true iff
212 ;; a and b are the both NaN or both +Inf or both -Inf.
213 ;; Note that float_approx_equal(NaN, NaN) returns true.
215 ;; When a and b to finite, nonzero floats, return true iff
217 ;; |a - b| <= float_approx_equal_tolerance * min(2^n, 2^m)
219 ;; where a = af * 2^m, |af| < 1, and m is an integer (similarly for b).
220 ;; See Knuth, "The Art of Computer Programming" (3rd ed.), Vol. 2, Sec. 4.2.2, Eq. 24, page 233.
222 ;; Note that Eq. 24 isn't well-defined for a or b equal to zero.
223 ;; To make progress, let's consider the limit as b --> 0,
224 ;; therefore n --> -inf. For any finite a, that means that min(2^n, 2^m) = 2^n
225 ;; and therefore |a - b| --> |a|, but to pass the test,
226 ;; |a| must be less than or equal to float_approx_equal_tolerance * 2^n --> 0.
227 ;; Therefore the test fails for all nonzero, finite a, when b = 0.
228 ;; i.e. when either a or b is zero but not both, return false.
230 ;; Note also that if a < 0 and b > 0 or vice versa, the test must fail:
231 ;; without loss of generality assume |a| > |b|. Then n <= m and min(2^n, 2^m) = 2^n.
232 ;; Now |a - b| = |a| + |b| since a and b are different signs.
233 ;; 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.
234 ;; So unless float_approx_equal_tolerance is unusually large, the test must fail.
236 ;; Otherwise, either a or b is not a float, so return false.
238 (defmvar $float_approx_equal_tolerance
(* 8 +flonum-epsilon
+))
240 (defmfun $float_approx_equal
(a b
)
241 (setq a
(if (floatp a
) a
($float a
)))
242 (setq b
(if (floatp b
) b
($float b
)))
251 ((> (abs a
) most-positive-double-float
) (= a b
))
252 ((> (abs b
) most-positive-double-float
) nil
)
254 ((= a
0d0
) (= b
0d0
))
259 ;; Implement test without involving floating-point arithmetic,
260 ;; to avoid errors which could occur with extreme values.
261 (multiple-value-bind (a-significand a-expt a-sign
)
263 (declare (ignore a-significand
))
264 (multiple-value-bind (b-significand b-expt b-sign
)
266 (declare (ignore b-significand
))
267 (when (or (= a-sign b-sign
)
268 (>= $float_approx_equal_tolerance
1d0
))
269 (multiple-value-bind (a-b-significand a-b-expt
)
270 (integer-decode-float (abs (- a b
)))
271 (multiple-value-bind (tol-significand tol-expt
)
272 (integer-decode-float $float_approx_equal_tolerance
)
273 (or (< a-b-expt
(+ tol-expt
(min a-expt b-expt
)))
274 (and (= a-b-expt
(+ tol-expt
(min a-expt b-expt
)))
275 (<= a-b-significand tol-significand
))))))))))))
277 ;; Big float version of float_approx_equal. But for bfloat_approx_equal, the tolerance isn't
278 ;; user settable; instead, it is 32 / 2^fpprec. The factor of 32 is too large, I suppose. But
279 ;; the test suite gives a few errors with a factor of 16. These errors might be due to
280 ;; float / big float comparisons.
282 (defmfun $bfloat_approx_equal
(a b
)
283 (setq a
(if ($bfloatp a
) a
($bfloat a
)))
284 (setq b
(if ($bfloatp b
) b
($bfloat b
)))
289 (setq bits
(min (third (first a
)) (third (first b
))))
290 (setq m
(* 32 (expt 2 (- bits
)) (min (expt 2 (- (car (last a
)) 1)) (expt 2 (- (car (last b
)) 1)))))
291 (setq m
(if (rationalp m
) (div (numerator m
) (denominator m
)) m
))
292 (eq t
(mgqp m
(take '(mabs) (sub a b
)))))))
295 ;; The first argument 'f' is the expected result; the second argument
296 ;; 'g' is the output of the test. By explicit evaluation, the expected
297 ;; result *can* be a CL array, CL hashtable, or a taylor polynomial. Such
298 ;; a test would look something like (yes, it's a silly test)
301 ;; ''(taylor(x,x,0,2)
303 (defun approx-alike (f g
)
305 (cond ((floatp f
) (and (floatp g
) ($float_approx_equal f g
)))
307 (($bfloatp f
) (and ($bfloatp g
) ($bfloat_approx_equal f g
)))
310 (approx-alike 0 (sub (ratdisrep f
) (ratdisrep g
))))
313 (and (stringp g
) (string= f g
)))
317 (equal (array-dimensions f
) (array-dimensions g
))
318 (approx-alike ($listarray f
) ($listarray g
))))
321 (and (hash-table-p g
) (approx-alike ($listarray f
) ($listarray g
))))
324 (and (atom g
) (equal f g
)))
326 ((op-equalp f
'lambda
)
327 (and (op-equalp g
'lambda
)
328 (approx-alike-list (mapcar #'(lambda (s) (simplifya s nil
)) (margs f
))
329 (mapcar #'(lambda (s) (simplifya s nil
)) (margs g
)))))
332 (and ($ratp g
) (approx-alike (ratdisrep f
) (ratdisrep g
))))
334 ;; maybe we don't want this.
335 ((op-equalp f
'mquote
)
336 (approx-alike (second f
) g
))
338 ;; I'm pretty sure that (mop f) and (mop g) won't signal errors, but
339 ;; let's be extra careful.
341 ((and (consp f
) (consp (car f
)) (consp g
) (consp (car g
))
342 (or (approx-alike (mop f
) (mop g
))
343 (and (symbolp (mop f
)) (symbolp (mop g
))
344 (approx-alike ($nounify
(mop f
)) ($nounify
(mop g
)))))
345 (eq ($subvarp f
) ($subvarp g
))
346 (approx-alike-list (margs f
) (margs g
))))
350 (defun approx-alike-list (p q
)
351 (cond ((null p
) (null q
))
353 (t (and (approx-alike (first p
) (first q
)) (approx-alike-list (rest p
) (rest q
))))))
355 (defun simple-equal-p (f g
)
356 (approx-alike (simplifya f nil
) (simplifya g nil
)))
358 (defun batch-equal-check (expected result
)
359 (let ((answer (catch 'macsyma-quit
(simple-equal-p expected result
))))
360 (if (eql answer
'maxima-error
) nil answer
)))
362 (defvar *collect-errors
* t
)
364 ;; Execute the code in FILENAME as a batch file. If EXPECTED-ERRORS
365 ;; is non-NIL, it is a list of numbers denoting which tests in this
366 ;; file are expected to fail. OUT specifies the stream where any
367 ;; output goes (defaulting to *standard-output*). SHOW-EXPECTED is
368 ;; non-NIL if the expected results should also be printed. SHOW-ALL
369 ;; is non-NIL if all tests (including expected failures) should be
370 ;; shown. Finally, SHOWTIME is non-NIL if the execution time should
373 ;; This function returns four values:
375 ;; 2. NIL or a Maxima list of test numbers that failed
376 ;; 3. NIL or a Maxima list of test numbers that were expected to
377 ;; fail but actually passed.
378 ;; 4. Total number of tests in the file
379 (defun test-batch (filename expected-errors
380 &key
(out *standard-output
*) (show-expected nil
)
381 (show-all nil
) (showtime nil
))
382 (declare (special $batch_answers_from_file
))
404 (test-start-run-time 0)
405 (test-end-run-time 0)
406 (test-start-real-time 0)
407 (test-end-real-time 0)
408 (*query-io
* *query-io
*)
409 (*standard-input
* *standard-input
*))
411 (cond (*collect-errors
*
413 (if (streamp *collect-errors
*) *collect-errors
*
415 (open (alter-pathname filename
:type
"ERR") :direction
:output
:if-exists
:supersede
)
416 (file-error () nil
))))
418 (format t
(intl:gettext
"~%batch: write error log to ~a") error-log
)
419 (format error-log
(intl:gettext
"~%/* Maxima error log from tests in ~A") filename
)
420 (format error-log
" */~2%"))))
424 (setq strm
(open filename
:direction
:input
))
425 (when $batch_answers_from_file
426 (setq *query-io
* (make-two-way-stream strm out
)))
427 (setq start-real-time
(get-internal-real-time))
428 (setq start-run-time
(get-internal-run-time))
429 (while (not (eq 'eof
(setq expr
(mread strm
'eof
))))
431 (setq problem-lineinfo
(second (first expr
)))
432 (setq problem-lineno
(if (and (consp problem-lineinfo
) (integerp (first problem-lineinfo
)))
433 (1+ (first problem-lineinfo
))))
435 (setf tmp-output
(make-string-output-stream))
436 (setf save-output
*standard-output
*)
437 (setf *standard-output
* tmp-output
)
441 (setq test-start-run-time
(get-internal-run-time))
442 (setq test-start-real-time
(get-internal-real-time))
444 (setq result
(meval* `(($errcatch
) ,(third expr
)))))
445 (setq result
(if ($emptyp result
) 'error-catch
(second result
)))
446 (setq test-end-run-time
(get-internal-run-time))
447 (setq test-end-real-time
(get-internal-real-time))
449 (setf *standard-output
* save-output
))
451 (setq next
(mread strm
'eof
))
452 (if (eq next
'eof
) (merror (intl:gettext
"batch: missing expected result in test script.")))
454 (setq next-result
(third next
))
455 (let* ((correct (batch-equal-check next-result result
))
456 (expected-error (member i expected-errors
))
457 (pass (or correct expected-error
)))
458 (when (or show-all
(not pass
) (and correct expected-error
)
459 (and expected-error show-expected
))
460 (format out
(intl:gettext
"~%********************** Problem ~A~A***************")
461 i
(if problem-lineno
(format nil
" (line ~S) " problem-lineno
) " "))
462 (format out
(intl:gettext
"~%Input:~%"))
463 (displa (third expr
))
464 (format out
(intl:gettext
"~%~%Result:~%"))
465 (format out
"~a" (get-output-stream-string tmp-output
))
467 (when (eq showtime
'$all
)
468 (format out
(intl:gettext
"~%Time: ~,3F sec (~,3F elapsed)")
469 (float (/ (- test-end-run-time test-start-run-time
)
470 internal-time-units-per-second
))
471 (float (/ (- test-end-real-time test-start-real-time
)
472 internal-time-units-per-second
)))))
473 (cond ((and correct expected-error
)
474 (push i unexpected-pass
)
476 (intl:gettext
"~%... Which was correct, but was expected ~
477 to be wrong due to a known bug in~% Maxima or ~A.~%")
478 (lisp-implementation-type)))
480 (if show-all
(format t
(intl:gettext
"~%... Which was correct.~%"))))
481 ((and (not correct
) expected-error
)
482 (when (or show-all show-expected
)
484 (intl:gettext
"~%This is a known error in Maxima or in ~A. ~
485 The correct result is:~%")
486 (lisp-implementation-type))
487 (displa next-result
)))
488 (t (format t
(intl:gettext
"~%This differed from the expected result:~%"))
489 (push i all-differences
)
491 (cond ((and *collect-errors
* error-log
)
492 (format error-log
(intl:gettext
"/* Problem ~A~A*/~%")
493 i
(if problem-lineno
(format nil
" (line ~S) " problem-lineno
) " "))
494 (mgrind (third expr
) error-log
)
495 (list-variable-bindings (third expr
) error-log
)
496 (format error-log
";~%")
497 (format error-log
(intl:gettext
"/* Erroneous Result?:~%"))
498 (mgrind result error-log
) (format error-log
" */ ")
500 (format error-log
(intl:gettext
"/* Expected result: */~%"))
501 (mgrind next-result error-log
)
502 (format error-log
";~%~%"))))))))
504 (setq end-run-time
(get-internal-run-time))
505 (setq end-real-time
(get-internal-real-time))
507 (or (streamp *collect-errors
*)
510 ((n-expected-errors (length expected-errors
))
511 (expected-errors-trailer
512 (if (= n-expected-errors
0)
514 (format nil
(intl:gettext
" (not counting ~a expected errors)") n-expected-errors
)))
516 (format nil
(intl:gettext
" using ~,3F seconds (~,3F elapsed).~%")
517 (float (/ (- end-run-time start-run-time
) internal-time-units-per-second
))
518 (float (/ (- end-real-time start-real-time
) internal-time-units-per-second
)))
520 (cond ((null all-differences
)
521 (format t
(intl:gettext
"~a/~a tests passed~a~%~A")
522 (- num-problems n-expected-errors
) (- num-problems n-expected-errors
)
523 expected-errors-trailer
525 (when unexpected-pass
526 (multiple-value-bind (plural was-were
)
527 (if (> (length unexpected-pass
) 1)
530 (format t
(intl:gettext
"~%The following ~A problem~A passed but ~A expected to fail: ~A~%")
531 (length unexpected-pass
) plural was-were
(reverse unexpected-pass
))))
534 `((mlist) ,@(reverse unexpected-pass
))
537 (format t
(intl:gettext
"~%~a/~a tests passed~a~%~A")
538 (- num-problems n-expected-errors
(length all-differences
)) (- num-problems n-expected-errors
) expected-errors-trailer
540 (let ((s (if (> (length all-differences
) 1) "s" "")))
541 (format t
(intl:gettext
"~%The following ~A problem~A failed: ~A~%")
542 (length all-differences
) s
(reverse all-differences
)))
543 (when unexpected-pass
544 (multiple-value-bind (plural was-were
)
545 (if (> (length unexpected-pass
) 1)
548 (format t
(intl:gettext
"~%The following ~A problem~A passed but ~A expected to fail: ~A~%")
549 (length unexpected-pass
) plural was-were
(reverse unexpected-pass
))))
551 `((mlist) ,@(reverse all-differences
))
552 `((mlist) ,@(reverse unexpected-pass
))
555 ;;to keep track of global values during the error:
556 (defun list-variable-bindings (expr &optional str
&aux tem
)
557 (loop for v in
(cdr ($listofvars expr
))
558 when
(member v $values
:test
#'equal
)
559 collecting
(setq tem
`((mequal) ,v
,(meval* v
)))
561 do
(cond (str (format str
",")(mgrind tem str
)))))
564 ;; name = foo or foo.type or dir/foo.type or dir/foo
565 ;; the empty parts are filled successively from defaults in templates in
566 ;; the path. A template may use multiple {a,b,c} constructions to indicate
567 ;; multiple possibilities. eg foo.l{i,}sp or foo.{dem,dm1,dm2}
568 (defmfun $file_search
(name &optional paths
)
569 (if (and (symbolp name
)
570 (char= (char (symbol-name name
) 0) #\$
))
571 (setq name
(subseq (print-invert-case name
) 1)))
572 (if (symbolp name
) (setf name
(string name
)))
573 (if (file-exists-p name
) (return-from $file_search name
))
574 (or paths
(setq paths
($append $file_search_lisp $file_search_maxima
576 (atomchk paths
'$file_search t
)
577 (new-file-search (string name
) (cdr paths
)))
579 ;; Returns T if NAME exists and it does not appear to be a directory.
580 ;; Note that Clisp throws an error from PROBE-FILE if NAME exists
581 ;; and is a directory; hence the use of IGNORE-ERRORS.
583 (defun file-exists-p (name)
584 (let ((foo (ignore-errors (probe-file name
))))
585 (if foo
(not (apparently-a-directory-p foo
)))))
587 (defun apparently-a-directory-p (path)
588 (eq (pathname-name path
) nil
))
590 ;; We keep these here in case we want to optimize the search. To
591 ;; speed things up, we might want to support search lists like
592 ;; "share/**/*.{mac,wxm,mc}" so that we only descend the directory
593 ;; once. Then we would take the list of paths and try to match the
594 ;; one with the given extensions.
596 ;; Currently, the search list is ["share/**/*.mac", "share/**/*.wxm",
597 ;; "share/**/*.mc"]. Thus to find "foo.mc", we end up doing a
598 ;; directory 3 times.
600 (defun new-file-search (name template
)
601 (cond ((file-exists-p name
))
603 (let ((lis (loop for w in
(split-string template
"{}")
604 when
(null (position #\
, w
))
607 collect
(split-string w
","))))
608 (new-file-search1 name
"" lis
)))
611 (loop for v in template
612 when
(setq temp
(new-file-search name v
))
613 do
(return temp
))))))
616 (defun new-file-search1 (name begin lis
)
618 (let ((file (namestring ($filename_merge begin name
))))
619 (if (file-exists-p file
) file nil
)))
621 (new-file-search1 name
623 ($sconcat begin
(car lis
)) (car lis
))
625 (t (loop for v in
(car lis
) with tem
626 when
(setq tem
(new-file-search1 name begin
(cons v
(cdr lis
))))
629 (defvar *debug-new-file-search
* nil
)
631 ;; Search for a file named NAME. If the file exists, return it.
632 ;; Otherwise, TEMPLATE is a list of wildcard paths to be searched for
633 ;; the NAME. Each entry in TEMPLATE should be a Lisp wildcard
635 (defun new-file-search (name template
)
636 (cond ((file-exists-p name
))
638 (let ((filename (pathname name
)))
639 (dolist (path template
)
640 (let ((pathnames (directory (merge-pathnames filename path
))))
641 (when *debug-new-file-search
*
642 (format *debug-io
* "wildpath ~S~%" (merge-pathnames filename path
)))
644 ;; We MUST sort the results in alphabetical order
645 ;; because that's how the old search paths were
647 (setf pathnames
(sort pathnames
#'string
< :key
#'namestring
))
648 (when *debug-new-file-search
*
649 (format *debug-io
* "pathname = ~S~%" pathnames
))
650 ;; If more than one path is returned, print a warning
651 ;; that we're selecting the first file. Print all
652 ;; the matches too so the user knows.
653 (unless (= 1 (length pathnames
))
656 "More than one file matches. Selecting the first file from:~
658 (mapcar #'namestring pathnames
))))
659 (return-from new-file-search
(namestring (first pathnames
))))))))))
661 (defun save-linenumbers (&key
(c-lines t
) d-lines
(from 1) (below $linenum
) a-list
663 &aux input-symbol
($linel
79))
664 (cond ((null a-list
) (setq a-list
(loop for i from from below below collecting i
))))
665 (with-open-file (st file
:direction
:output
)
666 (format st
"/* -*- Mode: MACSYMA; Package: MACSYMA -*- */")
667 (format st
"~%~% /* ~A */ ~%"
669 (multiple-value-list (get-decoded-time)))))
670 (format nil
"~a:~a:~a" (car tem
) (cadr tem
) (caadr tem
))))
671 (loop for i in a-list
672 when
(and c-lines
(boundp (setq input-symbol
(intern (format nil
"$~A~A" '#:c i
)))))
674 (format st
"~% C~3A; " i
)
675 (mgrind (symbol-value input-symbol
) st
)
678 (boundp (setq input-symbol
(intern (format nil
"$~A~A" '#:d i
)))))
680 (format st
"~% D~3A: " i
)
681 (mgrind (symbol-value input-symbol
) st
)
685 (defmfun $printfile
(file)
686 (setq file
($file_search1 file
'((mlist) $file_search_usage
)))
687 (with-open-file (st file
)
690 while
(setq tem
(read-char st nil
'eof
))
692 (if (eq tem
'eof
) (return t
))
696 (defun disable-some-lisp-warnings ()
697 ;; Suppress warnings about redefining functions;
698 ;; it appears that only Clisp and SBCL emit these warnings
699 ;; (ECL, GCL, CMUCL, and Clozure CL apparently do not).
700 ;; Such warnings are generated by the autoload mechanism.
701 ;; I guess it is plausible that we could also avoid the warnings by
702 ;; reworking autoload to not trigger them. I don't have enough
703 ;; motivation to attempt that right now.
705 (setq sb-ext
:*muffled-warnings
* '(or sb-kernel
:redefinition-with-defun
sb-kernel:uninteresting-redefinition
))
707 (declaim (sb-ext:muffle-conditions sb-ext
:compiler-note
))
709 (setq custom
:*suppress-check-redefinition
* t
)
711 ;; Suppress compiler output messages.
712 ;; These include the "0 errors, 0 warnings" message output from Clisp,
713 ;; and maybe other messages from other Lisps.
714 (setq *compile-verbose
* nil
))
716 (defun enable-some-lisp-warnings ()
717 ;; SB-KERNEL:UNINTERESTING-REDEFINITION appears to be the default value.
719 (setq sb-ext
:*muffled-warnings
* 'sb-kernel
:uninteresting-redefinition
)
721 (declaim (sb-ext:unmuffle-conditions sb-ext
:compiler-note
))
723 (setq custom
:*suppress-check-redefinition
* nil
)
724 (setq *compile-verbose
* t
))
726 (defun simple-remove-dollarsign (x)
727 "Like stripdollar, but less heavy. Intended for use with the
728 testsuite implementation."
730 (subseq (maxima-string x
) 1)
733 (defun intersect-tests (tests)
734 ;; If TESTS is non-NIL, we assume it's a Maxima list of (maxima)
735 ;; strings naming the tests we want to run. They must match the
736 ;; file names in $testsuite_files. We ignore any items that aren't
737 ;; in $testsuite_files.
738 (mapcar #'simple-remove-dollarsign
741 ;; Using INTERSECTION would be convenient, but
742 ;; INTERSECTION can return the result in any
743 ;; order, and we'd prefer that the order of the
744 ;; tests be preserved. CMUCL and CCL returns the
745 ;; intersection in reverse order. Clisp produces
746 ;; the original order. Fortunately, this doesn't
747 ;; have to be very fast, so we do it very naively.
748 (dolist (test (mapcar #'simple-remove-dollarsign
(cdr tests
)))
749 (let ((matching-test (find test
(cdr $testsuite_files
)
751 (maxima-string (if (listp x
)
756 (push matching-test results
))))
759 (cdr $testsuite_files
)))))
761 (defun print-testsuite-summary (errs unexpected-pass error-count total-count
)
763 ((problem-summary (x)
764 ;; We want to print all the elements in the list.
765 (let ((*print-length
* nil
)
766 (s (if (> (length (rest x
)) 1) "s" "")))
769 " ~a problem~a:~% ~a~%")
772 (sort (rest x
) #'<)))))
776 "~%~%No unexpected errors found out of ~:d tests.~%")
778 (format t
(intl:gettext
"~%Error summary:~%")))
780 (format t
(intl:gettext
"Error(s) found:~%"))
781 (mapcar #'problem-summary
(reverse errs
)))
782 (when unexpected-pass
783 (format t
(intl:gettext
"Tests that were expected to fail but passed:~%"))
784 (mapcar #'problem-summary
(reverse unexpected-pass
)))
788 "~&~:d test~p failed out of ~:d total tests.~%")
793 (defun validate-given-tests (tests share-tests-p
)
794 ;; Check the test names and print out some warnings if it
795 ;; doesn't exist, or if it does and is part of the share test
796 ;; suite, but share_tests was not set.
797 (dolist (test (mapcar #'simple-remove-dollarsign
801 (cond ((and (not share-tests-p
)
802 (find test
(cdr $share_testsuite_files
)
804 (maxima-string (if (listp x
)
808 (mwarning test
"is a share test, but share_tests was not set"))
809 ((not (find test
(cdr $testsuite_files
)
811 (maxima-string (if (listp x
)
815 (mwarning "Unknown test: " test
)))))
817 (defmfun $run_testsuite
(&key tests display_all display_known_bugs share_tests time debug
)
818 "Run the testsuite. Options are
819 tests List of tests to run
820 display_all Display output from each test entry
821 display_known_bugs Include tests that are known to fail.
822 time Display time to run each test entry
823 share_tests Whether to include the share testsuite or not
824 debug Set to enable some debugging prints.
826 (enable-some-lisp-warnings)
830 (format t
"Testsuite run for ~a ~a:~%"
831 (lisp-implementation-type) (lisp-implementation-version))
832 ;; Allow only T and NIL for display_known_bugs and display_all
833 (unless (member display_known_bugs
'(t nil
))
834 (merror (intl:gettext
"run_testsuite: display_known_bugs must be true or false; found: ~M") display_known_bugs
))
835 (unless (member display_all
'(t nil
))
836 (merror (intl:gettext
"run_testsuite: display_all must be true or false; found: ~M") display_all
))
837 (unless (member time
'(t nil $all
))
838 (merror (intl:gettext
"run_testsuite: time must be true, false, or all; found: ~M") time
))
840 (unless (member share_tests
'(t nil $only
))
841 (merror (intl:gettext
"run_testsuite: share_tests must be true, false or only: found ~M") share_tests
))
843 (setq *collect-errors
* nil
)
845 (multiple-value-bind (desired-tests desired-search-path
)
849 (values $testsuite_files $file_search_tests
))
851 ;; Append the share files and concatenate the search paths
852 ;; for tests and maxima so we can find both sets of tests.
853 (values ($append $testsuite_files $share_testsuite_files
)
854 ;; Is there a better way to do this?
857 (rest $file_search_tests
)
858 (rest $file_search_maxima
))))
860 ;; Only the share test files
861 (values $share_testsuite_files $file_search_maxima
)))
862 (let* (($testsuite_files desired-tests
)
863 ($file_search_tests desired-search-path
)
865 (tests-to-run (intersect-tests (cond ((consp tests
) tests
)
866 (tests (list '(mlist) tests
)))))
874 (validate-given-tests tests share_tests
)
877 (let (($stringdisp t
))
878 (mformat t
"$testsuite_files = ~M~%" $testsuite_files
)
879 (mformat t
"$file_search_tests = ~M~%" $file_search_tests
)))
881 (let (($stringdisp t
))
882 (mformat t
"tests-to-run = ~M~%" tests-to-run
)))
885 (mwarning "No tests to run")
886 (return-from $run_testsuite
'$done
))
890 (loop with errs
= 'nil
891 with unexpected-pass
= nil
892 for testentry in tests-to-run
893 do
(if (atom testentry
)
895 (setf test-file testentry
)
896 (setf expected-failures nil
))
898 (setf test-file
(second testentry
))
899 (setf expected-failures
900 ;; Support the expected failures list in
903 ;; ((mlist) "test" 1 2 3)
904 ;; ((mlist) "test" ((mlist) 1 2 3))
906 ;; The first is the old style whereas the
907 ;; second is the new style. We support
908 ;; the old style for backward
910 (if (consp (caddr testentry
))
913 (setf test-file-path
($file_search test-file $file_search_tests
))
915 (intl:gettext
"Running tests in ~a: ")
916 (if (symbolp test-file
)
917 (subseq (print-invert-case test-file
) 1)
920 (format t
(intl:gettext
"(~A) ") test-file-path
))
924 (multiple-value-setq (filename diff upass test-count
)
925 (test-batch test-file-path
926 expected-failures
:show-expected display_known_bugs
927 :show-all display_all
:showtime time
))
928 (incf total-count test-count
)
929 (when (or (rest diff
) (rest upass
))
930 (incf error-count
(length (rest diff
)))
932 (push (list* filename
(rest diff
))
935 (push (list* filename
(rest upass
))
938 (setq error-break-file
(format nil
"~a" test-file
))
939 (push (list error-break-file
"error break")
942 (intl:gettext
"~%Caused an error break: ~a")
944 ;; If the test failed because we
945 ;; couldn't find the file, make a note of
947 (unless test-file-path
948 (format t
(intl:gettext
": test file not found.")))
951 (print-testsuite-summary errs unexpected-pass error-count total-count
))))
952 (time (testsuite))))))
953 (disable-some-lisp-warnings)