test-encodings.script 4.03 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
(defmacro with-encoding-test ((encoding &key (op 'asdf:load-source-op) (path "lambda")) defsystem &body body)
25
26
27
  (let ((sys (second defsystem)))
    `(progn
       (format t "~&Test ~A: should be ~A~%" ',sys ',encoding)
28
       (setf *lambda-string* nil)
29
       ,defsystem
30
31
32
33
34
35
       (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
           `((asdf:operate ',op ',(second defsystem))))
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
44
45
    (defsystem :test-encoding-explicit-u8
      :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
56
      (defsystem :test-encoding-explicit-default
        :components ((:file "lambda" :encoding :default))))
57
    (with-encoding-test (:default)
58
59
60
      (defsystem :test-encoding-implicit-default
        :components ((:file "lambda")))))

Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
61
62
63
64
65
66
67
68
69
70
71
72
73
74
  ;; BEWARE: For testing purposes, we assume ASDF-ENCODINGS is under the same root as ASDF.
  (pushnew (asdf::subpathname *asdf-directory* "../asdf-encodings/") asdf:*central-registry*)
  (unless (find-system :asdf-encodings nil)
    (leave-test "ASDF-ENCODINGS is not installed next to ASDF. Skipping the rest the test." 0))

  (asdf:load-system :asdf-encodings)
  #-lispworks
  (with-encoding-test (:latin-2)
    (defsystem :test-encoding-implicit-autodetect
      :components ((:file "lambda"))))
  #+sbcl
  (with-encoding-test (:koi8-r)
    (defsystem :test-encoding-explicit-koi8-r
      :components ((:file "lambda" :encoding :koi8-r))))
75

76
  (with-encoding-test (:utf-8)
77
78
79
    (defsystem :test-file-encoding-u8
      :encoding :latin-1
      :components ((:file "lambda" :encoding :utf-8))))
80
  (with-encoding-test (:latin-1)
81
82
83
    (defsystem :test-file-encoding-l1
      :encoding :utf-8
      :components ((:file "lambda" :encoding :latin-1))))
84
  (with-encoding-test (:utf-8 :op asdf:load-source-op)
85
86
87
    (defsystem :test-system-encoding-u8
      :encoding :utf-8
      :components ((:file "lambda"))))
88
  (with-encoding-test (:utf-8 :op asdf:load-op)
89
90
91
    (defsystem :test-system-encoding-u8-load-op
      :encoding :utf-8
      :components ((:file "lambda"))))
92
  (with-encoding-test (:latin-1)
93
94
95
    (defsystem :test-system-encoding-l1
      :encoding :latin-1
      :components ((:file "lambda"))))
96
  #-ecl-bytecmp
97
  (with-encoding-test (:latin-1 :op asdf:load-op)
98
99
100
    (defsystem :test-system-encoding-l1-load-op
      :encoding :latin-1
      :components ((:file "lambda"))))
101
  (with-encoding-test (:utf-8 :path ("foo" "lambda"))
102
103
104
105
106
    (defsystem :test-module-encoding-u8
      :encoding :latin-1
      :components
      ((:module "foo" :pathname "" :encoding :utf-8
        :components ((:file "lambda"))))))
107
  (with-encoding-test (:latin-1 :path ("foo" "lambda"))
108
109
110
111
112
113
    (defsystem :test-module-encoding-l1
      :encoding :utf-8
      :components
      ((:module "foo" :pathname "" :encoding :latin-1
        :components ((:file "lambda"))))))
  t)