1 ;;; ert-tests.el --- ERT's self-tests -*- lexical-binding: t -*-
3 ;; Copyright (C) 2007-2008, 2010-2018 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 `https://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 (ert-deftest ert-test-should-error-argument
()
298 "Errors due to evaluating arguments should not break tests."
299 (should-error (identity (/ 1 0))))
301 (ert-deftest ert-test-should-error-macroexpansion
()
302 "Errors due to expanding macros should not break tests."
303 (cl-macrolet ((test () (error "Foo")))
304 (should-error (test))))
306 (ert-deftest ert-test-skip-unless
()
308 (let ((test (make-ert-test :body
(lambda () (skip-unless t
)))))
309 (let ((result (ert-run-test test
)))
310 (should (ert-test-passed-p result
))))
312 (let ((test (make-ert-test :body
(lambda () (skip-unless nil
)))))
313 (let ((result (ert-run-test test
)))
314 (should (ert-test-skipped-p result
))))
315 ;; Skip in case of error.
316 (let ((test (make-ert-test :body
(lambda () (skip-unless (error "Foo"))))))
317 (let ((result (ert-run-test test
)))
318 (should (ert-test-skipped-p result
)))))
320 (defmacro ert--test-my-list
(&rest args
)
321 "Don't use this. Instead, call `list' with ARGS, it does the same thing.
323 This macro is used to test if macroexpansion in `should' works."
326 (ert-deftest ert-test-should-failure-debugging
()
327 "Test that `should' errors contain the information we expect them to."
329 for
(body expected-condition
) in
330 `((,(lambda () (let ((x nil
)) (should x
)))
331 (ert-test-failed ((should x
) :form x
:value nil
)))
332 (,(lambda () (let ((x t
)) (should-not x
)))
333 (ert-test-failed ((should-not x
) :form x
:value t
)))
334 (,(lambda () (let ((x t
)) (should (not x
))))
335 (ert-test-failed ((should (not x
)) :form
(not t
) :value nil
)))
336 (,(lambda () (let ((x nil
)) (should-not (not x
))))
337 (ert-test-failed ((should-not (not x
)) :form
(not nil
) :value t
)))
338 (,(lambda () (let ((x t
) (y nil
)) (should-not
339 (ert--test-my-list x y
))))
341 ((should-not (ert--test-my-list x y
))
344 (,(lambda () (let ((_x t
)) (should (error "Foo"))))
347 (let ((test (make-ert-test :body body
)))
348 (condition-case actual-condition
350 (let ((ert-debug-on-error t
))
354 (should (equal actual-condition expected-condition
)))))))
356 (defun ert-test--which-file ()
357 "Dummy function to help test `symbol-file' for tests.")
359 (ert-deftest ert-test-deftest
()
360 (ert-deftest ert-test-abc
() "foo" :tags
'(bar))
361 (let ((abc (ert-get-test 'ert-test-abc
)))
362 (should (equal (ert-test-tags abc
) '(bar)))
363 (should (equal (ert-test-documentation abc
) "foo")))
364 (should (equal (symbol-file 'ert-test-deftest
'ert--test
)
365 (symbol-file 'ert-test--which-file
'defun
)))
367 (ert-deftest ert-test-def
() :expected-result
':passed
)
368 (let ((def (ert-get-test 'ert-test-def
)))
369 (should (equal (ert-test-expected-result-type def
) :passed
)))
370 ;; :documentation keyword is forbidden
371 (should-error (macroexpand '(ert-deftest ghi
()
372 :documentation
"foo"))))
374 (ert-deftest ert-test-record-backtrace
()
375 (let* ((test-body (lambda () (ert-fail "foo")))
376 (test (make-ert-test :body test-body
))
377 (result (ert-run-test test
)))
378 (should (ert-test-failed-p result
))
379 (should (eq (nth 1 (car (ert-test-failed-backtrace result
)))
382 (ert-deftest ert-test-messages
()
383 :tags
'(:causes-redisplay
)
384 (let* ((message-string "Test message")
385 (messages-buffer (get-buffer-create "*Messages*"))
386 (test (make-ert-test :body
(lambda () (message "%s" message-string
)))))
387 (with-current-buffer messages-buffer
388 (let ((result (ert-run-test test
)))
389 (should (equal (concat message-string
"\n")
390 (ert-test-result-messages result
)))))))
392 (ert-deftest ert-test-running-tests
()
393 (let ((outer-test (ert-get-test 'ert-test-running-tests
)))
394 (should (equal (ert-running-test) outer-test
))
395 (let (test1 test2 test3
)
396 (setq test1
(make-ert-test
399 (should (equal (ert-running-test) outer-test
))
400 (should (equal ert--running-tests
401 (list test1 test2 test3
406 (should (equal (ert-running-test) outer-test
))
407 (should (equal ert--running-tests
408 (list test3 test2 outer-test
)))
409 (ert-run-test test1
)))
413 (should (equal (ert-running-test) outer-test
))
414 (should (equal ert--running-tests
415 (list test3 outer-test
)))
416 (ert-run-test test2
))))
417 (should (ert-test-passed-p (ert-run-test test3
))))))
419 (ert-deftest ert-test-test-result-expected-p
()
420 "Test `ert-test-result-expected-p' and (implicitly) `ert-test-result-type-p'."
422 (let ((test (make-ert-test :body
(lambda ()))))
423 (should (ert-test-result-expected-p test
(ert-run-test test
))))
424 ;; unexpected failure
425 (let ((test (make-ert-test :body
(lambda () (ert-fail "failed")))))
426 (should-not (ert-test-result-expected-p test
(ert-run-test test
))))
428 (let ((test (make-ert-test :body
(lambda () (ert-fail "failed"))
429 :expected-result-type
':failed
)))
430 (should (ert-test-result-expected-p test
(ert-run-test test
))))
431 ;; `not' expected type
432 (let ((test (make-ert-test :body
(lambda ())
433 :expected-result-type
'(not :failed
))))
434 (should (ert-test-result-expected-p test
(ert-run-test test
))))
435 (let ((test (make-ert-test :body
(lambda ())
436 :expected-result-type
'(not :passed
))))
437 (should-not (ert-test-result-expected-p test
(ert-run-test test
))))
438 ;; `and' expected type
439 (let ((test (make-ert-test :body
(lambda ())
440 :expected-result-type
'(and :passed
:failed
))))
441 (should-not (ert-test-result-expected-p test
(ert-run-test test
))))
442 (let ((test (make-ert-test :body
(lambda ())
443 :expected-result-type
'(and :passed
445 (should (ert-test-result-expected-p test
(ert-run-test test
))))
446 ;; `or' expected type
447 (let ((test (make-ert-test :body
(lambda ())
448 :expected-result-type
'(or (and :passed
:failed
)
450 (should (ert-test-result-expected-p test
(ert-run-test test
))))
451 (let ((test (make-ert-test :body
(lambda ())
452 :expected-result-type
'(or (and :passed
:failed
)
454 (should-not (ert-test-result-expected-p test
(ert-run-test test
)))))
456 ;;; Test `ert-select-tests'.
457 (ert-deftest ert-test-select-regexp
()
458 (should (equal (ert-select-tests "^ert-test-select-regexp$" t
)
459 (list (ert-get-test 'ert-test-select-regexp
)))))
461 (ert-deftest ert-test-test-boundp
()
462 (should (ert-test-boundp 'ert-test-test-boundp
))
463 (should-not (ert-test-boundp (make-symbol "ert-not-a-test"))))
465 (ert-deftest ert-test-select-member
()
466 (should (equal (ert-select-tests '(member ert-test-select-member
) t
)
467 (list (ert-get-test 'ert-test-select-member
)))))
469 (ert-deftest ert-test-select-test
()
470 (should (equal (ert-select-tests (ert-get-test 'ert-test-select-test
) t
)
471 (list (ert-get-test 'ert-test-select-test
)))))
473 (ert-deftest ert-test-select-symbol
()
474 (should (equal (ert-select-tests 'ert-test-select-symbol t
)
475 (list (ert-get-test 'ert-test-select-symbol
)))))
477 (ert-deftest ert-test-select-and
()
478 (let ((test (make-ert-test
481 :most-recent-result
(make-ert-test-failed
485 (should (equal (ert-select-tests `(and (member ,test
) :failed
) t
)
488 (ert-deftest ert-test-select-tag
()
489 (let ((test (make-ert-test
493 (should (equal (ert-select-tests `(tag a
) (list test
)) (list test
)))
494 (should (equal (ert-select-tests `(tag b
) (list test
)) (list test
)))
495 (should (equal (ert-select-tests `(tag c
) (list test
)) '()))))
498 ;;; Tests for utility functions.
499 (ert-deftest ert-test-proper-list-p
()
500 (should (ert--proper-list-p '()))
501 (should (ert--proper-list-p '(1)))
502 (should (ert--proper-list-p '(1 2)))
503 (should (ert--proper-list-p '(1 2 3)))
504 (should (ert--proper-list-p '(1 2 3 4)))
505 (should (not (ert--proper-list-p 'a
)))
506 (should (not (ert--proper-list-p '(1 . a
))))
507 (should (not (ert--proper-list-p '(1 2 . a
))))
508 (should (not (ert--proper-list-p '(1 2 3 . a
))))
509 (should (not (ert--proper-list-p '(1 2 3 4 . a
))))
511 (setf (cdr (last a
)) a
)
512 (should (not (ert--proper-list-p a
))))
513 (let ((a (list 1 2)))
514 (setf (cdr (last a
)) a
)
515 (should (not (ert--proper-list-p a
))))
516 (let ((a (list 1 2 3)))
517 (setf (cdr (last a
)) a
)
518 (should (not (ert--proper-list-p a
))))
519 (let ((a (list 1 2 3 4)))
520 (setf (cdr (last a
)) a
)
521 (should (not (ert--proper-list-p a
))))
522 (let ((a (list 1 2)))
523 (setf (cdr (last a
)) (cdr a
))
524 (should (not (ert--proper-list-p a
))))
525 (let ((a (list 1 2 3)))
526 (setf (cdr (last a
)) (cdr a
))
527 (should (not (ert--proper-list-p a
))))
528 (let ((a (list 1 2 3 4)))
529 (setf (cdr (last a
)) (cdr a
))
530 (should (not (ert--proper-list-p a
))))
531 (let ((a (list 1 2 3)))
532 (setf (cdr (last a
)) (cddr a
))
533 (should (not (ert--proper-list-p a
))))
534 (let ((a (list 1 2 3 4)))
535 (setf (cdr (last a
)) (cddr a
))
536 (should (not (ert--proper-list-p a
))))
537 (let ((a (list 1 2 3 4)))
538 (setf (cdr (last a
)) (cl-cdddr a
))
539 (should (not (ert--proper-list-p a
)))))
541 (ert-deftest ert-test-parse-keys-and-body
()
542 (should (equal (ert--parse-keys-and-body '(foo)) '(nil (foo))))
543 (should (equal (ert--parse-keys-and-body '(:bar foo
)) '((:bar foo
) nil
)))
544 (should (equal (ert--parse-keys-and-body '(:bar foo a
(b)))
545 '((:bar foo
) (a (b)))))
546 (should (equal (ert--parse-keys-and-body '(:bar foo
:a
(b)))
547 '((:bar foo
:a
(b)) nil
)))
548 (should (equal (ert--parse-keys-and-body '(bar foo
:a
(b)))
549 '(nil (bar foo
:a
(b)))))
550 (should-error (ert--parse-keys-and-body '(:bar foo
:a
))))
553 (ert-deftest ert-test-run-tests-interactively
()
554 :tags
'(:causes-redisplay
)
555 (let ((passing-test (make-ert-test :name
'passing-test
556 :body
(lambda () (ert-pass))))
557 (failing-test (make-ert-test :name
'failing-test
558 :body
(lambda () (ert-fail
559 "failure message"))))
560 (skipped-test (make-ert-test :name
'skipped-test
561 :body
(lambda () (ert-skip
563 (let ((ert-debug-on-error nil
))
564 (let* ((buffer-name (generate-new-buffer-name " *ert-test-run-tests*"))
567 (lambda (format-string &rest args
)
568 (push (apply #'format format-string args
) messages
))))
569 (save-window-excursion
571 (let ((case-fold-search nil
))
572 (ert-run-tests-interactively
573 `(member ,passing-test
,failing-test
, skipped-test
) buffer-name
575 (should (equal messages
`(,(concat
576 "Ran 3 tests, 1 results were "
577 "as expected, 1 unexpected, "
579 (with-current-buffer buffer-name
580 (goto-char (point-min))
582 (buffer-substring (point-min)
587 "Selector: (member <passing-test> <failing-test> "
590 "Failed: 1 (1 unexpected)\n"
593 (when (get-buffer buffer-name
)
594 (kill-buffer buffer-name
))))))))
596 (ert-deftest ert-test-special-operator-p
()
597 (should (ert--special-operator-p 'if
))
598 (should-not (ert--special-operator-p 'car
))
599 (should-not (ert--special-operator-p 'ert--special-operator-p
))
600 (let ((b (cl-gensym)))
601 (should-not (ert--special-operator-p b
))
603 (should (ert--special-operator-p b
))))
605 (ert-deftest ert-test-list-of-should-forms
()
606 (let ((test (make-ert-test :body
(lambda ()
611 (let ((result (let ((ert-debug-on-error nil
))
612 (ert-run-test test
))))
613 (should (equal (ert-test-result-should-forms result
)
614 '(((should t
) :form t
:value t
)
615 ((should (null '())) :form
(null nil
) :value t
)
616 ((should nil
) :form nil
:value nil
)))))))
618 (ert-deftest ert-test-list-of-should-forms-observers-should-not-stack
()
619 (let ((test (make-ert-test
621 (let ((test2 (make-ert-test
624 (let ((result (ert-run-test test2
)))
625 (should (ert-test-passed-p result
))))))))
626 (let ((result (let ((ert-debug-on-error nil
))
627 (ert-run-test test
))))
628 (should (ert-test-passed-p result
))
629 (should (eql (length (ert-test-result-should-forms result
))
632 (ert-deftest ert-test-list-of-should-forms-no-deep-copy
()
633 (let ((test (make-ert-test :body
(lambda ()
634 (let ((obj (list 'a
)))
635 (should (equal obj
'(a)))
637 (should (equal obj
'(b))))))))
638 (let ((result (let ((ert-debug-on-error nil
))
639 (ert-run-test test
))))
640 (should (ert-test-passed-p result
))
641 (should (equal (ert-test-result-should-forms result
)
642 '(((should (equal obj
'(a))) :form
(equal (b) (a)) :value t
644 ((should (equal obj
'(b))) :form
(equal (b) (b)) :value t
648 (ert-deftest ert-test-string-first-line
()
649 (should (equal (ert--string-first-line "") ""))
650 (should (equal (ert--string-first-line "abc") "abc"))
651 (should (equal (ert--string-first-line "abc\n") "abc"))
652 (should (equal (ert--string-first-line "foo\nbar") "foo"))
653 (should (equal (ert--string-first-line " foo\nbar\nbaz\n") " foo")))
655 (ert-deftest ert-test-explain-equal
()
656 (should (equal (ert--explain-equal nil
'foo
)
657 '(different-atoms nil foo
)))
658 (should (equal (ert--explain-equal '(a a
) '(a b
))
659 '(list-elt 1 (different-atoms a b
))))
660 (should (equal (ert--explain-equal '(1 48) '(1 49))
661 '(list-elt 1 (different-atoms (48 "#x30" "?0")
663 (should (equal (ert--explain-equal 'nil
'(a))
664 '(different-types nil
(a))))
665 (should (equal (ert--explain-equal '(a b c
) '(a b c d
))
666 '(proper-lists-of-different-length 3 4 (a b c
) (a b c d
)
667 first-mismatch-at
3)))
668 (let ((sym (make-symbol "a")))
669 (should (equal (ert--explain-equal 'a sym
)
670 `(different-symbols-with-the-same-name a
,sym
)))))
672 (ert-deftest ert-test-explain-equal-improper-list
()
673 (should (equal (ert--explain-equal '(a . b
) '(a . c
))
674 '(cdr (different-atoms b c
)))))
676 (ert-deftest ert-test-explain-equal-keymaps
()
677 ;; This used to be very slow.
678 (should (equal (make-keymap) (make-keymap)))
679 (should (equal (make-sparse-keymap) (make-sparse-keymap))))
681 (ert-deftest ert-test-significant-plist-keys
()
682 (should (equal (ert--significant-plist-keys '()) '()))
683 (should (equal (ert--significant-plist-keys '(a b c d e f c g p q r nil s t
))
686 (ert-deftest ert-test-plist-difference-explanation
()
687 (should (equal (ert--plist-difference-explanation
690 (should (equal (ert--plist-difference-explanation
692 '(different-properties-for-key c
(different-atoms t nil
))))
693 (should (equal (ert--plist-difference-explanation
694 '(a b c t
) '(c nil a b
))
695 '(different-properties-for-key c
(different-atoms t nil
))))
696 (should (equal (ert--plist-difference-explanation
697 '(a b c
(foo . bar
)) '(c (foo . baz
) a b
))
698 '(different-properties-for-key c
700 (different-atoms bar baz
))))))
702 (ert-deftest ert-test-abbreviate-string
()
703 (should (equal (ert--abbreviate-string "foo" 4 nil
) "foo"))
704 (should (equal (ert--abbreviate-string "foo" 3 nil
) "foo"))
705 (should (equal (ert--abbreviate-string "foo" 3 nil
) "foo"))
706 (should (equal (ert--abbreviate-string "foo" 2 nil
) "fo"))
707 (should (equal (ert--abbreviate-string "foo" 1 nil
) "f"))
708 (should (equal (ert--abbreviate-string "foo" 0 nil
) ""))
709 (should (equal (ert--abbreviate-string "bar" 4 t
) "bar"))
710 (should (equal (ert--abbreviate-string "bar" 3 t
) "bar"))
711 (should (equal (ert--abbreviate-string "bar" 3 t
) "bar"))
712 (should (equal (ert--abbreviate-string "bar" 2 t
) "ar"))
713 (should (equal (ert--abbreviate-string "bar" 1 t
) "r"))
714 (should (equal (ert--abbreviate-string "bar" 0 t
) "")))
716 (ert-deftest ert-test-explain-equal-string-properties
()
718 (equal (ert--explain-equal-including-properties #("foo" 0 1 (a b
))
721 (different-properties-for-key a
(different-atoms b nil
))
723 context-after
"oo")))
724 (should (equal (ert--explain-equal-including-properties
727 '(array-elt 0 (different-atoms (?f
"#x66" "?f")
730 (equal (ert--explain-equal-including-properties
731 #("foo" 0 1 (a b c d
) 1 3 (a b
))
732 #("foo" 0 1 (c d a b
) 1 2 (a foo
)))
733 '(char 1 "o" (different-properties-for-key a
(different-atoms b foo
))
734 context-before
"f" context-after
"o"))))
736 (ert-deftest ert-test-equal-including-properties
()
737 (should (equal-including-properties "foo" "foo"))
738 (should (ert-equal-including-properties "foo" "foo"))
740 (should (equal-including-properties #("foo" 0 3 (a b
))
741 (propertize "foo" 'a
'b
)))
742 (should (ert-equal-including-properties #("foo" 0 3 (a b
))
743 (propertize "foo" 'a
'b
)))
745 (should (equal-including-properties #("foo" 0 3 (a b c d
))
746 (propertize "foo" 'a
'b
'c
'd
)))
747 (should (ert-equal-including-properties #("foo" 0 3 (a b c d
))
748 (propertize "foo" 'a
'b
'c
'd
)))
750 (should-not (equal-including-properties #("foo" 0 3 (a b c e
))
751 (propertize "foo" 'a
'b
'c
'd
)))
752 (should-not (ert-equal-including-properties #("foo" 0 3 (a b c e
))
753 (propertize "foo" 'a
'b
'c
'd
)))
756 (should-not (equal-including-properties #("foo" 0 3 (a (t)))
757 (propertize "foo" 'a
(list t
))))
758 (should (ert-equal-including-properties #("foo" 0 3 (a (t)))
759 (propertize "foo" 'a
(list t
)))))
761 (ert-deftest ert-test-stats-set-test-and-result
()
762 (let* ((test-1 (make-ert-test :name
'test-1
763 :body
(lambda () nil
)))
764 (test-2 (make-ert-test :name
'test-2
765 :body
(lambda () nil
)))
766 (test-3 (make-ert-test :name
'test-2
767 :body
(lambda () nil
)))
768 (stats (ert--make-stats (list test-1 test-2
) 't
))
769 (failed (make-ert-test-failed :condition nil
772 (skipped (make-ert-test-skipped :condition nil
775 (should (eql 2 (ert-stats-total stats
)))
776 (should (eql 0 (ert-stats-completed stats
)))
777 (should (eql 0 (ert-stats-completed-expected stats
)))
778 (should (eql 0 (ert-stats-completed-unexpected stats
)))
779 (should (eql 0 (ert-stats-skipped stats
)))
780 (ert--stats-set-test-and-result stats
0 test-1
(make-ert-test-passed))
781 (should (eql 2 (ert-stats-total stats
)))
782 (should (eql 1 (ert-stats-completed stats
)))
783 (should (eql 1 (ert-stats-completed-expected stats
)))
784 (should (eql 0 (ert-stats-completed-unexpected stats
)))
785 (should (eql 0 (ert-stats-skipped stats
)))
786 (ert--stats-set-test-and-result stats
0 test-1 failed
)
787 (should (eql 2 (ert-stats-total stats
)))
788 (should (eql 1 (ert-stats-completed stats
)))
789 (should (eql 0 (ert-stats-completed-expected stats
)))
790 (should (eql 1 (ert-stats-completed-unexpected stats
)))
791 (should (eql 0 (ert-stats-skipped stats
)))
792 (ert--stats-set-test-and-result stats
0 test-1 nil
)
793 (should (eql 2 (ert-stats-total stats
)))
794 (should (eql 0 (ert-stats-completed stats
)))
795 (should (eql 0 (ert-stats-completed-expected stats
)))
796 (should (eql 0 (ert-stats-completed-unexpected stats
)))
797 (should (eql 0 (ert-stats-skipped stats
)))
798 (ert--stats-set-test-and-result stats
0 test-3 failed
)
799 (should (eql 2 (ert-stats-total stats
)))
800 (should (eql 1 (ert-stats-completed stats
)))
801 (should (eql 0 (ert-stats-completed-expected stats
)))
802 (should (eql 1 (ert-stats-completed-unexpected stats
)))
803 (should (eql 0 (ert-stats-skipped stats
)))
804 (ert--stats-set-test-and-result stats
1 test-2
(make-ert-test-passed))
805 (should (eql 2 (ert-stats-total stats
)))
806 (should (eql 2 (ert-stats-completed stats
)))
807 (should (eql 1 (ert-stats-completed-expected stats
)))
808 (should (eql 1 (ert-stats-completed-unexpected stats
)))
809 (should (eql 0 (ert-stats-skipped stats
)))
810 (ert--stats-set-test-and-result stats
0 test-1
(make-ert-test-passed))
811 (should (eql 2 (ert-stats-total stats
)))
812 (should (eql 2 (ert-stats-completed stats
)))
813 (should (eql 2 (ert-stats-completed-expected stats
)))
814 (should (eql 0 (ert-stats-completed-unexpected stats
)))
815 (should (eql 0 (ert-stats-skipped stats
)))
816 (ert--stats-set-test-and-result stats
0 test-1 skipped
)
817 (should (eql 2 (ert-stats-total stats
)))
818 (should (eql 2 (ert-stats-completed stats
)))
819 (should (eql 1 (ert-stats-completed-expected stats
)))
820 (should (eql 0 (ert-stats-completed-unexpected stats
)))
821 (should (eql 1 (ert-stats-skipped stats
)))))
826 ;;; ert-tests.el ends here