1 ;;; ert-tests.el --- ERT's self-tests -*- lexical-binding: t -*-
3 ;; Copyright (C) 2007-2008, 2010-2013 Free Software Foundation, Inc.
5 ;; Author: Christian Ohler <ohler@gnu.org>
7 ;; This file is part of GNU Emacs.
9 ;; This program is free software: you can redistribute it and/or
10 ;; modify it under the terms of the GNU General Public License as
11 ;; published by the Free Software Foundation, either version 3 of the
12 ;; License, or (at your option) any later version.
14 ;; This program is distributed in the hope that it will be useful, but
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 ;; General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with this program. If not, see `http://www.gnu.org/licenses/'.
24 ;; This file is part of ERT, the Emacs Lisp Regression Testing tool.
25 ;; See ert.el or the texinfo manual for more details.
32 ;;; Self-test that doesn't rely on ERT, for bootstrapping.
34 ;; This is used to test that bodies actually run.
35 (defvar ert--test-body-was-run
)
36 (ert-deftest ert-test-body-runs
()
37 (setq ert--test-body-was-run t
))
39 (defun ert-self-test ()
40 "Run ERT's self-tests and make sure they actually ran."
41 (let ((window-configuration (current-window-configuration)))
42 (let ((ert--test-body-was-run nil
))
43 ;; The buffer name chosen here should not compete with the default
44 ;; results buffer name for completion in `switch-to-buffer'.
45 (let ((stats (ert-run-tests-interactively "^ert-" " *ert self-tests*")))
46 (cl-assert ert--test-body-was-run
)
47 (if (zerop (ert-stats-completed-unexpected stats
))
48 ;; Hide results window only when everything went well.
49 (set-window-configuration window-configuration
)
50 (error "ERT self-test failed"))))))
52 (defun ert-self-test-and-exit ()
53 "Run ERT's self-tests and exit Emacs.
55 The exit code will be zero if the tests passed, nonzero if they
56 failed or if there was a problem."
63 (message "Error running tests")
68 ;;; Further tests are defined using ERT.
70 (ert-deftest ert-test-nested-test-body-runs
()
71 "Test that nested test bodies run."
73 (let ((test (make-ert-test :body
(lambda ()
75 (cl-assert (not was-run
))
77 (cl-assert was-run
))))
80 ;;; Test that pass/fail works.
81 (ert-deftest ert-test-pass
()
82 (let ((test (make-ert-test :body
(lambda ()))))
83 (let ((result (ert-run-test test
)))
84 (cl-assert (ert-test-passed-p result
)))))
86 (ert-deftest ert-test-fail
()
87 (let ((test (make-ert-test :body
(lambda () (ert-fail "failure message")))))
88 (let ((result (let ((ert-debug-on-error nil
))
89 (ert-run-test test
))))
90 (cl-assert (ert-test-failed-p result
) t
)
91 (cl-assert (equal (ert-test-result-with-condition-condition result
)
92 '(ert-test-failed "failure message"))
95 (ert-deftest ert-test-fail-debug-with-condition-case
()
96 (let ((test (make-ert-test :body
(lambda () (ert-fail "failure message")))))
97 (condition-case condition
99 (let ((ert-debug-on-error t
))
103 (cl-assert (equal condition
'(ert-test-failed "failure message")) t
)))))
105 (ert-deftest ert-test-fail-debug-with-debugger-1
()
106 (let ((test (make-ert-test :body
(lambda () (ert-fail "failure message")))))
107 (let ((debugger (lambda (&rest _args
)
109 (let ((ert-debug-on-error nil
))
110 (ert-run-test test
)))))
112 (ert-deftest ert-test-fail-debug-with-debugger-2
()
113 (let ((test (make-ert-test :body
(lambda () (ert-fail "failure message")))))
115 (let ((debugger (lambda (&rest _args
)
116 (cl-return-from nil nil
))))
117 (let ((ert-debug-on-error t
))
121 (ert-deftest ert-test-fail-debug-nested-with-debugger
()
122 (let ((test (make-ert-test :body
(lambda ()
123 (let ((ert-debug-on-error t
))
124 (ert-fail "failure message"))))))
125 (let ((debugger (lambda (&rest _args
)
126 (cl-assert nil nil
"Assertion a"))))
127 (let ((ert-debug-on-error nil
))
128 (ert-run-test test
))))
129 (let ((test (make-ert-test :body
(lambda ()
130 (let ((ert-debug-on-error nil
))
131 (ert-fail "failure message"))))))
133 (let ((debugger (lambda (&rest _args
)
134 (cl-return-from nil nil
))))
135 (let ((ert-debug-on-error t
))
137 (cl-assert nil nil
"Assertion b")))))
139 (ert-deftest ert-test-error
()
140 (let ((test (make-ert-test :body
(lambda () (error "Error message")))))
141 (let ((result (let ((ert-debug-on-error nil
))
142 (ert-run-test test
))))
143 (cl-assert (ert-test-failed-p result
) t
)
144 (cl-assert (equal (ert-test-result-with-condition-condition result
)
145 '(error "Error message"))
148 (ert-deftest ert-test-error-debug
()
149 (let ((test (make-ert-test :body
(lambda () (error "Error message")))))
150 (condition-case condition
152 (let ((ert-debug-on-error t
))
156 (cl-assert (equal condition
'(error "Error message")) t
)))))
159 ;;; Test that `should' works.
160 (ert-deftest ert-test-should
()
161 (let ((test (make-ert-test :body
(lambda () (should nil
)))))
162 (let ((result (let ((ert-debug-on-error nil
))
163 (ert-run-test test
))))
164 (cl-assert (ert-test-failed-p result
) t
)
165 (cl-assert (equal (ert-test-result-with-condition-condition result
)
166 '(ert-test-failed ((should nil
) :form nil
:value nil
)))
168 (let ((test (make-ert-test :body
(lambda () (should t
)))))
169 (let ((result (ert-run-test test
)))
170 (cl-assert (ert-test-passed-p result
) t
))))
172 (ert-deftest ert-test-should-value
()
173 (should (eql (should 'foo
) 'foo
))
174 (should (eql (should 'bar
) 'bar
)))
176 (ert-deftest ert-test-should-not
()
177 (let ((test (make-ert-test :body
(lambda () (should-not t
)))))
178 (let ((result (let ((ert-debug-on-error nil
))
179 (ert-run-test test
))))
180 (cl-assert (ert-test-failed-p result
) t
)
181 (cl-assert (equal (ert-test-result-with-condition-condition result
)
182 '(ert-test-failed ((should-not t
) :form t
:value t
)))
184 (let ((test (make-ert-test :body
(lambda () (should-not nil
)))))
185 (let ((result (ert-run-test test
)))
186 (cl-assert (ert-test-passed-p result
)))))
189 (ert-deftest ert-test-should-with-macrolet
()
190 (let ((test (make-ert-test :body
(lambda ()
191 (cl-macrolet ((foo () `(progn t nil
)))
193 (let ((result (let ((ert-debug-on-error nil
))
194 (ert-run-test test
))))
195 (should (ert-test-failed-p result
))
197 (ert-test-result-with-condition-condition result
)
198 '(ert-test-failed ((should (foo))
202 (ert-deftest ert-test-should-error
()
204 (let ((test (make-ert-test :body
(lambda () (should-error (progn))))))
205 (let ((result (let ((ert-debug-on-error nil
))
206 (ert-run-test test
))))
207 (should (ert-test-failed-p result
))
208 (should (equal (ert-test-result-with-condition-condition result
)
210 ((should-error (progn))
213 :fail-reason
"did not signal an error"))))))
215 (should (equal (should-error (error "Foo"))
217 ;; Error of unexpected type.
218 (let ((test (make-ert-test :body
(lambda ()
219 (should-error (error "Foo")
220 :type
'singularity-error
)))))
221 (let ((result (ert-run-test test
)))
222 (should (ert-test-failed-p result
))
224 (ert-test-result-with-condition-condition result
)
226 ((should-error (error "Foo") :type
'singularity-error
)
228 :condition
(error "Foo")
230 "the error signaled did not have the expected type"))))))
231 ;; Error of the expected type.
236 (should-error (signal 'singularity-error nil
)
237 :type
'singularity-error
))))))
238 (let ((result (ert-run-test test
)))
239 (should (ert-test-passed-p result
))
240 (should (equal error
'(singularity-error))))))
242 (ert-deftest ert-test-should-error-subtypes
()
243 (should-error (signal 'singularity-error nil
)
244 :type
'singularity-error
246 (let ((test (make-ert-test
248 (should-error (signal 'arith-error nil
)
249 :type
'singularity-error
)))))
250 (let ((result (ert-run-test test
)))
251 (should (ert-test-failed-p result
))
253 (ert-test-result-with-condition-condition result
)
255 ((should-error (signal 'arith-error nil
)
256 :type
'singularity-error
)
257 :form
(signal arith-error nil
)
258 :condition
(arith-error)
260 "the error signaled did not have the expected type"))))))
261 (let ((test (make-ert-test
263 (should-error (signal 'arith-error nil
)
264 :type
'singularity-error
265 :exclude-subtypes t
)))))
266 (let ((result (ert-run-test test
)))
267 (should (ert-test-failed-p result
))
269 (ert-test-result-with-condition-condition result
)
271 ((should-error (signal 'arith-error nil
)
272 :type
'singularity-error
274 :form
(signal arith-error nil
)
275 :condition
(arith-error)
277 "the error signaled did not have the expected type"))))))
278 (let ((test (make-ert-test
280 (should-error (signal 'singularity-error nil
)
282 :exclude-subtypes t
)))))
283 (let ((result (ert-run-test test
)))
284 (should (ert-test-failed-p result
))
286 (ert-test-result-with-condition-condition result
)
288 ((should-error (signal 'singularity-error nil
)
291 :form
(signal singularity-error nil
)
292 :condition
(singularity-error)
294 "the error signaled was a subtype of the expected type")))))
297 (defmacro ert--test-my-list
(&rest args
)
298 "Don't use this. Instead, call `list' with ARGS, it does the same thing.
300 This macro is used to test if macroexpansion in `should' works."
303 (ert-deftest ert-test-should-failure-debugging
()
304 "Test that `should' errors contain the information we expect them to."
306 for
(body expected-condition
) in
307 `((,(lambda () (let ((x nil
)) (should x
)))
308 (ert-test-failed ((should x
) :form x
:value nil
)))
309 (,(lambda () (let ((x t
)) (should-not x
)))
310 (ert-test-failed ((should-not x
) :form x
:value t
)))
311 (,(lambda () (let ((x t
)) (should (not x
))))
312 (ert-test-failed ((should (not x
)) :form
(not t
) :value nil
)))
313 (,(lambda () (let ((x nil
)) (should-not (not x
))))
314 (ert-test-failed ((should-not (not x
)) :form
(not nil
) :value t
)))
315 (,(lambda () (let ((x t
) (y nil
)) (should-not
316 (ert--test-my-list x y
))))
318 ((should-not (ert--test-my-list x y
))
321 (,(lambda () (let ((_x t
)) (should (error "Foo"))))
324 (let ((test (make-ert-test :body body
)))
325 (condition-case actual-condition
327 (let ((ert-debug-on-error t
))
331 (should (equal actual-condition expected-condition
)))))))
333 (ert-deftest ert-test-deftest
()
334 (should (equal (macroexpand '(ert-deftest abc
() "foo" :tags
'(bar)))
337 (make-ert-test :name
'abc
341 (push '(ert-deftest . abc
) current-load-list
)
343 (should (equal (macroexpand '(ert-deftest def
()
344 :expected-result
':passed
))
347 (make-ert-test :name
'def
348 :expected-result-type
':passed
350 (push '(ert-deftest . def
) current-load-list
)
352 ;; :documentation keyword is forbidden
353 (should-error (macroexpand '(ert-deftest ghi
()
354 :documentation
"foo"))))
356 ;; FIXME Test disabled due to persistent failure owing to lexical binding.
357 ;; http://debbugs.gnu.org/13064
358 ;;; (ert-deftest ert-test-record-backtrace ()
359 ;;; (let ((test (make-ert-test :body (lambda () (ert-fail "foo")))))
360 ;;; (let ((result (ert-run-test test)))
361 ;;; (should (ert-test-failed-p result))
362 ;;; (with-temp-buffer
363 ;;; (ert--print-backtrace (ert-test-failed-backtrace result))
364 ;;; (goto-char (point-min))
366 ;;; (let ((first-line (buffer-substring-no-properties (point-min) (point))))
367 ;;; (should (equal first-line " signal(ert-test-failed (\"foo\"))")))))))
369 (ert-deftest ert-test-messages
()
370 :tags
'(:causes-redisplay
)
371 (let* ((message-string "Test message")
372 (messages-buffer (get-buffer-create "*Messages*"))
373 (test (make-ert-test :body
(lambda () (message "%s" message-string
)))))
374 (with-current-buffer messages-buffer
375 (let ((result (ert-run-test test
)))
376 (should (equal (concat message-string
"\n")
377 (ert-test-result-messages result
)))))))
379 (ert-deftest ert-test-running-tests
()
380 (let ((outer-test (ert-get-test 'ert-test-running-tests
)))
381 (should (equal (ert-running-test) outer-test
))
382 (let (test1 test2 test3
)
383 (setq test1
(make-ert-test
386 (should (equal (ert-running-test) outer-test
))
387 (should (equal ert--running-tests
388 (list test1 test2 test3
393 (should (equal (ert-running-test) outer-test
))
394 (should (equal ert--running-tests
395 (list test3 test2 outer-test
)))
396 (ert-run-test test1
)))
400 (should (equal (ert-running-test) outer-test
))
401 (should (equal ert--running-tests
402 (list test3 outer-test
)))
403 (ert-run-test test2
))))
404 (should (ert-test-passed-p (ert-run-test test3
))))))
406 (ert-deftest ert-test-test-result-expected-p
()
407 "Test `ert-test-result-expected-p' and (implicitly) `ert-test-result-type-p'."
409 (let ((test (make-ert-test :body
(lambda ()))))
410 (should (ert-test-result-expected-p test
(ert-run-test test
))))
411 ;; unexpected failure
412 (let ((test (make-ert-test :body
(lambda () (ert-fail "failed")))))
413 (should-not (ert-test-result-expected-p test
(ert-run-test test
))))
415 (let ((test (make-ert-test :body
(lambda () (ert-fail "failed"))
416 :expected-result-type
':failed
)))
417 (should (ert-test-result-expected-p test
(ert-run-test test
))))
418 ;; `not' expected type
419 (let ((test (make-ert-test :body
(lambda ())
420 :expected-result-type
'(not :failed
))))
421 (should (ert-test-result-expected-p test
(ert-run-test test
))))
422 (let ((test (make-ert-test :body
(lambda ())
423 :expected-result-type
'(not :passed
))))
424 (should-not (ert-test-result-expected-p test
(ert-run-test test
))))
425 ;; `and' expected type
426 (let ((test (make-ert-test :body
(lambda ())
427 :expected-result-type
'(and :passed
:failed
))))
428 (should-not (ert-test-result-expected-p test
(ert-run-test test
))))
429 (let ((test (make-ert-test :body
(lambda ())
430 :expected-result-type
'(and :passed
432 (should (ert-test-result-expected-p test
(ert-run-test test
))))
433 ;; `or' expected type
434 (let ((test (make-ert-test :body
(lambda ())
435 :expected-result-type
'(or (and :passed
:failed
)
437 (should (ert-test-result-expected-p test
(ert-run-test test
))))
438 (let ((test (make-ert-test :body
(lambda ())
439 :expected-result-type
'(or (and :passed
:failed
)
441 (should-not (ert-test-result-expected-p test
(ert-run-test test
)))))
443 ;;; Test `ert-select-tests'.
444 (ert-deftest ert-test-select-regexp
()
445 (should (equal (ert-select-tests "^ert-test-select-regexp$" t
)
446 (list (ert-get-test 'ert-test-select-regexp
)))))
448 (ert-deftest ert-test-test-boundp
()
449 (should (ert-test-boundp 'ert-test-test-boundp
))
450 (should-not (ert-test-boundp (make-symbol "ert-not-a-test"))))
452 (ert-deftest ert-test-select-member
()
453 (should (equal (ert-select-tests '(member ert-test-select-member
) t
)
454 (list (ert-get-test 'ert-test-select-member
)))))
456 (ert-deftest ert-test-select-test
()
457 (should (equal (ert-select-tests (ert-get-test 'ert-test-select-test
) t
)
458 (list (ert-get-test 'ert-test-select-test
)))))
460 (ert-deftest ert-test-select-symbol
()
461 (should (equal (ert-select-tests 'ert-test-select-symbol t
)
462 (list (ert-get-test 'ert-test-select-symbol
)))))
464 (ert-deftest ert-test-select-and
()
465 (let ((test (make-ert-test
468 :most-recent-result
(make-ert-test-failed
472 (should (equal (ert-select-tests `(and (member ,test
) :failed
) t
)
475 (ert-deftest ert-test-select-tag
()
476 (let ((test (make-ert-test
480 (should (equal (ert-select-tests `(tag a
) (list test
)) (list test
)))
481 (should (equal (ert-select-tests `(tag b
) (list test
)) (list test
)))
482 (should (equal (ert-select-tests `(tag c
) (list test
)) '()))))
485 ;;; Tests for utility functions.
486 (ert-deftest ert-test-proper-list-p
()
487 (should (ert--proper-list-p '()))
488 (should (ert--proper-list-p '(1)))
489 (should (ert--proper-list-p '(1 2)))
490 (should (ert--proper-list-p '(1 2 3)))
491 (should (ert--proper-list-p '(1 2 3 4)))
492 (should (not (ert--proper-list-p 'a
)))
493 (should (not (ert--proper-list-p '(1 . a
))))
494 (should (not (ert--proper-list-p '(1 2 . a
))))
495 (should (not (ert--proper-list-p '(1 2 3 . a
))))
496 (should (not (ert--proper-list-p '(1 2 3 4 . a
))))
498 (setf (cdr (last a
)) a
)
499 (should (not (ert--proper-list-p a
))))
500 (let ((a (list 1 2)))
501 (setf (cdr (last a
)) a
)
502 (should (not (ert--proper-list-p a
))))
503 (let ((a (list 1 2 3)))
504 (setf (cdr (last a
)) a
)
505 (should (not (ert--proper-list-p a
))))
506 (let ((a (list 1 2 3 4)))
507 (setf (cdr (last a
)) a
)
508 (should (not (ert--proper-list-p a
))))
509 (let ((a (list 1 2)))
510 (setf (cdr (last a
)) (cdr a
))
511 (should (not (ert--proper-list-p a
))))
512 (let ((a (list 1 2 3)))
513 (setf (cdr (last a
)) (cdr a
))
514 (should (not (ert--proper-list-p a
))))
515 (let ((a (list 1 2 3 4)))
516 (setf (cdr (last a
)) (cdr a
))
517 (should (not (ert--proper-list-p a
))))
518 (let ((a (list 1 2 3)))
519 (setf (cdr (last a
)) (cddr a
))
520 (should (not (ert--proper-list-p a
))))
521 (let ((a (list 1 2 3 4)))
522 (setf (cdr (last a
)) (cddr a
))
523 (should (not (ert--proper-list-p a
))))
524 (let ((a (list 1 2 3 4)))
525 (setf (cdr (last a
)) (cl-cdddr a
))
526 (should (not (ert--proper-list-p a
)))))
528 (ert-deftest ert-test-parse-keys-and-body
()
529 (should (equal (ert--parse-keys-and-body '(foo)) '(nil (foo))))
530 (should (equal (ert--parse-keys-and-body '(:bar foo
)) '((:bar foo
) nil
)))
531 (should (equal (ert--parse-keys-and-body '(:bar foo a
(b)))
532 '((:bar foo
) (a (b)))))
533 (should (equal (ert--parse-keys-and-body '(:bar foo
:a
(b)))
534 '((:bar foo
:a
(b)) nil
)))
535 (should (equal (ert--parse-keys-and-body '(bar foo
:a
(b)))
536 '(nil (bar foo
:a
(b)))))
537 (should-error (ert--parse-keys-and-body '(:bar foo
:a
))))
540 (ert-deftest ert-test-run-tests-interactively
()
541 :tags
'(:causes-redisplay
)
542 (let ((passing-test (make-ert-test :name
'passing-test
543 :body
(lambda () (ert-pass))))
544 (failing-test (make-ert-test :name
'failing-test
545 :body
(lambda () (ert-fail
546 "failure message")))))
547 (let ((ert-debug-on-error nil
))
548 (let* ((buffer-name (generate-new-buffer-name " *ert-test-run-tests*"))
551 (lambda (format-string &rest args
)
552 (push (apply #'format format-string args
) messages
))))
553 (save-window-excursion
555 (let ((case-fold-search nil
))
556 (ert-run-tests-interactively
557 `(member ,passing-test
,failing-test
) buffer-name
559 (should (equal messages
`(,(concat
560 "Ran 2 tests, 1 results were "
561 "as expected, 1 unexpected"))))
562 (with-current-buffer buffer-name
563 (goto-char (point-min))
565 (buffer-substring (point-min)
570 "Selector: (member <passing-test> <failing-test>)\n"
572 "Failed: 1 (1 unexpected)\n"
574 (when (get-buffer buffer-name
)
575 (kill-buffer buffer-name
))))))))
577 (ert-deftest ert-test-special-operator-p
()
578 (should (ert--special-operator-p 'if
))
579 (should-not (ert--special-operator-p 'car
))
580 (should-not (ert--special-operator-p 'ert--special-operator-p
))
581 (let ((b (cl-gensym)))
582 (should-not (ert--special-operator-p b
))
584 (should (ert--special-operator-p b
))))
586 (ert-deftest ert-test-list-of-should-forms
()
587 (let ((test (make-ert-test :body
(lambda ()
592 (let ((result (let ((ert-debug-on-error nil
))
593 (ert-run-test test
))))
594 (should (equal (ert-test-result-should-forms result
)
595 '(((should t
) :form t
:value t
)
596 ((should (null '())) :form
(null nil
) :value t
)
597 ((should nil
) :form nil
:value nil
)))))))
599 (ert-deftest ert-test-list-of-should-forms-observers-should-not-stack
()
600 (let ((test (make-ert-test
602 (let ((test2 (make-ert-test
605 (let ((result (ert-run-test test2
)))
606 (should (ert-test-passed-p result
))))))))
607 (let ((result (let ((ert-debug-on-error nil
))
608 (ert-run-test test
))))
609 (should (ert-test-passed-p result
))
610 (should (eql (length (ert-test-result-should-forms result
))
613 (ert-deftest ert-test-list-of-should-forms-no-deep-copy
()
614 (let ((test (make-ert-test :body
(lambda ()
615 (let ((obj (list 'a
)))
616 (should (equal obj
'(a)))
618 (should (equal obj
'(b))))))))
619 (let ((result (let ((ert-debug-on-error nil
))
620 (ert-run-test test
))))
621 (should (ert-test-passed-p result
))
622 (should (equal (ert-test-result-should-forms result
)
623 '(((should (equal obj
'(a))) :form
(equal (b) (a)) :value t
625 ((should (equal obj
'(b))) :form
(equal (b) (b)) :value t
629 (ert-deftest ert-test-string-first-line
()
630 (should (equal (ert--string-first-line "") ""))
631 (should (equal (ert--string-first-line "abc") "abc"))
632 (should (equal (ert--string-first-line "abc\n") "abc"))
633 (should (equal (ert--string-first-line "foo\nbar") "foo"))
634 (should (equal (ert--string-first-line " foo\nbar\nbaz\n") " foo")))
636 (ert-deftest ert-test-explain-equal
()
637 (should (equal (ert--explain-equal nil
'foo
)
638 '(different-atoms nil foo
)))
639 (should (equal (ert--explain-equal '(a a
) '(a b
))
640 '(list-elt 1 (different-atoms a b
))))
641 (should (equal (ert--explain-equal '(1 48) '(1 49))
642 '(list-elt 1 (different-atoms (48 "#x30" "?0")
644 (should (equal (ert--explain-equal 'nil
'(a))
645 '(different-types nil
(a))))
646 (should (equal (ert--explain-equal '(a b c
) '(a b c d
))
647 '(proper-lists-of-different-length 3 4 (a b c
) (a b c d
)
648 first-mismatch-at
3)))
649 (let ((sym (make-symbol "a")))
650 (should (equal (ert--explain-equal 'a sym
)
651 `(different-symbols-with-the-same-name a
,sym
)))))
653 (ert-deftest ert-test-explain-equal-improper-list
()
654 (should (equal (ert--explain-equal '(a . b
) '(a . c
))
655 '(cdr (different-atoms b c
)))))
657 (ert-deftest ert-test-explain-equal-keymaps
()
658 ;; This used to be very slow.
659 (should (equal (make-keymap) (make-keymap)))
660 (should (equal (make-sparse-keymap) (make-sparse-keymap))))
662 (ert-deftest ert-test-significant-plist-keys
()
663 (should (equal (ert--significant-plist-keys '()) '()))
664 (should (equal (ert--significant-plist-keys '(a b c d e f c g p q r nil s t
))
667 (ert-deftest ert-test-plist-difference-explanation
()
668 (should (equal (ert--plist-difference-explanation
671 (should (equal (ert--plist-difference-explanation
673 '(different-properties-for-key c
(different-atoms t nil
))))
674 (should (equal (ert--plist-difference-explanation
675 '(a b c t
) '(c nil a b
))
676 '(different-properties-for-key c
(different-atoms t nil
))))
677 (should (equal (ert--plist-difference-explanation
678 '(a b c
(foo . bar
)) '(c (foo . baz
) a b
))
679 '(different-properties-for-key c
681 (different-atoms bar baz
))))))
683 (ert-deftest ert-test-abbreviate-string
()
684 (should (equal (ert--abbreviate-string "foo" 4 nil
) "foo"))
685 (should (equal (ert--abbreviate-string "foo" 3 nil
) "foo"))
686 (should (equal (ert--abbreviate-string "foo" 3 nil
) "foo"))
687 (should (equal (ert--abbreviate-string "foo" 2 nil
) "fo"))
688 (should (equal (ert--abbreviate-string "foo" 1 nil
) "f"))
689 (should (equal (ert--abbreviate-string "foo" 0 nil
) ""))
690 (should (equal (ert--abbreviate-string "bar" 4 t
) "bar"))
691 (should (equal (ert--abbreviate-string "bar" 3 t
) "bar"))
692 (should (equal (ert--abbreviate-string "bar" 3 t
) "bar"))
693 (should (equal (ert--abbreviate-string "bar" 2 t
) "ar"))
694 (should (equal (ert--abbreviate-string "bar" 1 t
) "r"))
695 (should (equal (ert--abbreviate-string "bar" 0 t
) "")))
697 (ert-deftest ert-test-explain-equal-string-properties
()
699 (equal (ert--explain-equal-including-properties #("foo" 0 1 (a b
))
702 (different-properties-for-key a
(different-atoms b nil
))
704 context-after
"oo")))
705 (should (equal (ert--explain-equal-including-properties
708 '(array-elt 0 (different-atoms (?f
"#x66" "?f")
711 (equal (ert--explain-equal-including-properties
712 #("foo" 0 1 (a b c d
) 1 3 (a b
))
713 #("foo" 0 1 (c d a b
) 1 2 (a foo
)))
714 '(char 1 "o" (different-properties-for-key a
(different-atoms b foo
))
715 context-before
"f" context-after
"o"))))
717 (ert-deftest ert-test-equal-including-properties
()
718 (should (equal-including-properties "foo" "foo"))
719 (should (ert-equal-including-properties "foo" "foo"))
721 (should (equal-including-properties #("foo" 0 3 (a b
))
722 (propertize "foo" 'a
'b
)))
723 (should (ert-equal-including-properties #("foo" 0 3 (a b
))
724 (propertize "foo" 'a
'b
)))
726 (should (equal-including-properties #("foo" 0 3 (a b c d
))
727 (propertize "foo" 'a
'b
'c
'd
)))
728 (should (ert-equal-including-properties #("foo" 0 3 (a b c d
))
729 (propertize "foo" 'a
'b
'c
'd
)))
731 (should-not (equal-including-properties #("foo" 0 3 (a b c e
))
732 (propertize "foo" 'a
'b
'c
'd
)))
733 (should-not (ert-equal-including-properties #("foo" 0 3 (a b c e
))
734 (propertize "foo" 'a
'b
'c
'd
)))
737 (should-not (equal-including-properties #("foo" 0 3 (a (t)))
738 (propertize "foo" 'a
(list t
))))
739 (should (ert-equal-including-properties #("foo" 0 3 (a (t)))
740 (propertize "foo" 'a
(list t
)))))
742 (ert-deftest ert-test-stats-set-test-and-result
()
743 (let* ((test-1 (make-ert-test :name
'test-1
744 :body
(lambda () nil
)))
745 (test-2 (make-ert-test :name
'test-2
746 :body
(lambda () nil
)))
747 (test-3 (make-ert-test :name
'test-2
748 :body
(lambda () nil
)))
749 (stats (ert--make-stats (list test-1 test-2
) 't
))
750 (failed (make-ert-test-failed :condition nil
753 (should (eql 2 (ert-stats-total stats
)))
754 (should (eql 0 (ert-stats-completed stats
)))
755 (should (eql 0 (ert-stats-completed-expected stats
)))
756 (should (eql 0 (ert-stats-completed-unexpected stats
)))
757 (ert--stats-set-test-and-result stats
0 test-1
(make-ert-test-passed))
758 (should (eql 2 (ert-stats-total stats
)))
759 (should (eql 1 (ert-stats-completed stats
)))
760 (should (eql 1 (ert-stats-completed-expected stats
)))
761 (should (eql 0 (ert-stats-completed-unexpected stats
)))
762 (ert--stats-set-test-and-result stats
0 test-1 failed
)
763 (should (eql 2 (ert-stats-total stats
)))
764 (should (eql 1 (ert-stats-completed stats
)))
765 (should (eql 0 (ert-stats-completed-expected stats
)))
766 (should (eql 1 (ert-stats-completed-unexpected stats
)))
767 (ert--stats-set-test-and-result stats
0 test-1 nil
)
768 (should (eql 2 (ert-stats-total stats
)))
769 (should (eql 0 (ert-stats-completed stats
)))
770 (should (eql 0 (ert-stats-completed-expected stats
)))
771 (should (eql 0 (ert-stats-completed-unexpected stats
)))
772 (ert--stats-set-test-and-result stats
0 test-3 failed
)
773 (should (eql 2 (ert-stats-total stats
)))
774 (should (eql 1 (ert-stats-completed stats
)))
775 (should (eql 0 (ert-stats-completed-expected stats
)))
776 (should (eql 1 (ert-stats-completed-unexpected stats
)))
777 (ert--stats-set-test-and-result stats
1 test-2
(make-ert-test-passed))
778 (should (eql 2 (ert-stats-total stats
)))
779 (should (eql 2 (ert-stats-completed stats
)))
780 (should (eql 1 (ert-stats-completed-expected stats
)))
781 (should (eql 1 (ert-stats-completed-unexpected stats
)))
782 (ert--stats-set-test-and-result stats
0 test-1
(make-ert-test-passed))
783 (should (eql 2 (ert-stats-total stats
)))
784 (should (eql 2 (ert-stats-completed stats
)))
785 (should (eql 2 (ert-stats-completed-expected stats
)))
786 (should (eql 0 (ert-stats-completed-unexpected stats
)))))
791 ;;; ert-tests.el ends here