* window.el (special-display-popup-frame): Doc fix.
[emacs.git] / test / automated / bytecomp-tests.el
blobb7ec79fd51cb468130fe017fd1d0e1d0f2e36c58
1 ;;; bytecomp-testsuite.el
3 ;; Copyright (C) 2008-2012 Free Software Foundation, Inc.
5 ;; Author: Shigeru Fukaya <shigeru.fukaya@gmail.com>
6 ;; Created: November 2008
7 ;; Keywords: internal
8 ;; Human-Keywords: internal
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;; Commentary:
27 (require 'ert)
29 ;;; Code:
30 (defconst byte-opt-testsuite-arith-data
32 ;; some functional tests
33 (let ((a most-positive-fixnum) (b 1) (c 1.0)) (+ a b c))
34 (let ((a most-positive-fixnum) (b -2) (c 1.0)) (- a b c))
35 (let ((a most-positive-fixnum) (b 2) (c 1.0)) (* a b c))
36 (let ((a 3) (b 2) (c 1.0)) (/ a b c))
37 (let ((a (+ 1 (expt 2 -64))) (b (expt 2 -65))) (+ a -1 b))
38 (let ((a (+ 1 (expt 2 -64))) (b (expt 2 -65))) (- a 1 (- b)))
39 ;; This fails. Should it be a bug?
40 ;; (let ((a (expt 2 -1074)) (b 0.125)) (* a 8 b))
41 (let ((a 1.0)) (* a 0))
42 (let ((a 1.0)) (* a 2.0 0))
43 (let ((a 1.0)) (/ 0 a))
44 (let ((a 1.0)) (/ 3 a 2))
45 (let ((a most-positive-fixnum) (b 2.0)) (* a 2 b))
46 (let ((a 3) (b 2)) (/ a b 1.0))
47 (/ 3 -1)
48 (+ 4 3 2 1)
49 (+ 4 3 2.0 1)
50 (- 4 3 2 1) ; not new, for reference
51 (- 4 3 2.0 1) ; not new, for reference
52 (* 4 3 2 1)
53 (* 4 3 2.0 1)
54 (/ 4 3 2 1)
55 (/ 4 3 2.0 1)
56 (let ((a 3) (b 2)) (+ a b 1))
57 (let ((a 3) (b 2)) (+ a b -1))
58 (let ((a 3) (b 2)) (- a b 1))
59 (let ((a 3) (b 2)) (- a b -1))
60 (let ((a 3) (b 2)) (+ a b a 1))
61 (let ((a 3) (b 2)) (+ a b a -1))
62 (let ((a 3) (b 2)) (- a b a 1))
63 (let ((a 3) (b 2)) (- a b a -1))
64 (let ((a 3) (b 2)) (* a b -1))
65 (let ((a 3) (b 2)) (* a -1))
66 (let ((a 3) (b 2)) (/ a b 1))
67 (let ((a 3) (b 2)) (/ (+ a b) 1))
69 ;; coverage test
70 (let ((a 3) (b 2) (c 1.0)) (+))
71 (let ((a 3) (b 2) (c 1.0)) (+ 2))
72 (let ((a 3) (b 2) (c 1.0)) (+ 2 0))
73 (let ((a 3) (b 2) (c 1.0)) (+ 2 0.0))
74 (let ((a 3) (b 2) (c 1.0)) (+ 2.0))
75 (let ((a 3) (b 2) (c 1.0)) (+ 2.0 0))
76 (let ((a 3) (b 2) (c 1.0)) (+ 2.0 0.0))
77 (let ((a 3) (b 2) (c 1.0)) (+ 0 2))
78 (let ((a 3) (b 2) (c 1.0)) (+ 0 2.0))
79 (let ((a 3) (b 2) (c 1.0)) (+ 0.0 2))
80 (let ((a 3) (b 2) (c 1.0)) (+ 0.0 2.0))
81 (let ((a 3) (b 2) (c 1.0)) (+ a))
82 (let ((a 3) (b 2) (c 1.0)) (+ a 0))
83 (let ((a 3) (b 2) (c 1.0)) (+ a 0.0))
84 (let ((a 3) (b 2) (c 1.0)) (+ 0 a))
85 (let ((a 3) (b 2) (c 1.0)) (+ 0.0 a))
86 (let ((a 3) (b 2) (c 1.0)) (+ c 0))
87 (let ((a 3) (b 2) (c 1.0)) (+ c 0.0))
88 (let ((a 3) (b 2) (c 1.0)) (+ 0 c))
89 (let ((a 3) (b 2) (c 1.0)) (+ 0.0 c))
90 (let ((a 3) (b 2) (c 1.0)) (+ a b 0 c 0))
91 (let ((a 3) (b 2) (c 1.0)) (+ 0 a))
92 (let ((a 3) (b 2) (c 1.0)) (+ 0 a b))
93 (let ((a 3) (b 2) (c 1.0)) (+ 0 a b c))
94 (let ((a 3) (b 2) (c 1.0)) (+ 1 2 3))
95 (let ((a 3) (b 2) (c 1.0)) (+ 3.0 2.0 1))
96 (let ((a 3) (b 2) (c 1.0)) (+ 3.0 2.0 1 4))
97 (let ((a 3) (b 2) (c 1.0)) (+ a 1))
98 (let ((a 3) (b 2) (c 1.0)) (+ a -1))
99 (let ((a 3) (b 2) (c 1.0)) (+ 1 a))
100 (let ((a 3) (b 2) (c 1.0)) (+ -1 a))
101 (let ((a 3) (b 2) (c 1.0)) (+ c 1))
102 (let ((a 3) (b 2) (c 1.0)) (+ c -1))
103 (let ((a 3) (b 2) (c 1.0)) (+ 1 c))
104 (let ((a 3) (b 2) (c 1.0)) (+ -1 c))
105 (let ((a 3) (b 2) (c 1.0)) (+ a b 0))
106 (let ((a 3) (b 2) (c 1.0)) (+ a b 1))
107 (let ((a 3) (b 2) (c 1.0)) (+ a b -1))
108 (let ((a 3) (b 2) (c 1.0)) (+ a b 2))
109 (let ((a 3) (b 2) (c 1.0)) (+ 1 a b c))
110 (let ((a 3) (b 2) (c 1.0)) (+ a b c 0))
111 (let ((a 3) (b 2) (c 1.0)) (+ a b c 1))
112 (let ((a 3) (b 2) (c 1.0)) (+ a b c -1))
114 (let ((a 3) (b 2) (c 1.0)) (-))
115 (let ((a 3) (b 2) (c 1.0)) (- 2))
116 (let ((a 3) (b 2) (c 1.0)) (- 2 0))
117 (let ((a 3) (b 2) (c 1.0)) (- 2 0.0))
118 (let ((a 3) (b 2) (c 1.0)) (- 2.0))
119 (let ((a 3) (b 2) (c 1.0)) (- 2.0 0))
120 (let ((a 3) (b 2) (c 1.0)) (- 2.0 0.0))
121 (let ((a 3) (b 2) (c 1.0)) (- 0 2))
122 (let ((a 3) (b 2) (c 1.0)) (- 0 2.0))
123 (let ((a 3) (b 2) (c 1.0)) (- 0.0 2))
124 (let ((a 3) (b 2) (c 1.0)) (- 0.0 2.0))
125 (let ((a 3) (b 2) (c 1.0)) (- a))
126 (let ((a 3) (b 2) (c 1.0)) (- a 0))
127 (let ((a 3) (b 2) (c 1.0)) (- a 0.0))
128 (let ((a 3) (b 2) (c 1.0)) (- 0 a))
129 (let ((a 3) (b 2) (c 1.0)) (- 0.0 a))
130 (let ((a 3) (b 2) (c 1.0)) (- c 0))
131 (let ((a 3) (b 2) (c 1.0)) (- c 0.0))
132 (let ((a 3) (b 2) (c 1.0)) (- 0 c))
133 (let ((a 3) (b 2) (c 1.0)) (- 0.0 c))
134 (let ((a 3) (b 2) (c 1.0)) (- a b 0 c 0))
135 (let ((a 3) (b 2) (c 1.0)) (- 0 a))
136 (let ((a 3) (b 2) (c 1.0)) (- 0 a b))
137 (let ((a 3) (b 2) (c 1.0)) (- 0 a b c))
138 (let ((a 3) (b 2) (c 1.0)) (- 1 2 3))
139 (let ((a 3) (b 2) (c 1.0)) (- 3.0 2.0 1))
140 (let ((a 3) (b 2) (c 1.0)) (- 3.0 2.0 1 4))
141 (let ((a 3) (b 2) (c 1.0)) (- a 1))
142 (let ((a 3) (b 2) (c 1.0)) (- a -1))
143 (let ((a 3) (b 2) (c 1.0)) (- 1 a))
144 (let ((a 3) (b 2) (c 1.0)) (- -1 a))
145 (let ((a 3) (b 2) (c 1.0)) (- c 1))
146 (let ((a 3) (b 2) (c 1.0)) (- c -1))
147 (let ((a 3) (b 2) (c 1.0)) (- 1 c))
148 (let ((a 3) (b 2) (c 1.0)) (- -1 c))
149 (let ((a 3) (b 2) (c 1.0)) (- a b 0))
150 (let ((a 3) (b 2) (c 1.0)) (- a b 1))
151 (let ((a 3) (b 2) (c 1.0)) (- a b -1))
152 (let ((a 3) (b 2) (c 1.0)) (- a b 2))
153 (let ((a 3) (b 2) (c 1.0)) (- 1 a b c))
154 (let ((a 3) (b 2) (c 1.0)) (- a b c 0))
155 (let ((a 3) (b 2) (c 1.0)) (- a b c 1))
156 (let ((a 3) (b 2) (c 1.0)) (- a b c -1))
158 (let ((a 3) (b 2) (c 1.0)) (*))
159 (let ((a 3) (b 2) (c 1.0)) (* 2))
160 (let ((a 3) (b 2) (c 1.0)) (* 2 0))
161 (let ((a 3) (b 2) (c 1.0)) (* 2 0.0))
162 (let ((a 3) (b 2) (c 1.0)) (* 2.0))
163 (let ((a 3) (b 2) (c 1.0)) (* 2.0 0))
164 (let ((a 3) (b 2) (c 1.0)) (* 2.0 0.0))
165 (let ((a 3) (b 2) (c 1.0)) (* 0 2))
166 (let ((a 3) (b 2) (c 1.0)) (* 0 2.0))
167 (let ((a 3) (b 2) (c 1.0)) (* 0.0 2))
168 (let ((a 3) (b 2) (c 1.0)) (* 0.0 2.0))
169 (let ((a 3) (b 2) (c 1.0)) (* a))
170 (let ((a 3) (b 2) (c 1.0)) (* a 0))
171 (let ((a 3) (b 2) (c 1.0)) (* a 0.0))
172 (let ((a 3) (b 2) (c 1.0)) (* 0 a))
173 (let ((a 3) (b 2) (c 1.0)) (* 0.0 a))
174 (let ((a 3) (b 2) (c 1.0)) (* c 0))
175 (let ((a 3) (b 2) (c 1.0)) (* c 0.0))
176 (let ((a 3) (b 2) (c 1.0)) (* 0 c))
177 (let ((a 3) (b 2) (c 1.0)) (* 0.0 c))
178 (let ((a 3) (b 2) (c 1.0)) (* a b 0 c 0))
179 (let ((a 3) (b 2) (c 1.0)) (* 0 a))
180 (let ((a 3) (b 2) (c 1.0)) (* 0 a b))
181 (let ((a 3) (b 2) (c 1.0)) (* 0 a b c))
182 (let ((a 3) (b 2) (c 1.0)) (* 1 2 3))
183 (let ((a 3) (b 2) (c 1.0)) (* 3.0 2.0 1))
184 (let ((a 3) (b 2) (c 1.0)) (* 3.0 2.0 1 4))
185 (let ((a 3) (b 2) (c 1.0)) (* a 1))
186 (let ((a 3) (b 2) (c 1.0)) (* a -1))
187 (let ((a 3) (b 2) (c 1.0)) (* 1 a))
188 (let ((a 3) (b 2) (c 1.0)) (* -1 a))
189 (let ((a 3) (b 2) (c 1.0)) (* c 1))
190 (let ((a 3) (b 2) (c 1.0)) (* c -1))
191 (let ((a 3) (b 2) (c 1.0)) (* 1 c))
192 (let ((a 3) (b 2) (c 1.0)) (* -1 c))
193 (let ((a 3) (b 2) (c 1.0)) (* a b 0))
194 (let ((a 3) (b 2) (c 1.0)) (* a b 1))
195 (let ((a 3) (b 2) (c 1.0)) (* a b -1))
196 (let ((a 3) (b 2) (c 1.0)) (* a b 2))
197 (let ((a 3) (b 2) (c 1.0)) (* 1 a b c))
198 (let ((a 3) (b 2) (c 1.0)) (* a b c 0))
199 (let ((a 3) (b 2) (c 1.0)) (* a b c 1))
200 (let ((a 3) (b 2) (c 1.0)) (* a b c -1))
202 (let ((a 3) (b 2) (c 1.0)) (/))
203 (let ((a 3) (b 2) (c 1.0)) (/ 2))
204 (let ((a 3) (b 2) (c 1.0)) (/ 2 0))
205 (let ((a 3) (b 2) (c 1.0)) (/ 2 0.0))
206 (let ((a 3) (b 2) (c 1.0)) (/ 2.0))
207 (let ((a 3) (b 2) (c 1.0)) (/ 2.0 0))
208 (let ((a 3) (b 2) (c 1.0)) (/ 2.0 0.0))
209 (let ((a 3) (b 2) (c 1.0)) (/ 0 2))
210 (let ((a 3) (b 2) (c 1.0)) (/ 0 2.0))
211 (let ((a 3) (b 2) (c 1.0)) (/ 0.0 2))
212 (let ((a 3) (b 2) (c 1.0)) (/ 0.0 2.0))
213 (let ((a 3) (b 2) (c 1.0)) (/ a))
214 (let ((a 3) (b 2) (c 1.0)) (/ a 0))
215 (let ((a 3) (b 2) (c 1.0)) (/ a 0.0))
216 (let ((a 3) (b 2) (c 1.0)) (/ 0 a))
217 (let ((a 3) (b 2) (c 1.0)) (/ 0.0 a))
218 (let ((a 3) (b 2) (c 1.0)) (/ c 0))
219 (let ((a 3) (b 2) (c 1.0)) (/ c 0.0))
220 (let ((a 3) (b 2) (c 1.0)) (/ 0 c))
221 (let ((a 3) (b 2) (c 1.0)) (/ 0.0 c))
222 (let ((a 3) (b 2) (c 1.0)) (/ a b 0 c 0))
223 (let ((a 3) (b 2) (c 1.0)) (/ 0 a))
224 (let ((a 3) (b 2) (c 1.0)) (/ 0 a b))
225 (let ((a 3) (b 2) (c 1.0)) (/ 0 a b c))
226 (let ((a 3) (b 2) (c 1.0)) (/ 1 2 3))
227 (let ((a 3) (b 2) (c 1.0)) (/ 3.0 2.0 1))
228 (let ((a 3) (b 2) (c 1.0)) (/ 3.0 2.0 1 4))
229 (let ((a 3) (b 2) (c 1.0)) (/ a 1))
230 (let ((a 3) (b 2) (c 1.0)) (/ a -1))
231 (let ((a 3) (b 2) (c 1.0)) (/ 1 a))
232 (let ((a 3) (b 2) (c 1.0)) (/ -1 a))
233 (let ((a 3) (b 2) (c 1.0)) (/ c 1))
234 (let ((a 3) (b 2) (c 1.0)) (/ c -1))
235 (let ((a 3) (b 2) (c 1.0)) (/ 1 c))
236 (let ((a 3) (b 2) (c 1.0)) (/ -1 c))
237 (let ((a 3) (b 2) (c 1.0)) (/ a b 0))
238 (let ((a 3) (b 2) (c 1.0)) (/ a b 1))
239 (let ((a 3) (b 2) (c 1.0)) (/ a b -1))
240 (let ((a 3) (b 2) (c 1.0)) (/ a b 2))
241 (let ((a 3) (b 2) (c 1.0)) (/ 1 a b c))
242 (let ((a 3) (b 2) (c 1.0)) (/ a b c 0))
243 (let ((a 3) (b 2) (c 1.0)) (/ a b c 1))
244 (let ((a 3) (b 2) (c 1.0)) (/ a b c -1)))
245 "List of expression for test.
246 Each element will be executed by interpreter and with
247 bytecompiled code, and their results compared.")
249 (defun bytecomp-check-1 (pat)
250 "Return non-nil if PAT is the same whether directly evalled or compiled."
251 (let ((warning-minimum-log-level :emergency)
252 (byte-compile-warnings nil)
253 (v0 (condition-case nil
254 (eval pat)
255 (error nil)))
256 (v1 (condition-case nil
257 (funcall (byte-compile (list 'lambda nil pat)))
258 (error nil))))
259 (equal v0 v1)))
261 (put 'bytecomp-check-1 'ert-explainer 'bytecomp-explain-1)
263 (defun bytecomp-explain-1 (pat)
264 (let ((v0 (condition-case nil
265 (eval pat)
266 (error nil)))
267 (v1 (condition-case nil
268 (funcall (byte-compile (list 'lambda nil pat)))
269 (error nil))))
270 (format "Expression `%s' gives `%s' if directly evalled, `%s' if compiled."
271 pat v0 v1)))
273 (ert-deftest bytecomp-tests ()
274 "Test the Emacs byte compiler."
275 (dolist (pat byte-opt-testsuite-arith-data)
276 (should (bytecomp-check-1 pat))))
278 (defun test-byte-opt-arithmetic (&optional arg)
279 "Unit test for byte-opt arithmetic operations.
280 Subtests signal errors if something goes wrong."
281 (interactive "P")
282 (switch-to-buffer (generate-new-buffer "*Font Pase Test*"))
283 (let ((warning-minimum-log-level :emergency)
284 (byte-compile-warnings nil)
285 (pass-face '((t :foreground "green")))
286 (fail-face '((t :foreground "red")))
287 (print-escape-nonascii t)
288 (print-escape-newlines t)
289 (print-quoted t)
290 v0 v1)
291 (dolist (pat byte-opt-testsuite-arith-data)
292 (condition-case nil
293 (setq v0 (eval pat))
294 (error (setq v0 nil)))
295 (condition-case nil
296 (setq v1 (funcall (byte-compile (list 'lambda nil pat))))
297 (error (setq v1 nil)))
298 (insert (format "%s" pat))
299 (indent-to-column 65)
300 (if (equal v0 v1)
301 (insert (propertize "OK" 'face pass-face))
302 (insert (propertize "FAIL\n" 'face fail-face))
303 (indent-to-column 55)
304 (insert (propertize (format "[%s] vs [%s]" v0 v1)
305 'face fail-face)))
306 (insert "\n"))))
309 ;; Local Variables:
310 ;; no-byte-compile: t
311 ;; End:
313 (provide 'byte-opt-testsuite)