+(delete-file *test-path*)
+
+;;; We used to call STREAM-EXTERNAL-FORMAT on the stream in the error
+;;; when printing a coding error, but that didn't work if the stream
+;;; was closed by the time the error was printed. See sbcl-devel
+;;; "Subject: Printing coding errors for closed streams" by Zach Beane
+;;; on 2008-10-16 for more info.
+(with-test (:name (:character-coding-error-stream-external-format))
+ (flet ((first-file-character ()
+ (with-open-file (stream *test-path* :external-format :utf-8)
+ (read-char stream))))
+ (with-open-file (stream *test-path*
+ :direction :output
+ :if-exists :supersede
+ :element-type '(unsigned-byte 8))
+ (write-byte 192 stream))
+ (princ-to-string (nth-value 1 (ignore-errors (first-file-character))))))
+(delete-file *test-path*)
+
+;;; External format support in SB-ALIEN
+
+(with-test (:name (:sb-alien :vanilla))
+ (define-alien-routine strdup c-string (str c-string))
+ (assert (equal "foo" (strdup "foo"))))
+
+(with-test (:name (:sb-alien :utf-8 :utf-8))
+ (define-alien-routine strdup (c-string :external-format :utf-8)
+ (str (c-string :external-format :utf-8)))
+ (assert (equal "foo" (strdup "foo"))))
+
+(with-test (:name (:sb-alien :latin-1 :utf-8))
+ (define-alien-routine strdup (c-string :external-format :latin-1)
+ (str (c-string :external-format :utf-8)))
+ (assert (= (length (strdup (string (code-char 246))))
+ 2)))
+
+(with-test (:name (:sb-alien :utf-8 :latin-1))
+ (define-alien-routine strdup (c-string :external-format :utf-8)
+ (str (c-string :external-format :latin-1)))
+ (assert (equal (string (code-char 228))
+ (strdup (concatenate 'string
+ (list (code-char 195))
+ (list (code-char 164)))))))
+
+(with-test (:name (:sb-alien :ebcdic :ebcdic))
+ (define-alien-routine strdup (c-string :external-format :ebcdic-us)
+ (str (c-string :external-format :ebcdic-us)))
+ (assert (equal "foo" (strdup "foo"))))
+
+(with-test (:name (:sb-alien :latin-1 :ebcdic))
+ (define-alien-routine strdup (c-string :external-format :latin-1)
+ (str (c-string :external-format :ebcdic-us)))
+ (assert (not (equal "foo" (strdup "foo")))))
+
+(with-test (:name (:sb-alien :simple-base-string))
+ (define-alien-routine strdup (c-string :external-format :ebcdic-us
+ :element-type base-char)
+ (str (c-string :external-format :ebcdic-us)))
+ (assert (typep (strdup "foo") 'simple-base-string)))