aboutsummaryrefslogtreecommitdiffstats
path: root/test/src
diff options
context:
space:
mode:
authorAndrea Corallo2019-08-07 22:00:35 +0200
committerAndrea Corallo2020-01-01 11:33:57 +0100
commita5e428a638718223b0ab667382a8493a135db0ca (patch)
tree7d1aa682ca09b51673cc65465674013fae56d6b7 /test/src
parentb3dc6e8f06892869e0dcf39fd226b63752ce6cf9 (diff)
downloademacs-a5e428a638718223b0ab667382a8493a135db0ca.tar.gz
emacs-a5e428a638718223b0ab667382a8493a135db0ca.zip
rework tests
Diffstat (limited to 'test/src')
-rw-r--r--test/src/comp-tests.el283
1 files changed, 126 insertions, 157 deletions
diff --git a/test/src/comp-tests.el b/test/src/comp-tests.el
index 332dd3f8c0f..e959e265228 100644
--- a/test/src/comp-tests.el
+++ b/test/src/comp-tests.el
@@ -27,19 +27,42 @@
27 27
28(require 'ert) 28(require 'ert)
29(require 'comp) 29(require 'comp)
30;; (require 'cl-lib)
30 31
31(setq garbage-collection-messages t) 32(defun comp-test-apply (func &rest args)
33 (unless (subrp (symbol-function func))
34 (native-compile func))
35 (apply func args))
36
37(defun comp-mashup (&rest args)
38 "Mash-up ARGS and return a symbol."
39 (intern (apply #'concat
40 (mapcar (lambda (x)
41 (cl-etypecase x
42 (symbol (symbol-name x))
43 (string x)))
44 args))))
45
46;; (setq garbage-collection-messages t)
32 47
33(defvar comp-tests-var1 3) 48(defvar comp-tests-var1 3)
34 49
35(ert-deftest comp-tests-varref () 50;; (defmacro comp-ert-deftest (name &rest body)
51;; (declare (indent defun))
52;; `(progn
53;; ,@(cl-loop for speed from 0 to 3
54;; for test-name = (comp-mashup name "-speed-"
55;; (number-to-string speed))
56;; collect `(ert-deftest ,test-name ()
57;; (let ((comp-speed ,speed))
58;; ,body)))))
59
60(ert-deftest comp-tests-varref ()
36 "Testing varref." 61 "Testing varref."
37 (defun comp-tests-varref-f () 62 (defun comp-tests-varref-f ()
38 comp-tests-var1) 63 comp-tests-var1)
39 64
40 (native-compile #'comp-tests-varref-f) 65 (should (= (comp-test-apply #'comp-tests-varref-f) 3)))
41
42 (should (= (comp-tests-varref-f) 3)))
43 66
44(ert-deftest comp-tests-list () 67(ert-deftest comp-tests-list ()
45 "Testing cons car cdr." 68 "Testing cons car cdr."
@@ -60,52 +83,42 @@
60 ;; Bcdr_safe 83 ;; Bcdr_safe
61 (cdr-safe x)) 84 (cdr-safe x))
62 85
63 (native-compile #'comp-tests-list-f) 86 (should (equal (comp-test-apply #'comp-tests-list-f) '(1 2 3)))
64 (native-compile #'comp-tests-list2-f) 87 (should (equal (comp-test-apply #'comp-tests-list2-f 1 2 3) '(1 2 3)))
65 (native-compile #'comp-tests-car-f) 88 (should (= (comp-test-apply #'comp-tests-car-f '(1 . 2)) 1))
66 (native-compile #'comp-tests-cdr-f) 89 (should (null (comp-test-apply #'comp-tests-car-f nil)))
67 (native-compile #'comp-tests-car-safe-f)
68 (native-compile #'comp-tests-cdr-safe-f)
69
70 (should (equal (comp-tests-list-f) '(1 2 3)))
71 (should (equal (comp-tests-list2-f 1 2 3) '(1 2 3)))
72 (should (= (comp-tests-car-f '(1 . 2)) 1))
73 (should (null (comp-tests-car-f nil)))
74 (should (= (condition-case err 90 (should (= (condition-case err
75 (comp-tests-car-f 3) 91 (comp-test-apply #'comp-tests-car-f 3)
76 (error 10)) 92 (error 10))
77 10)) 93 10))
78 (should (= (comp-tests-cdr-f '(1 . 2)) 2)) 94 (should (= (comp-test-apply #'comp-tests-cdr-f '(1 . 2)) 2))
79 (should (null (comp-tests-cdr-f nil))) 95 (should (null (comp-test-apply #'comp-tests-cdr-f nil)))
80 (should (= (condition-case err 96 (should (= (condition-case err
81 (comp-tests-cdr-f 3) 97 (comp-test-apply #'comp-tests-cdr-f 3)
82 (error 10)) 98 (error 10))
83 10)) 99 10))
84 (should (= (comp-tests-car-safe-f '(1 . 2)) 1)) 100 (should (= (comp-test-apply #'comp-tests-car-safe-f '(1 . 2)) 1))
85 (should (null (comp-tests-car-safe-f 'a))) 101 (should (null (comp-test-apply #'comp-tests-car-safe-f 'a)))
86 (should (= (comp-tests-cdr-safe-f '(1 . 2)) 2)) 102 (should (= (comp-test-apply #'comp-tests-cdr-safe-f '(1 . 2)) 2))
87 (should (null (comp-tests-cdr-safe-f 'a)))) 103 (should (null (comp-test-apply #'comp-tests-cdr-safe-f 'a))))
88 104
89(ert-deftest comp-tests-cons-car-cdr () 105(ert-deftest comp-tests-cons-car-cdr ()
90 "Testing cons car cdr." 106 "Testing cons car cdr."
91 (defun comp-tests-cons-car-f () 107 (defun comp-tests-cons-car-f ()
92 (car (cons 1 2))) 108 (car (cons 1 2)))
93 (native-compile #'comp-tests-cons-car-f)
94 109
95 (defun comp-tests-cons-cdr-f (x) 110 (defun comp-tests-cons-cdr-f (x)
96 (cdr (cons 'foo x))) 111 (cdr (cons 'foo x)))
97 (native-compile #'comp-tests-cons-cdr-f)
98 112
99 (should (= (comp-tests-cons-car-f) 1)) 113 (should (= (comp-test-apply #'comp-tests-cons-car-f) 1))
100 (should (= (comp-tests-cons-cdr-f 3) 3))) 114 (should (= (comp-test-apply #'comp-tests-cons-cdr-f 3) 3)))
101 115
102(ert-deftest comp-tests-varset () 116(ert-deftest comp-tests-varset ()
103 "Testing varset." 117 "Testing varset."
104 (defun comp-tests-varset-f () 118 (defun comp-tests-varset-f ()
105 (setq comp-tests-var1 55)) 119 (setq comp-tests-var1 55))
106 (native-compile #'comp-tests-varset-f)
107 120
108 (comp-tests-varset-f) 121 (comp-test-apply #'comp-tests-varset-f)
109 122
110 (should (= comp-tests-var1 55))) 123 (should (= comp-tests-var1 55)))
111 124
@@ -113,98 +126,91 @@
113 "Testing length." 126 "Testing length."
114 (defun comp-tests-length-f () 127 (defun comp-tests-length-f ()
115 (length '(1 2 3))) 128 (length '(1 2 3)))
116 (native-compile #'comp-tests-length-f)
117 129
118 (should (= (comp-tests-length-f) 3))) 130 (should (= (comp-test-apply #'comp-tests-length-f) 3)))
119 131
120(ert-deftest comp-tests-aref-aset () 132(ert-deftest comp-tests-aref-aset ()
121 "Testing aref and aset." 133 "Testing aref and aset."
122 (defun comp-tests-aref-aset-f () 134 (defun comp-tests-aref-aset-f ()
123 (let ((vec [1 2 3])) 135 (let ((vec [1 2 3]))
124 (aset vec 2 100) 136 (aset vec 2 100)
125 (aref vec 2))) 137 (aref vec 2)))
126 (native-compile #'comp-tests-aref-aset-f)
127 138
128 (should (= (comp-tests-aref-aset-f) 100))) 139 (should (= (comp-test-apply #'comp-tests-aref-aset-f) 100)))
129 140
130(ert-deftest comp-tests-symbol-value () 141(ert-deftest comp-tests-symbol-value ()
131 "Testing aref and aset." 142 "Testing aref and aset."
132 (defvar comp-tests-var2 3) 143 (defvar comp-tests-var2 3)
133 (defun comp-tests-symbol-value-f () 144 (defun comp-tests-symbol-value-f ()
134 (symbol-value 'comp-tests-var2)) 145 (symbol-value 'comp-tests-var2))
135 (native-compile #'comp-tests-symbol-value-f)
136 146
137 (should (= (comp-tests-symbol-value-f) 3))) 147 (should (= (comp-test-apply #'comp-tests-symbol-value-f) 3)))
138 148
139(ert-deftest comp-tests-concat () 149(ert-deftest comp-tests-concat ()
140 "Testing concatX opcodes." 150 "Testing concatX opcodes."
141 (defun comp-tests-concat-f (x) 151 (defun comp-tests-concat-f (x)
142 (concat "a" "b" "c" "d" 152 (concat "a" "b" "c" "d"
143 (concat "a" "b" "c" (concat "a" "b" (concat "foo" x))))) 153 (concat "a" "b" "c" (concat "a" "b" (concat "foo" x)))))
144 (native-compile #'comp-tests-concat-f)
145 154
146 (should (string= (comp-tests-concat-f "bar") "abcdabcabfoobar"))) 155 (should (string= (comp-test-apply #'comp-tests-concat-f "bar") "abcdabcabfoobar")))
147 156
148(ert-deftest comp-tests-ffuncall () 157(defun comp-tests-ffuncall-callee-f (x y z)
149 "Test calling conventions."
150 (defun comp-tests-ffuncall-callee-f (x y z)
151 (list x y z)) 158 (list x y z))
159
160(ert-deftest comp-tests-ffuncall ()
161 "Test calling conventions."
162 (native-compile #'comp-tests-ffuncall-calle-f)
152 (defun comp-tests-ffuncall-caller-f () 163 (defun comp-tests-ffuncall-caller-f ()
153 (comp-tests-ffuncall-callee-f 1 2 3)) 164 (comp-tests-ffuncall-callee-f 1 2 3))
154 165
155 (native-compile #'comp-tests-ffuncall-caller-f) 166 (should (equal (comp-test-apply #'comp-tests-ffuncall-caller-f) '(1 2 3)))
156
157 (should (equal (comp-tests-ffuncall-caller-f) '(1 2 3)))
158 167
159 (defun comp-tests-ffuncall-callee-optional-f (a b &optional c d) 168 (defun comp-tests-ffuncall-callee-optional-f (a b &optional c d)
160 (list a b c d)) 169 (list a b c d))
161 (native-compile #'comp-tests-ffuncall-callee-optional-f)
162 170
163 (should (equal (comp-tests-ffuncall-callee-optional-f 1 2 3 4) '(1 2 3 4))) 171 (should (equal (comp-test-apply #'comp-tests-ffuncall-callee-optional-f 1 2 3 4)
164 (should (equal (comp-tests-ffuncall-callee-optional-f 1 2 3) '(1 2 3 nil))) 172 '(1 2 3 4)))
165 (should (equal (comp-tests-ffuncall-callee-optional-f 1 2) '(1 2 nil nil))) 173 (should (equal (comp-test-apply #'comp-tests-ffuncall-callee-optional-f 1 2 3)
174 '(1 2 3 nil)))
175 (should (equal (comp-test-apply #'comp-tests-ffuncall-callee-optional-f 1 2)
176 '(1 2 nil nil)))
166 177
167 (defun comp-tests-ffuncall-callee-rest-f (a b &rest c) 178 (defun comp-tests-ffuncall-callee-rest-f (a b &rest c)
168 (list a b c)) 179 (list a b c))
169 (native-compile #'comp-tests-ffuncall-callee-rest-f)
170 180
171 (should (equal (comp-tests-ffuncall-callee-rest-f 1 2) '(1 2 nil))) 181 (should (equal (comp-test-apply #'comp-tests-ffuncall-callee-rest-f 1 2)
172 (should (equal (comp-tests-ffuncall-callee-rest-f 1 2 3) '(1 2 (3)))) 182 '(1 2 nil)))
173 (should (equal (comp-tests-ffuncall-callee-rest-f 1 2 3 4) '(1 2 (3 4)))) 183 (should (equal (comp-test-apply #'comp-tests-ffuncall-callee-rest-f 1 2 3)
184 '(1 2 (3))))
185 (should (equal (comp-test-apply #'comp-tests-ffuncall-callee-rest-f 1 2 3 4)
186 '(1 2 (3 4))))
174 187
175 (defun comp-tests-ffuncall-native-f () 188 (defun comp-tests-ffuncall-native-f ()
176 "Call a primitive with no dedicate op." 189 "Call a primitive with no dedicate op."
177 (make-vector 1 nil)) 190 (make-vector 1 nil))
178 191
179 (native-compile #'comp-tests-ffuncall-native-f) 192 (should (equal (comp-test-apply #'comp-tests-ffuncall-native-f) [nil]))
180
181 (should (equal (comp-tests-ffuncall-native-f) [nil]))
182 193
183 (defun comp-tests-ffuncall-native-rest-f () 194 (defun comp-tests-ffuncall-native-rest-f ()
184 "Call a primitive with no dedicate op with &rest." 195 "Call a primitive with no dedicate op with &rest."
185 (vector 1 2 3)) 196 (vector 1 2 3))
186 197
187 (native-compile #'comp-tests-ffuncall-native-rest-f) 198 (should (equal (comp-test-apply #'comp-tests-ffuncall-native-rest-f) [1 2 3]))
188
189 (should (equal (comp-tests-ffuncall-native-rest-f) [1 2 3]))
190 199
191 (defun comp-tests-ffuncall-apply-many-f (x) 200 (defun comp-tests-ffuncall-apply-many-f (x)
192 (apply #'list x)) 201 (apply #'list x))
193 202
194 (native-compile #'comp-tests-ffuncall-apply-many-f) 203 (should (equal (comp-test-apply #'comp-tests-ffuncall-apply-many-f '(1 2 3))
195 204 '(1 2 3)))
196 (should (equal (comp-tests-ffuncall-apply-many-f '(1 2 3)) '(1 2 3)))
197 205
198 (defun comp-tests-ffuncall-lambda-f (x) 206 (defun comp-tests-ffuncall-lambda-f (x)
199 (let ((fun (lambda (x) 207 (let ((fun (lambda (x)
200 (1+ x)))) 208 (1+ x))))
201 (funcall fun x))) 209 (funcall fun x)))
202 210
203 (native-compile #'comp-tests-ffuncall-lambda-f) 211 (should (= (comp-test-apply #'comp-tests-ffuncall-lambda-f 1) 2)))
204
205 (should (= (comp-tests-ffuncall-lambda-f 1) 2)))
206 212
207(ert-deftest comp-tests-jump-table () 213(ert-deftest comp-tests-jump-table ()
208 "Testing jump tables" 214 "Testing jump tables"
209 (defun comp-tests-jump-table-1-f (x) 215 (defun comp-tests-jump-table-1-f (x)
210 (pcase x 216 (pcase x
@@ -212,13 +218,11 @@
212 ('y 'b) 218 ('y 'b)
213 (_ 'c))) 219 (_ 'c)))
214 220
215 (native-compile #'comp-tests-jump-table-1-f) 221 (should (eq (comp-test-apply #'comp-tests-jump-table-1-f 'x) 'a))
222 (should (eq (comp-test-apply #'comp-tests-jump-table-1-f 'y) 'b))
223 (should (eq (comp-test-apply #'comp-tests-jump-table-1-f 'xxx) 'c)))
216 224
217 (should (eq (comp-tests-jump-table-1-f 'x) 'a)) 225(ert-deftest comp-tests-conditionals ()
218 (should (eq (comp-tests-jump-table-1-f 'y) 'b))
219 (should (eq (comp-tests-jump-table-1-f 'xxx) 'c)))
220
221(ert-deftest comp-tests-conditionals ()
222 "Testing conditionals." 226 "Testing conditionals."
223 (defun comp-tests-conditionals-1-f (x) 227 (defun comp-tests-conditionals-1-f (x)
224 ;; Generate goto-if-nil 228 ;; Generate goto-if-nil
@@ -227,15 +231,13 @@
227 ;; Generate goto-if-nil-else-pop 231 ;; Generate goto-if-nil-else-pop
228 (when x 232 (when x
229 1340)) 233 1340))
230 (native-compile #'comp-tests-conditionals-1-f)
231 (native-compile #'comp-tests-conditionals-2-f)
232 234
233 (should (= (comp-tests-conditionals-1-f t) 1)) 235 (should (= (comp-test-apply #'comp-tests-conditionals-1-f t) 1))
234 (should (= (comp-tests-conditionals-1-f nil) 2)) 236 (should (= (comp-test-apply #'comp-tests-conditionals-1-f nil) 2))
235 (should (= (comp-tests-conditionals-2-f t) 1340)) 237 (should (= (comp-test-apply #'comp-tests-conditionals-2-f t) 1340))
236 (should (eq (comp-tests-conditionals-2-f nil) nil))) 238 (should (eq (comp-test-apply #'comp-tests-conditionals-2-f nil) nil)))
237 239
238(ert-deftest comp-tests-fixnum () 240(ert-deftest comp-tests-fixnum ()
239 "Testing some fixnum inline operation." 241 "Testing some fixnum inline operation."
240 (defun comp-tests-fixnum-1-minus-f (x) 242 (defun comp-tests-fixnum-1-minus-f (x)
241 ;; Bsub1 243 ;; Bsub1
@@ -247,33 +249,29 @@
247 ;; Bnegate 249 ;; Bnegate
248 (- x)) 250 (- x))
249 251
250 (native-compile #'comp-tests-fixnum-1-minus-f) 252 (should (= (comp-test-apply #'comp-tests-fixnum-1-minus-f 10) 9))
251 (native-compile #'comp-tests-fixnum-1-plus-f) 253 (should (= (comp-test-apply #'comp-tests-fixnum-1-minus-f most-negative-fixnum)
252 (native-compile #'comp-tests-fixnum-minus-f)
253
254 (should (= (comp-tests-fixnum-1-minus-f 10) 9))
255 (should (= (comp-tests-fixnum-1-minus-f most-negative-fixnum)
256 (1- most-negative-fixnum))) 254 (1- most-negative-fixnum)))
257 (should (equal (condition-case err 255 (should (equal (condition-case err
258 (comp-tests-fixnum-1-minus-f 'a) 256 (comp-tests-fixnum-1-minus-f 'a)
259 (error err)) 257 (error err))
260 '(wrong-type-argument number-or-marker-p a))) 258 '(wrong-type-argument number-or-marker-p a)))
261 (should (= (comp-tests-fixnum-1-plus-f 10) 11)) 259 (should (= (comp-test-apply #'comp-tests-fixnum-1-plus-f 10) 11))
262 (should (= (comp-tests-fixnum-1-plus-f most-positive-fixnum) 260 (should (= (comp-test-apply #'comp-tests-fixnum-1-plus-f most-positive-fixnum)
263 (1+ most-positive-fixnum))) 261 (1+ most-positive-fixnum)))
264 (should (equal (condition-case err 262 (should (equal (condition-case err
265 (comp-tests-fixnum-1-plus-f 'a) 263 (comp-tests-fixnum-1-plus-f 'a)
266 (error err)) 264 (error err))
267 '(wrong-type-argument number-or-marker-p a))) 265 '(wrong-type-argument number-or-marker-p a)))
268 (should (= (comp-tests-fixnum-minus-f 10) -10)) 266 (should (= (comp-test-apply #'comp-tests-fixnum-minus-f 10) -10))
269 (should (= (comp-tests-fixnum-minus-f most-negative-fixnum) 267 (should (= (comp-test-apply #'comp-tests-fixnum-minus-f most-negative-fixnum)
270 (- most-negative-fixnum))) 268 (- most-negative-fixnum)))
271 (should (equal (condition-case err 269 (should (equal (condition-case err
272 (comp-tests-fixnum-minus-f 'a) 270 (comp-tests-fixnum-minus-f 'a)
273 (error err)) 271 (error err))
274 '(wrong-type-argument number-or-marker-p a)))) 272 '(wrong-type-argument number-or-marker-p a))))
275 273
276(ert-deftest comp-tests-arith-comp () 274(ert-deftest comp-tests-arith-comp ()
277 "Testing arithmetic comparisons." 275 "Testing arithmetic comparisons."
278 (defun comp-tests-eqlsign-f (x y) 276 (defun comp-tests-eqlsign-f (x y)
279 ;; Beqlsign 277 ;; Beqlsign
@@ -291,27 +289,21 @@
291 ;; Bgeq 289 ;; Bgeq
292 (>= x y)) 290 (>= x y))
293 291
294 (native-compile #'comp-tests-eqlsign-f) 292 (should (eq (comp-test-apply #'comp-tests-eqlsign-f 4 3) nil))
295 (native-compile #'comp-tests-gtr-f) 293 (should (eq (comp-test-apply #'comp-tests-eqlsign-f 3 3) t))
296 (native-compile #'comp-tests-lss-f) 294 (should (eq (comp-test-apply #'comp-tests-eqlsign-f 2 3) nil))
297 (native-compile #'comp-tests-les-f) 295 (should (eq (comp-test-apply #'comp-tests-gtr-f 4 3) t))
298 (native-compile #'comp-tests-geq-f) 296 (should (eq (comp-test-apply #'comp-tests-gtr-f 3 3) nil))
299 297 (should (eq (comp-test-apply #'comp-tests-gtr-f 2 3) nil))
300 (should (eq (comp-tests-eqlsign-f 4 3) nil)) 298 (should (eq (comp-test-apply #'comp-tests-lss-f 4 3) nil))
301 (should (eq (comp-tests-eqlsign-f 3 3) t)) 299 (should (eq (comp-test-apply #'comp-tests-lss-f 3 3) nil))
302 (should (eq (comp-tests-eqlsign-f 2 3) nil)) 300 (should (eq (comp-test-apply #'comp-tests-lss-f 2 3) t))
303 (should (eq (comp-tests-gtr-f 4 3) t)) 301 (should (eq (comp-test-apply #'comp-tests-les-f 4 3) nil))
304 (should (eq (comp-tests-gtr-f 3 3) nil)) 302 (should (eq (comp-test-apply #'comp-tests-les-f 3 3) t))
305 (should (eq (comp-tests-gtr-f 2 3) nil)) 303 (should (eq (comp-test-apply #'comp-tests-les-f 2 3) t))
306 (should (eq (comp-tests-lss-f 4 3) nil)) 304 (should (eq (comp-test-apply #'comp-tests-geq-f 4 3) t))
307 (should (eq (comp-tests-lss-f 3 3) nil)) 305 (should (eq (comp-test-apply #'comp-tests-geq-f 3 3) t))
308 (should (eq (comp-tests-lss-f 2 3) t)) 306 (should (eq (comp-test-apply #'comp-tests-geq-f 2 3) nil)))
309 (should (eq (comp-tests-les-f 4 3) nil))
310 (should (eq (comp-tests-les-f 3 3) t))
311 (should (eq (comp-tests-les-f 2 3) t))
312 (should (eq (comp-tests-geq-f 4 3) t))
313 (should (eq (comp-tests-geq-f 3 3) t))
314 (should (eq (comp-tests-geq-f 2 3) nil)))
315 307
316(ert-deftest comp-tests-setcarcdr () 308(ert-deftest comp-tests-setcarcdr ()
317 "Testing setcar setcdr." 309 "Testing setcar setcdr."
@@ -322,11 +314,8 @@
322 (setcdr x y) 314 (setcdr x y)
323 x) 315 x)
324 316
325 (native-compile #'comp-tests-setcar-f) 317 (should (equal (comp-test-apply #'comp-tests-setcar-f '(10 . 10) 3) '(3 . 10)))
326 (native-compile #'comp-tests-setcdr-f) 318 (should (equal (comp-test-apply #'comp-tests-setcdr-f '(10 . 10) 3) '(10 . 3)))
327
328 (should (equal (comp-tests-setcar-f '(10 . 10) 3) '(3 . 10)))
329 (should (equal (comp-tests-setcdr-f '(10 . 10) 3) '(10 . 3)))
330 (should (equal (condition-case 319 (should (equal (condition-case
331 err 320 err
332 (comp-tests-setcar-f 3 10) 321 (comp-tests-setcar-f 3 10)
@@ -334,7 +323,7 @@
334 '(wrong-type-argument consp 3))) 323 '(wrong-type-argument consp 3)))
335 (should (equal (condition-case 324 (should (equal (condition-case
336 err 325 err
337 (comp-tests-setcdr-f 3 10) 326 (comp-test-apply #'comp-tests-setcdr-f 3 10)
338 (error err)) 327 (error err))
339 '(wrong-type-argument consp 3)))) 328 '(wrong-type-argument consp 3))))
340 329
@@ -352,14 +341,12 @@
352 (setq i (1- i))) 341 (setq i (1- i)))
353 list)) 342 list))
354 343
355 (native-compile #'comp-bubble-sort-f)
356
357 (let* ((list1 (mapcar 'random (make-list 1000 most-positive-fixnum))) 344 (let* ((list1 (mapcar 'random (make-list 1000 most-positive-fixnum)))
358 (list2 (copy-sequence list1))) 345 (list2 (copy-sequence list1)))
359 (should (equal (comp-bubble-sort-f list1) 346 (should (equal (comp-bubble-sort-f list1)
360 (sort list2 #'<))))) 347 (sort list2 #'<)))))
361 348
362(ert-deftest comp-tests-list-inline () 349(ert-deftest comp-test-apply ()
363 "Test some inlined list functions." 350 "Test some inlined list functions."
364 (defun comp-tests-consp-f (x) 351 (defun comp-tests-consp-f (x)
365 ;; Bconsp 352 ;; Bconsp
@@ -368,13 +355,10 @@
368 ;; Bsetcar 355 ;; Bsetcar
369 (setcar x 3)) 356 (setcar x 3))
370 357
371 (native-compile #'comp-tests-consp-f) 358 (should (eq (comp-test-apply #'comp-tests-consp-f '(1)) t))
372 (native-compile #'comp-tests-car-f) 359 (should (eq (comp-test-apply #'comp-tests-consp-f 1) nil))
373
374 (should (eq (comp-tests-consp-f '(1)) t))
375 (should (eq (comp-tests-consp-f 1) nil))
376 (let ((x (cons 1 2))) 360 (let ((x (cons 1 2)))
377 (should (= (comp-tests-car-f x) 3)) 361 (should (= (comp-test-apply #'comp-tests-car-f x) 3))
378 (should (equal x '(3 . 2))))) 362 (should (equal x '(3 . 2)))))
379 363
380(ert-deftest comp-tests-num-inline () 364(ert-deftest comp-tests-num-inline ()
@@ -386,17 +370,14 @@
386 ;; Bnumberp 370 ;; Bnumberp
387 (numberp x)) 371 (numberp x))
388 372
389 (native-compile #'comp-tests-integerp-f) 373 (should (eq (comp-test-apply #'comp-tests-integerp-f 1) t))
390 (native-compile #'comp-tests-numberp-f) 374 (should (eq (comp-test-apply #'comp-tests-integerp-f '(1)) nil))
391 375 (should (eq (comp-test-apply #'comp-tests-integerp-f 3.5) nil))
392 (should (eq (comp-tests-integerp-f 1) t)) 376 (should (eq (comp-test-apply #'comp-tests-integerp-f (1+ most-negative-fixnum)) t))
393 (should (eq (comp-tests-integerp-f '(1)) nil))
394 (should (eq (comp-tests-integerp-f 3.5) nil))
395 (should (eq (comp-tests-integerp-f (1+ most-negative-fixnum)) t))
396 377
397 (should (eq (comp-tests-numberp-f 1) t)) 378 (should (eq (comp-test-apply #'comp-tests-numberp-f 1) t))
398 (should (eq (comp-tests-numberp-f 'a) nil)) 379 (should (eq (comp-test-apply #'comp-tests-numberp-f 'a) nil))
399 (should (eq (comp-tests-numberp-f 3.5) t))) 380 (should (eq (comp-test-apply #'comp-tests-numberp-f 3.5) t)))
400 381
401(ert-deftest comp-tests-stack () 382(ert-deftest comp-tests-stack ()
402 "Test some stack operation." 383 "Test some stack operation."
@@ -410,11 +391,7 @@
410 ;; Binsert 391 ;; Binsert
411 (insert a b c d)) 392 (insert a b c d))
412 393
413 (native-compile #'comp-tests-discardn-f) 394 (should (= (comp-test-apply #'comp-tests-discardn-f 10) 2))
414 (native-compile #'comp-tests-insertn-f)
415
416 (should (= (comp-tests-discardn-f 10) 2))
417
418 (should (string= (with-temp-buffer 395 (should (string= (with-temp-buffer
419 (comp-tests-insertn-f "a" "b" "c" "d") 396 (comp-tests-insertn-f "a" "b" "c" "d")
420 (buffer-string)) 397 (buffer-string))
@@ -459,16 +436,13 @@
459 (defun comp-tests-throw-f (x) 436 (defun comp-tests-throw-f (x)
460 (throw 'foo x)) 437 (throw 'foo x))
461 438
462 (native-compile #'comp-tests-condition-case-0-f) 439 (should (string= (comp-test-apply #'comp-tests-condition-case-0-f)
463 (native-compile #'comp-tests-condition-case-1-f)
464 (native-compile #'comp-tests-catch-f)
465 (native-compile #'comp-tests-throw-f)
466
467 (should (string= (comp-tests-condition-case-0-f)
468 "arith-error Arithmetic error catched")) 440 "arith-error Arithmetic error catched"))
469 (should (string= (comp-tests-condition-case-1-f) 441 (should (string= (comp-test-apply #'comp-tests-condition-case-1-f)
470 "error foo catched")) 442 "error foo catched"))
471 (should (= (comp-tests-catch-f (lambda () (throw 'foo 3))) 3)) 443 (should (= (comp-test-apply #'comp-tests-catch-f
444 (lambda () (throw 'foo 3)))
445 3))
472 (should (= (catch 'foo 446 (should (= (catch 'foo
473 (comp-tests-throw-f 3)))))) 447 (comp-tests-throw-f 3))))))
474 448
@@ -477,17 +451,12 @@
477 (dotimes (_ 100000) 451 (dotimes (_ 100000)
478 (comp-tests-cons-cdr-f 3)) 452 (comp-tests-cons-cdr-f 3))
479 453
480 (should (= (comp-tests-cons-cdr-f 3) 3))) 454 (should (= (comp-test-apply #'comp-tests-cons-cdr-f 3) 3)))
481 455
482;;;;;;;;;;;;;;;;;;;; 456;;;;;;;;;;;;;;;;;;;;
483;; Tromey's tests ;; 457;; Tromey's tests ;;
484;;;;;;;;;;;;;;;;;;;; 458;;;;;;;;;;;;;;;;;;;;
485 459
486(defun comp-test-apply (func &rest args)
487 (unless (subrp (symbol-function func))
488 (native-compile func))
489 (apply func args))
490
491;; Test Bconsp. 460;; Test Bconsp.
492(defun comp-test-consp (x) (consp x)) 461(defun comp-test-consp (x) (consp x))
493 462