test-encodings.script 4.46 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
;;; -*- Lisp -*-
(load "script-support.lisp")
(load-asdf)

(defparameter *lambda-string* nil)

(defun string-char-codes (s)
  (loop :for c :across s :collect (char-code c)))

(defun expected-char-codes (x)
  #-asdf-unicode '(#xCE #xBB)
  #+asdf-unicode
  (ecase x
    (:utf-8 '(955))
    ((:latin1 :latin-1) '(206 187))
    ((:latin2 :latin-2) '(206 357))
    ((:latin3 :latin-3) '(206 287))
    (:koi8-r '(1085 9577))
    (:default (expected-char-codes
               #+clozure ccl:*default-external-format*
               #+sbcl sb-impl::*default-external-format*
               #-(or clozure sbcl) (error "can't determine default external-format")))))

24 25
(defmacro with-encoding-test ((encoding &key (op 'asdf:load-source-op) (path "lambda")) def-test-system &body body)
  (let ((sys (second def-test-system)))
26 27
    `(progn
       (format t "~&Test ~A: should be ~A~%" ',sys ',encoding)
28
       (setf *lambda-string* nil)
29
       ,def-test-system
30 31 32 33 34
       (let ((c (asdf:find-component ',sys ',path)))
         (assert-equal (asdf:component-encoding c) ',encoding)
         (loop :for o :in (asdf:output-files (asdf::make-operation 'asdf:compile-op) c)
               :do (asdf::delete-file-if-exists o)))
       ,@(when op
35
           `((asdf:operate ',op ',(second def-test-system))))
36
       ,@body
37 38
       (eval `(assert-equal (string-char-codes ,*lambda-string*)
                            (expected-char-codes ',',encoding))))))
39

40
(with-test ()
41

42
  (with-encoding-test (:utf-8)
43
    (def-test-system :test-encoding-explicit-u8
44 45
      :components ((:file "lambda" :encoding :utf-8))))

46 47 48
  #-asdf-unicode
  (leave-test "No Unicode support to test on this lisp implementation" 0)

49 50
  ;; NB: recent clozure can autodetect without asdf-encodings with :default (!)

Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
51
  #+sbcl
52 53
  (progn
    #+sbcl (setf sb-impl::*default-external-format* :latin-3)
54
    (with-encoding-test (:default)
55
      (def-test-system :test-encoding-explicit-default
56
        :components ((:file "lambda" :encoding :default))))
57
    (with-encoding-test (:default)
58
      (def-test-system :test-encoding-implicit-default
59 60
        :components ((:file "lambda")))))

61 62 63 64 65
  ;; Try to load asdf-encodings
  (setf *central-registry*
        (list *asdf-directory* ;; be sure that *OUR* asdf is first of any possible ASDF
              ;; try finding asdf-encodings it right next to asdf.
              (subpathname *asdf-directory* "../asdf-encodings/")))
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
66
  (unless (find-system :asdf-encodings nil)
67 68 69 70 71 72 73
    ;; try harder by enabling the user's source-registry
    (initialize-source-registry ""))
  (unless (find-system :asdf-encodings nil)
    (leave-test "Couldn't find ASDF-ENCODINGS. Skipping the rest the test." 0))
  ;; Disable any user source registry.
  (initialize-source-registry `(:source-registry :ignore-inherited-configuration))

Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
74 75 76 77

  (asdf:load-system :asdf-encodings)
  #-lispworks
  (with-encoding-test (:latin-2)
78
    (def-test-system :test-encoding-implicit-autodetect
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
79 80 81
      :components ((:file "lambda"))))
  #+sbcl
  (with-encoding-test (:koi8-r)
82
    (def-test-system :test-encoding-explicit-koi8-r
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
83
      :components ((:file "lambda" :encoding :koi8-r))))
84

85
  (with-encoding-test (:utf-8)
86
    (def-test-system :test-file-encoding-u8
87 88
      :encoding :latin-1
      :components ((:file "lambda" :encoding :utf-8))))
89
  (with-encoding-test (:latin-1)
90
    (def-test-system :test-file-encoding-l1
91 92
      :encoding :utf-8
      :components ((:file "lambda" :encoding :latin-1))))
93
  (with-encoding-test (:utf-8 :op asdf:load-source-op)
94
    (def-test-system :test-system-encoding-u8
95 96
      :encoding :utf-8
      :components ((:file "lambda"))))
97
  (with-encoding-test (:utf-8 :op asdf:load-op)
98
    (def-test-system :test-system-encoding-u8-load-op
99 100
      :encoding :utf-8
      :components ((:file "lambda"))))
101
  (with-encoding-test (:latin-1)
102
    (def-test-system :test-system-encoding-l1
103 104
      :encoding :latin-1
      :components ((:file "lambda"))))
105
  #-ecl-bytecmp
106
  (with-encoding-test (:latin-1 :op asdf:load-op)
107
    (def-test-system :test-system-encoding-l1-load-op
108 109
      :encoding :latin-1
      :components ((:file "lambda"))))
110
  (with-encoding-test (:utf-8 :path ("foo" "lambda"))
111
    (def-test-system :test-module-encoding-u8
112 113 114 115
      :encoding :latin-1
      :components
      ((:module "foo" :pathname "" :encoding :utf-8
        :components ((:file "lambda"))))))
116
  (with-encoding-test (:latin-1 :path ("foo" "lambda"))
117
    (def-test-system :test-module-encoding-l1
118 119 120 121 122
      :encoding :utf-8
      :components
      ((:module "foo" :pathname "" :encoding :latin-1
        :components ((:file "lambda"))))))
  t)