1 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; While most of SBCL is derived from the CMU CL system, the test
5 ;;;; files (like this one) were written from scratch after the fork
8 ;;;; This software is in the public domain and is provided with
9 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
10 ;;;; more information.
14 (defvar *format-mode
*)
16 (defun format* (format-control &rest arguments
)
19 (eval `(format nil
,format-control
,@arguments
)))
21 (let ((names (sb-int:make-gensym-list
(length arguments
))))
22 (funcall (checked-compile
23 `(lambda ,names
(format nil
,format-control
,@names
)))
26 (defmacro with-compiled-and-interpreted-format
(() &body body
)
27 `(flet ((run-body (mode)
28 (let ((*format-mode
* mode
))
32 (error "~@<Error in ~A FORMAT: ~A~@:>"
37 (defun format-error-format-control-string-p (condition)
38 (and (typep condition
'sb-format
:format-error
)
39 (sb-format::format-error-control-string condition
)))
41 (deftype format-error-with-control-string
()
42 `(and sb-format
:format-error
43 (satisfies format-error-format-control-string-p
)))
45 (with-test (:name
(:[-directive
:non-integer-argument
))
46 (with-compiled-and-interpreted-format ()
47 (assert-error (format* "~[~]" 1d0
) format-error-with-control-string
)))
49 (with-test (:name
(:P-directive
:no-previous-argument
))
50 (with-compiled-and-interpreted-format ()
51 (assert-error (format* "~@<~:P~@:>" '()) format-error-with-control-string
)))
53 (with-test (:name
(:*-directive
:out-of-bounds
))
54 (with-compiled-and-interpreted-format ()
55 (assert-error (format* "~2@*" '()) format-error-with-control-string
)
56 (assert-error (format* "~1:*" '()) format-error-with-control-string
)))