(defun get-external-format-or-lose (external-format)
(or (get-external-format external-format)
- (error "Undefined external-format ~A" external-format)))
+ (error "Undefined external-format: ~S" external-format)))
(defun external-format-keyword (external-format)
(typecase external-format
;;; number of bytes per element.
(defun pick-output-routine (type buffering &optional external-format)
(when (subtypep type 'character)
- (let ((entry (get-external-format external-format)))
- (when entry
- (return-from pick-output-routine
- (values (ecase buffering
- (:none (ef-write-char-none-buffered-fun entry))
- (:line (ef-write-char-line-buffered-fun entry))
- (:full (ef-write-char-full-buffered-fun entry)))
- 'character
- 1
- (ef-write-n-bytes-fun entry)
- (canonize-external-format external-format entry))))))
+ (let ((entry (get-external-format-or-lose external-format)))
+ (return-from pick-output-routine
+ (values (ecase buffering
+ (:none (ef-write-char-none-buffered-fun entry))
+ (:line (ef-write-char-line-buffered-fun entry))
+ (:full (ef-write-char-full-buffered-fun entry)))
+ 'character
+ 1
+ (ef-write-n-bytes-fun entry)
+ (canonize-external-format external-format entry)))))
(dolist (entry *output-routines*)
(when (and (subtypep type (first entry))
(eq buffering (second entry))
;;; bytes per element (and for character types string input routine).
(defun pick-input-routine (type &optional external-format)
(when (subtypep type 'character)
- (let ((entry (get-external-format external-format)))
- (when entry
- (return-from pick-input-routine
- (values (ef-read-char-fun entry)
- 'character
- 1
- (ef-read-n-chars-fun entry)
- (canonize-external-format external-format entry))))))
+ (let ((entry (get-external-format-or-lose external-format)))
+ (return-from pick-input-routine
+ (values (ef-read-char-fun entry)
+ 'character
+ 1
+ (ef-read-n-chars-fun entry)
+ (canonize-external-format external-format entry)))))
(dolist (entry *input-routines*)
(when (and (subtypep type (first entry))
(or (not (fourth entry))
(write-string string s))
(with-open-file (s *test-path* :external-format :utf-32be)
(assert (string= " ???? " (read-line s))))))
+
+(with-test (:name :invalid-external-format)
+ (labels ((test-error (e)
+ (assert (typep e 'error))
+ (unless (equal "Undefined external-format: :BAD-FORMAT"
+ (princ-to-string e))
+ (error "Bad error:~% ~A" e)))
+ (test (direction)
+ (test-error
+ (handler-case
+ (open "/dev/null" :direction direction :external-format :bad-format
+ :if-exists :overwrite)
+ (error (e) e)))))
+ (test :input)
+ (test :output)
+ (test :io)
+ (test-error
+ (handler-case
+ (run-program "sh" '() :input :stream :external-format :bad-format)
+ (error (e) e)))
+ (test-error
+ (handler-case
+ (string-to-octets "foobar" :external-format :bad-format)
+ (error (e) e)))
+ (test-error
+ (let ((octets (string-to-octets "foobar" :external-format :latin1)))
+ (handler-case
+ (octets-to-string octets :external-format :bad-format)
+ (error (e) e))))))
\f
;;;; success