aboutsummaryrefslogtreecommitdiffstats
path: root/test/src
diff options
context:
space:
mode:
authorTom Tromey2018-08-09 17:56:53 -0600
committerTom Tromey2018-08-09 17:56:53 -0600
commitaccb7b7ecc19f85c2750ded1046a464bc73c6a52 (patch)
tree1aa94af022d6700a93a8ff2b73f5b210046ac010 /test/src
parentf822a2516d88eeb2118fbbc8554f155e86dfd74e (diff)
parent53483df0de0085dbc9ef0b15a0f629ab808b0147 (diff)
downloademacs-accb7b7ecc19f85c2750ded1046a464bc73c6a52.tar.gz
emacs-accb7b7ecc19f85c2750ded1046a464bc73c6a52.zip
Merge remote-tracking branch 'origin/master' into feature/bignum
Diffstat (limited to 'test/src')
-rw-r--r--test/src/editfns-tests.el8
-rw-r--r--test/src/fns-tests.el11
-rw-r--r--test/src/regex-emacs-tests.el (renamed from test/src/regex-tests.el)6
-rw-r--r--test/src/thread-tests.el125
4 files changed, 104 insertions, 46 deletions
diff --git a/test/src/editfns-tests.el b/test/src/editfns-tests.el
index 501e0d87818..8dee4bdc0fd 100644
--- a/test/src/editfns-tests.el
+++ b/test/src/editfns-tests.el
@@ -169,7 +169,13 @@
169 (should (eq (type-of (read (format "#o%o" most-negative-fixnum))) 169 (should (eq (type-of (read (format "#o%o" most-negative-fixnum)))
170 'integer)) 170 'integer))
171 (should (eq (type-of (read (format "#32rG%x" most-positive-fixnum))) 171 (should (eq (type-of (read (format "#32rG%x" most-positive-fixnum)))
172 'integer))) 172 'integer))
173 (let ((binary-as-unsigned nil))
174 (dolist (fmt '("%d" "%s" "#o%o" "#x%x"))
175 (dolist (val (list most-negative-fixnum (1+ most-negative-fixnum)
176 -1 0 1
177 (1- most-positive-fixnum) most-positive-fixnum))
178 (should (eq val (read (format fmt val))))))))
173 179
174(ert-deftest format-%o-invalid-float () 180(ert-deftest format-%o-invalid-float ()
175 (should-error (format "%o" -1e-37) 181 (should-error (format "%o" -1e-37)
diff --git a/test/src/fns-tests.el b/test/src/fns-tests.el
index d560f0bb0d9..f722ed6333e 100644
--- a/test/src/fns-tests.el
+++ b/test/src/fns-tests.el
@@ -23,6 +23,17 @@
23 23
24(require 'cl-lib) 24(require 'cl-lib)
25 25
26;; Test that equality predicates work correctly on NaNs when combined
27;; with hash tables based on those predicates. This was not the case
28;; for eql in Emacs 26.
29(ert-deftest fns-tests-equality-nan ()
30 (dolist (test (list #'eq #'eql #'equal))
31 (let* ((h (make-hash-table :test test))
32 (nan 0.0e+NaN)
33 (-nan (- nan)))
34 (puthash nan t h)
35 (should (eq (funcall test nan -nan) (gethash -nan h))))))
36
26(ert-deftest fns-tests-reverse () 37(ert-deftest fns-tests-reverse ()
27 (should-error (reverse)) 38 (should-error (reverse))
28 (should-error (reverse 1)) 39 (should-error (reverse 1))
diff --git a/test/src/regex-tests.el b/test/src/regex-emacs-tests.el
index 083ed5c4c8c..7a075908a6b 100644
--- a/test/src/regex-tests.el
+++ b/test/src/regex-emacs-tests.el
@@ -1,4 +1,4 @@
1;;; regex-tests.el --- tests for regex.c functions -*- lexical-binding: t -*- 1;;; regex-emacs-tests.el --- tests for regex-emacs.c -*- lexical-binding: t -*-
2 2
3;; Copyright (C) 2015-2018 Free Software Foundation, Inc. 3;; Copyright (C) 2015-2018 Free Software Foundation, Inc.
4 4
@@ -24,7 +24,7 @@
24(defvar regex-tests--resources-dir 24(defvar regex-tests--resources-dir
25 (concat (concat (file-name-directory (or load-file-name buffer-file-name)) 25 (concat (concat (file-name-directory (or load-file-name buffer-file-name))
26 "/regex-resources/")) 26 "/regex-resources/"))
27 "Path to regex-resources directory next to the \"regex-tests.el\" file.") 27 "Path to regex-resources directory next to the \"regex-emacs-tests.el\" file.")
28 28
29(ert-deftest regex-word-cc-fallback-test () 29(ert-deftest regex-word-cc-fallback-test ()
30 "Test that \"[[:cc:]]*x\" matches \"x\" (bug#24020). 30 "Test that \"[[:cc:]]*x\" matches \"x\" (bug#24020).
@@ -683,4 +683,4 @@ This evaluates the TESTS test cases from glibc."
683 (should-not (string-match "\\`x\\{65535\\}" (make-string 65534 ?x))) 683 (should-not (string-match "\\`x\\{65535\\}" (make-string 65534 ?x)))
684 (should-error (string-match "\\`x\\{65536\\}" "X") :type 'invalid-regexp)) 684 (should-error (string-match "\\`x\\{65536\\}" "X") :type 'invalid-regexp))
685 685
686;;; regex-tests.el ends here 686;;; regex-emacs-tests.el ends here
diff --git a/test/src/thread-tests.el b/test/src/thread-tests.el
index 0e909d3e511..364f6d61f05 100644
--- a/test/src/thread-tests.el
+++ b/test/src/thread-tests.el
@@ -19,38 +19,64 @@
19 19
20;;; Code: 20;;; Code:
21 21
22;; Declare the functions in case Emacs has been configured --without-threads.
23(declare-function all-threads "thread.c" ())
24(declare-function condition-mutex "thread.c" (cond))
25(declare-function condition-name "thread.c" (cond))
26(declare-function condition-notify "thread.c" (cond &optional all))
27(declare-function condition-wait "thread.c" (cond))
28(declare-function current-thread "thread.c" ())
29(declare-function make-condition-variable "thread.c" (mutex &optional name))
30(declare-function make-mutex "thread.c" (&optional name))
31(declare-function make-thread "thread.c" (function &optional name))
32(declare-function mutex-lock "thread.c" (mutex))
33(declare-function mutex-unlock "thread.c" (mutex))
34(declare-function thread--blocker "thread.c" (thread))
35(declare-function thread-alive-p "thread.c" (thread))
36(declare-function thread-join "thread.c" (thread))
37(declare-function thread-last-error "thread.c" (&optional cleanup))
38(declare-function thread-name "thread.c" (thread))
39(declare-function thread-signal "thread.c" (thread error-symbol data))
40(declare-function thread-yield "thread.c" ())
41(defvar main-thread)
42
22(ert-deftest threads-is-one () 43(ert-deftest threads-is-one ()
23 "Test for existence of a thread." 44 "Test for existence of a thread."
24 (skip-unless (fboundp 'make-thread)) 45 (skip-unless (featurep 'threads))
25 (should (current-thread))) 46 (should (current-thread)))
26 47
27(ert-deftest threads-threadp () 48(ert-deftest threads-threadp ()
28 "Test of threadp." 49 "Test of threadp."
29 (skip-unless (fboundp 'make-thread)) 50 (skip-unless (featurep 'threads))
30 (should (threadp (current-thread)))) 51 (should (threadp (current-thread))))
31 52
32(ert-deftest threads-type () 53(ert-deftest threads-type ()
33 "Test of thread type." 54 "Test of thread type."
34 (skip-unless (fboundp 'make-thread)) 55 (skip-unless (featurep 'threads))
35 (should (eq (type-of (current-thread)) 'thread))) 56 (should (eq (type-of (current-thread)) 'thread)))
36 57
37(ert-deftest threads-name () 58(ert-deftest threads-name ()
38 "Test for name of a thread." 59 "Test for name of a thread."
39 (skip-unless (fboundp 'make-thread)) 60 (skip-unless (featurep 'threads))
40 (should 61 (should
41 (string= "hi bob" (thread-name (make-thread #'ignore "hi bob"))))) 62 (string= "hi bob" (thread-name (make-thread #'ignore "hi bob")))))
42 63
43(ert-deftest threads-alive () 64(ert-deftest threads-alive ()
44 "Test for thread liveness." 65 "Test for thread liveness."
45 (skip-unless (fboundp 'make-thread)) 66 (skip-unless (featurep 'threads))
46 (should 67 (should
47 (thread-alive-p (make-thread #'ignore)))) 68 (thread-alive-p (make-thread #'ignore))))
48 69
49(ert-deftest threads-all-threads () 70(ert-deftest threads-all-threads ()
50 "Simple test for all-threads." 71 "Simple test for all-threads."
51 (skip-unless (fboundp 'make-thread)) 72 (skip-unless (featurep 'threads))
52 (should (listp (all-threads)))) 73 (should (listp (all-threads))))
53 74
75(ert-deftest threads-main-thread ()
76 "Simple test for all-threads."
77 (skip-unless (featurep 'threads))
78 (should (eq main-thread (car (all-threads)))))
79
54(defvar threads-test-global nil) 80(defvar threads-test-global nil)
55 81
56(defun threads-test-thread1 () 82(defun threads-test-thread1 ()
@@ -58,7 +84,7 @@
58 84
59(ert-deftest threads-basic () 85(ert-deftest threads-basic ()
60 "Basic thread test." 86 "Basic thread test."
61 (skip-unless (fboundp 'make-thread)) 87 (skip-unless (featurep 'threads))
62 (should 88 (should
63 (progn 89 (progn
64 (setq threads-test-global nil) 90 (setq threads-test-global nil)
@@ -69,20 +95,29 @@
69 95
70(ert-deftest threads-join () 96(ert-deftest threads-join ()
71 "Test of `thread-join'." 97 "Test of `thread-join'."
72 (skip-unless (fboundp 'make-thread)) 98 (skip-unless (featurep 'threads))
73 (should 99 (should
74 (progn 100 (progn
75 (setq threads-test-global nil) 101 (setq threads-test-global nil)
76 (let ((thread (make-thread #'threads-test-thread1))) 102 (let ((thread (make-thread #'threads-test-thread1)))
77 (thread-join thread) 103 (and (= (thread-join thread) 23)
78 (and threads-test-global 104 (= threads-test-global 23)
79 (not (thread-alive-p thread))))))) 105 (not (thread-alive-p thread)))))))
80 106
81(ert-deftest threads-join-self () 107(ert-deftest threads-join-self ()
82 "Cannot `thread-join' the current thread." 108 "Cannot `thread-join' the current thread."
83 (skip-unless (fboundp 'make-thread)) 109 (skip-unless (featurep 'threads))
84 (should-error (thread-join (current-thread)))) 110 (should-error (thread-join (current-thread))))
85 111
112(ert-deftest threads-join-error ()
113 "Test of error signalling from `thread-join'."
114 :tags '(:unstable)
115 (skip-unless (featurep 'threads))
116 (let ((thread (make-thread #'threads-call-error)))
117 (while (thread-alive-p thread)
118 (thread-yield))
119 (should-error (thread-join thread))))
120
86(defvar threads-test-binding nil) 121(defvar threads-test-binding nil)
87 122
88(defun threads-test-thread2 () 123(defun threads-test-thread2 ()
@@ -92,7 +127,7 @@
92 127
93(ert-deftest threads-let-binding () 128(ert-deftest threads-let-binding ()
94 "Simple test of threads and let bindings." 129 "Simple test of threads and let bindings."
95 (skip-unless (fboundp 'make-thread)) 130 (skip-unless (featurep 'threads))
96 (should 131 (should
97 (progn 132 (progn
98 (setq threads-test-global nil) 133 (setq threads-test-global nil)
@@ -104,22 +139,22 @@
104 139
105(ert-deftest threads-mutexp () 140(ert-deftest threads-mutexp ()
106 "Simple test of `mutexp'." 141 "Simple test of `mutexp'."
107 (skip-unless (fboundp 'make-thread)) 142 (skip-unless (featurep 'threads))
108 (should-not (mutexp 'hi))) 143 (should-not (mutexp 'hi)))
109 144
110(ert-deftest threads-mutexp-2 () 145(ert-deftest threads-mutexp-2 ()
111 "Another simple test of `mutexp'." 146 "Another simple test of `mutexp'."
112 (skip-unless (fboundp 'make-thread)) 147 (skip-unless (featurep 'threads))
113 (should (mutexp (make-mutex)))) 148 (should (mutexp (make-mutex))))
114 149
115(ert-deftest threads-mutex-type () 150(ert-deftest threads-mutex-type ()
116 "type-of mutex." 151 "type-of mutex."
117 (skip-unless (fboundp 'make-thread)) 152 (skip-unless (featurep 'threads))
118 (should (eq (type-of (make-mutex)) 'mutex))) 153 (should (eq (type-of (make-mutex)) 'mutex)))
119 154
120(ert-deftest threads-mutex-lock-unlock () 155(ert-deftest threads-mutex-lock-unlock ()
121 "Test mutex-lock and unlock." 156 "Test mutex-lock and unlock."
122 (skip-unless (fboundp 'make-thread)) 157 (skip-unless (featurep 'threads))
123 (should 158 (should
124 (let ((mx (make-mutex))) 159 (let ((mx (make-mutex)))
125 (mutex-lock mx) 160 (mutex-lock mx)
@@ -128,7 +163,7 @@
128 163
129(ert-deftest threads-mutex-recursive () 164(ert-deftest threads-mutex-recursive ()
130 "Test mutex recursion." 165 "Test mutex recursion."
131 (skip-unless (fboundp 'make-thread)) 166 (skip-unless (featurep 'threads))
132 (should 167 (should
133 (let ((mx (make-mutex))) 168 (let ((mx (make-mutex)))
134 (mutex-lock mx) 169 (mutex-lock mx)
@@ -149,7 +184,7 @@
149 184
150(ert-deftest threads-mutex-contention () 185(ert-deftest threads-mutex-contention ()
151 "Test of mutex contention." 186 "Test of mutex contention."
152 (skip-unless (fboundp 'make-thread)) 187 (skip-unless (featurep 'threads))
153 (should 188 (should
154 (progn 189 (progn
155 (setq threads-mutex (make-mutex)) 190 (setq threads-mutex (make-mutex))
@@ -170,8 +205,8 @@
170 205
171(ert-deftest threads-mutex-signal () 206(ert-deftest threads-mutex-signal ()
172 "Test signaling a blocked thread." 207 "Test signaling a blocked thread."
173 (skip-unless (fboundp 'make-thread)) 208 (skip-unless (featurep 'threads))
174 (should 209 (should-error
175 (progn 210 (progn
176 (setq threads-mutex (make-mutex)) 211 (setq threads-mutex (make-mutex))
177 (setq threads-mutex-key nil) 212 (setq threads-mutex-key nil)
@@ -180,15 +215,17 @@
180 (while (not threads-mutex-key) 215 (while (not threads-mutex-key)
181 (thread-yield)) 216 (thread-yield))
182 (thread-signal thr 'quit nil) 217 (thread-signal thr 'quit nil)
183 (thread-join thr)) 218 ;; `quit' is not catched by `should-error'. We must indicate it.
184 t))) 219 (condition-case nil
220 (thread-join thr)
221 (quit (signal 'error nil)))))))
185 222
186(defun threads-test-io-switch () 223(defun threads-test-io-switch ()
187 (setq threads-test-global 23)) 224 (setq threads-test-global 23))
188 225
189(ert-deftest threads-io-switch () 226(ert-deftest threads-io-switch ()
190 "Test that `accept-process-output' causes thread switch." 227 "Test that `accept-process-output' causes thread switch."
191 (skip-unless (fboundp 'make-thread)) 228 (skip-unless (featurep 'threads))
192 (should 229 (should
193 (progn 230 (progn
194 (setq threads-test-global nil) 231 (setq threads-test-global nil)
@@ -199,67 +236,71 @@
199 236
200(ert-deftest threads-condvarp () 237(ert-deftest threads-condvarp ()
201 "Simple test of `condition-variable-p'." 238 "Simple test of `condition-variable-p'."
202 (skip-unless (fboundp 'make-thread)) 239 (skip-unless (featurep 'threads))
203 (should-not (condition-variable-p 'hi))) 240 (should-not (condition-variable-p 'hi)))
204 241
205(ert-deftest threads-condvarp-2 () 242(ert-deftest threads-condvarp-2 ()
206 "Another simple test of `condition-variable-p'." 243 "Another simple test of `condition-variable-p'."
207 (skip-unless (fboundp 'make-thread)) 244 (skip-unless (featurep 'threads))
208 (should (condition-variable-p (make-condition-variable (make-mutex))))) 245 (should (condition-variable-p (make-condition-variable (make-mutex)))))
209 246
210(ert-deftest threads-condvar-type () 247(ert-deftest threads-condvar-type ()
211 "type-of condvar" 248 "type-of condvar"
212 (skip-unless (fboundp 'make-thread)) 249 (skip-unless (featurep 'threads))
213 (should (eq (type-of (make-condition-variable (make-mutex))) 250 (should (eq (type-of (make-condition-variable (make-mutex)))
214 'condition-variable))) 251 'condition-variable)))
215 252
216(ert-deftest threads-condvar-mutex () 253(ert-deftest threads-condvar-mutex ()
217 "Simple test of `condition-mutex'." 254 "Simple test of `condition-mutex'."
218 (skip-unless (fboundp 'make-thread)) 255 (skip-unless (featurep 'threads))
219 (should 256 (should
220 (let ((m (make-mutex))) 257 (let ((m (make-mutex)))
221 (eq m (condition-mutex (make-condition-variable m)))))) 258 (eq m (condition-mutex (make-condition-variable m))))))
222 259
223(ert-deftest threads-condvar-name () 260(ert-deftest threads-condvar-name ()
224 "Simple test of `condition-name'." 261 "Simple test of `condition-name'."
225 (skip-unless (fboundp 'make-thread)) 262 (skip-unless (featurep 'threads))
226 (should 263 (should
227 (eq nil (condition-name (make-condition-variable (make-mutex)))))) 264 (eq nil (condition-name (make-condition-variable (make-mutex))))))
228 265
229(ert-deftest threads-condvar-name-2 () 266(ert-deftest threads-condvar-name-2 ()
230 "Another simple test of `condition-name'." 267 "Another simple test of `condition-name'."
231 (skip-unless (fboundp 'make-thread)) 268 (skip-unless (featurep 'threads))
232 (should 269 (should
233 (string= "hi bob" 270 (string= "hi bob"
234 (condition-name (make-condition-variable (make-mutex) 271 (condition-name (make-condition-variable (make-mutex)
235 "hi bob"))))) 272 "hi bob")))))
236(defun call-error () 273
274(defun threads-call-error ()
237 "Call `error'." 275 "Call `error'."
238 (error "Error is called")) 276 (error "Error is called"))
239 277
240;; This signals an error internally; the error should be caught. 278;; This signals an error internally; the error should be caught.
241(defun thread-custom () 279(defun threads-custom ()
242 (defcustom thread-custom-face 'highlight 280 (defcustom threads-custom-face 'highlight
243 "Face used for thread customizations." 281 "Face used for thread customizations."
244 :type 'face 282 :type 'face
245 :group 'widget-faces)) 283 :group 'widget-faces))
246 284
247(ert-deftest thread-errors () 285(ert-deftest threads-errors ()
248 "Test what happens when a thread signals an error." 286 "Test what happens when a thread signals an error."
249 (skip-unless (fboundp 'make-thread)) 287 (skip-unless (featurep 'threads))
250 (let (th1 th2) 288 (let (th1 th2)
251 (setq th1 (make-thread #'call-error "call-error")) 289 (setq th1 (make-thread #'threads-call-error "call-error"))
252 (should (threadp th1)) 290 (should (threadp th1))
253 (while (thread-alive-p th1) 291 (while (thread-alive-p th1)
254 (thread-yield)) 292 (thread-yield))
255 (should (equal (thread-last-error) 293 (should (equal (thread-last-error)
256 '(error "Error is called"))) 294 '(error "Error is called")))
257 (setq th2 (make-thread #'thread-custom "thread-custom")) 295 (should (equal (thread-last-error 'cleanup)
296 '(error "Error is called")))
297 (should-not (thread-last-error))
298 (setq th2 (make-thread #'threads-custom "threads-custom"))
258 (should (threadp th2)))) 299 (should (threadp th2))))
259 300
260(ert-deftest thread-sticky-point () 301(ert-deftest threads-sticky-point ()
261 "Test bug #25165 with point movement in cloned buffer." 302 "Test bug #25165 with point movement in cloned buffer."
262 (skip-unless (fboundp 'make-thread)) 303 (skip-unless (featurep 'threads))
263 (with-temp-buffer 304 (with-temp-buffer
264 (insert "Lorem ipsum dolor sit amet, consectetur adipiscing elit.") 305 (insert "Lorem ipsum dolor sit amet, consectetur adipiscing elit.")
265 (goto-char (point-min)) 306 (goto-char (point-min))
@@ -268,9 +309,9 @@
268 (sit-for 1) 309 (sit-for 1)
269 (should (= (point) 21)))) 310 (should (= (point) 21))))
270 311
271(ert-deftest thread-signal-early () 312(ert-deftest threads-signal-early ()
272 "Test signaling a thread as soon as it is started by the OS." 313 "Test signaling a thread as soon as it is started by the OS."
273 (skip-unless (fboundp 'make-thread)) 314 (skip-unless (featurep 'threads))
274 (let ((thread 315 (let ((thread
275 (make-thread #'(lambda () 316 (make-thread #'(lambda ()
276 (while t (thread-yield)))))) 317 (while t (thread-yield))))))
@@ -291,7 +332,7 @@
291 332
292(ert-deftest threads-condvar-wait () 333(ert-deftest threads-condvar-wait ()
293 "Test waiting on conditional variable." 334 "Test waiting on conditional variable."
294 (skip-unless (fboundp 'make-thread)) 335 (skip-unless (featurep 'threads))
295 (let ((cv-mutex (make-mutex)) 336 (let ((cv-mutex (make-mutex))
296 new-thread) 337 new-thread)
297 ;; We could have spurious threads from the previous tests still 338 ;; We could have spurious threads from the previous tests still