Mercurial > emacs
annotate test/automated/ert-tests.el @ 112400:c729a73f3e52
Merge: aclocal.m4: tweaks to regenerate more conveniently
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Fri, 21 Jan 2011 12:24:31 -0800 |
parents | c5917804ecad |
children |
rev | line source |
---|---|
112201
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
1 ;;; ert-tests.el --- ERT's self-tests |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
2 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
3 ;; Copyright (C) 2007, 2008, 2010, 2011 Free Software Foundation, Inc. |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
4 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
5 ;; Author: Christian Ohler <ohler@gnu.org> |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
6 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
7 ;; This file is part of GNU Emacs. |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
8 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
9 ;; This program is free software: you can redistribute it and/or |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
10 ;; modify it under the terms of the GNU General Public License as |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
11 ;; published by the Free Software Foundation, either version 3 of the |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
12 ;; License, or (at your option) any later version. |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
13 ;; |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
14 ;; This program is distributed in the hope that it will be useful, but |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
17 ;; General Public License for more details. |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
18 ;; |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
19 ;; You should have received a copy of the GNU General Public License |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
20 ;; along with this program. If not, see `http://www.gnu.org/licenses/'. |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
21 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
22 ;;; Commentary: |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
23 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
24 ;; This file is part of ERT, the Emacs Lisp Regression Testing tool. |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
25 ;; See ert.el or the texinfo manual for more details. |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
26 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
27 ;;; Code: |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
28 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
29 (eval-when-compile |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
30 (require 'cl)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
31 (require 'ert) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
32 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
33 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
34 ;;; Self-test that doesn't rely on ERT, for bootstrapping. |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
35 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
36 ;; This is used to test that bodies actually run. |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
37 (defvar ert--test-body-was-run) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
38 (ert-deftest ert-test-body-runs () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
39 (setq ert--test-body-was-run t)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
40 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
41 (defun ert-self-test () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
42 "Run ERT's self-tests and make sure they actually ran." |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
43 (let ((window-configuration (current-window-configuration))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
44 (let ((ert--test-body-was-run nil)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
45 ;; The buffer name chosen here should not compete with the default |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
46 ;; results buffer name for completion in `switch-to-buffer'. |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
47 (let ((stats (ert-run-tests-interactively "^ert-" " *ert self-tests*"))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
48 (assert ert--test-body-was-run) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
49 (if (zerop (ert-stats-completed-unexpected stats)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
50 ;; Hide results window only when everything went well. |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
51 (set-window-configuration window-configuration) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
52 (error "ERT self-test failed")))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
53 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
54 (defun ert-self-test-and-exit () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
55 "Run ERT's self-tests and exit Emacs. |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
56 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
57 The exit code will be zero if the tests passed, nonzero if they |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
58 failed or if there was a problem." |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
59 (unwind-protect |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
60 (progn |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
61 (ert-self-test) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
62 (kill-emacs 0)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
63 (unwind-protect |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
64 (progn |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
65 (message "Error running tests") |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
66 (backtrace)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
67 (kill-emacs 1)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
68 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
69 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
70 ;;; Further tests are defined using ERT. |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
71 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
72 (ert-deftest ert-test-nested-test-body-runs () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
73 "Test that nested test bodies run." |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
74 (lexical-let ((was-run nil)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
75 (let ((test (make-ert-test :body (lambda () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
76 (setq was-run t))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
77 (assert (not was-run)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
78 (ert-run-test test) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
79 (assert was-run)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
80 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
81 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
82 ;;; Test that pass/fail works. |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
83 (ert-deftest ert-test-pass () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
84 (let ((test (make-ert-test :body (lambda ())))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
85 (let ((result (ert-run-test test))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
86 (assert (ert-test-passed-p result))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
87 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
88 (ert-deftest ert-test-fail () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
89 (let ((test (make-ert-test :body (lambda () (ert-fail "failure message"))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
90 (let ((result (let ((ert-debug-on-error nil)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
91 (ert-run-test test)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
92 (assert (ert-test-failed-p result) t) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
93 (assert (equal (ert-test-result-with-condition-condition result) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
94 '(ert-test-failed "failure message")) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
95 t)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
96 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
97 (ert-deftest ert-test-fail-debug-with-condition-case () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
98 (let ((test (make-ert-test :body (lambda () (ert-fail "failure message"))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
99 (condition-case condition |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
100 (progn |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
101 (let ((ert-debug-on-error t)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
102 (ert-run-test test)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
103 (assert nil)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
104 ((error) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
105 (assert (equal condition '(ert-test-failed "failure message")) t))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
106 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
107 (ert-deftest ert-test-fail-debug-with-debugger-1 () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
108 (let ((test (make-ert-test :body (lambda () (ert-fail "failure message"))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
109 (let ((debugger (lambda (&rest debugger-args) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
110 (assert nil)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
111 (let ((ert-debug-on-error nil)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
112 (ert-run-test test))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
113 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
114 (ert-deftest ert-test-fail-debug-with-debugger-2 () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
115 (let ((test (make-ert-test :body (lambda () (ert-fail "failure message"))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
116 (block nil |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
117 (let ((debugger (lambda (&rest debugger-args) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
118 (return-from nil nil)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
119 (let ((ert-debug-on-error t)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
120 (ert-run-test test)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
121 (assert nil))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
122 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
123 (ert-deftest ert-test-fail-debug-nested-with-debugger () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
124 (let ((test (make-ert-test :body (lambda () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
125 (let ((ert-debug-on-error t)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
126 (ert-fail "failure message")))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
127 (let ((debugger (lambda (&rest debugger-args) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
128 (assert nil nil "Assertion a")))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
129 (let ((ert-debug-on-error nil)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
130 (ert-run-test test)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
131 (let ((test (make-ert-test :body (lambda () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
132 (let ((ert-debug-on-error nil)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
133 (ert-fail "failure message")))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
134 (block nil |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
135 (let ((debugger (lambda (&rest debugger-args) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
136 (return-from nil nil)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
137 (let ((ert-debug-on-error t)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
138 (ert-run-test test)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
139 (assert nil nil "Assertion b"))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
140 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
141 (ert-deftest ert-test-error () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
142 (let ((test (make-ert-test :body (lambda () (error "Error message"))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
143 (let ((result (let ((ert-debug-on-error nil)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
144 (ert-run-test test)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
145 (assert (ert-test-failed-p result) t) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
146 (assert (equal (ert-test-result-with-condition-condition result) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
147 '(error "Error message")) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
148 t)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
149 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
150 (ert-deftest ert-test-error-debug () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
151 (let ((test (make-ert-test :body (lambda () (error "Error message"))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
152 (condition-case condition |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
153 (progn |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
154 (let ((ert-debug-on-error t)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
155 (ert-run-test test)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
156 (assert nil)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
157 ((error) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
158 (assert (equal condition '(error "Error message")) t))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
159 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
160 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
161 ;;; Test that `should' works. |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
162 (ert-deftest ert-test-should () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
163 (let ((test (make-ert-test :body (lambda () (should nil))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
164 (let ((result (let ((ert-debug-on-error nil)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
165 (ert-run-test test)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
166 (assert (ert-test-failed-p result) t) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
167 (assert (equal (ert-test-result-with-condition-condition result) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
168 '(ert-test-failed ((should nil) :form nil :value nil))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
169 t))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
170 (let ((test (make-ert-test :body (lambda () (should t))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
171 (let ((result (ert-run-test test))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
172 (assert (ert-test-passed-p result) t)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
173 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
174 (ert-deftest ert-test-should-value () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
175 (should (eql (should 'foo) 'foo)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
176 (should (eql (should 'bar) 'bar))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
177 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
178 (ert-deftest ert-test-should-not () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
179 (let ((test (make-ert-test :body (lambda () (should-not t))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
180 (let ((result (let ((ert-debug-on-error nil)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
181 (ert-run-test test)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
182 (assert (ert-test-failed-p result) t) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
183 (assert (equal (ert-test-result-with-condition-condition result) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
184 '(ert-test-failed ((should-not t) :form t :value t))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
185 t))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
186 (let ((test (make-ert-test :body (lambda () (should-not nil))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
187 (let ((result (ert-run-test test))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
188 (assert (ert-test-passed-p result))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
189 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
190 (ert-deftest ert-test-should-with-macrolet () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
191 (let ((test (make-ert-test :body (lambda () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
192 (macrolet ((foo () `(progn t nil))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
193 (should (foo))))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
194 (let ((result (let ((ert-debug-on-error nil)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
195 (ert-run-test test)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
196 (should (ert-test-failed-p result)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
197 (should (equal |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
198 (ert-test-result-with-condition-condition result) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
199 '(ert-test-failed ((should (foo)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
200 :form (progn t nil) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
201 :value nil))))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
202 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
203 (ert-deftest ert-test-should-error () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
204 ;; No error. |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
205 (let ((test (make-ert-test :body (lambda () (should-error (progn)))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
206 (let ((result (let ((ert-debug-on-error nil)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
207 (ert-run-test test)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
208 (should (ert-test-failed-p result)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
209 (should (equal (ert-test-result-with-condition-condition result) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
210 '(ert-test-failed |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
211 ((should-error (progn)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
212 :form (progn) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
213 :value nil |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
214 :fail-reason "did not signal an error")))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
215 ;; A simple error. |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
216 (should (equal (should-error (error "Foo")) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
217 '(error "Foo"))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
218 ;; Error of unexpected type. |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
219 (let ((test (make-ert-test :body (lambda () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
220 (should-error (error "Foo") |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
221 :type 'singularity-error))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
222 (let ((result (ert-run-test test))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
223 (should (ert-test-failed-p result)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
224 (should (equal |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
225 (ert-test-result-with-condition-condition result) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
226 '(ert-test-failed |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
227 ((should-error (error "Foo") :type 'singularity-error) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
228 :form (error "Foo") |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
229 :condition (error "Foo") |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
230 :fail-reason |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
231 "the error signalled did not have the expected type")))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
232 ;; Error of the expected type. |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
233 (let* ((error nil) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
234 (test (make-ert-test |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
235 :body (lambda () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
236 (setq error |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
237 (should-error (signal 'singularity-error nil) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
238 :type 'singularity-error)))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
239 (let ((result (ert-run-test test))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
240 (should (ert-test-passed-p result)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
241 (should (equal error '(singularity-error)))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
242 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
243 (ert-deftest ert-test-should-error-subtypes () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
244 (should-error (signal 'singularity-error nil) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
245 :type 'singularity-error |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
246 :exclude-subtypes t) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
247 (let ((test (make-ert-test |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
248 :body (lambda () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
249 (should-error (signal 'arith-error nil) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
250 :type 'singularity-error))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
251 (let ((result (ert-run-test test))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
252 (should (ert-test-failed-p result)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
253 (should (equal |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
254 (ert-test-result-with-condition-condition result) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
255 '(ert-test-failed |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
256 ((should-error (signal 'arith-error nil) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
257 :type 'singularity-error) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
258 :form (signal arith-error nil) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
259 :condition (arith-error) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
260 :fail-reason |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
261 "the error signalled did not have the expected type")))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
262 (let ((test (make-ert-test |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
263 :body (lambda () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
264 (should-error (signal 'arith-error nil) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
265 :type 'singularity-error |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
266 :exclude-subtypes t))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
267 (let ((result (ert-run-test test))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
268 (should (ert-test-failed-p result)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
269 (should (equal |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
270 (ert-test-result-with-condition-condition result) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
271 '(ert-test-failed |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
272 ((should-error (signal 'arith-error nil) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
273 :type 'singularity-error |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
274 :exclude-subtypes t) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
275 :form (signal arith-error nil) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
276 :condition (arith-error) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
277 :fail-reason |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
278 "the error signalled did not have the expected type")))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
279 (let ((test (make-ert-test |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
280 :body (lambda () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
281 (should-error (signal 'singularity-error nil) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
282 :type 'arith-error |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
283 :exclude-subtypes t))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
284 (let ((result (ert-run-test test))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
285 (should (ert-test-failed-p result)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
286 (should (equal |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
287 (ert-test-result-with-condition-condition result) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
288 '(ert-test-failed |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
289 ((should-error (signal 'singularity-error nil) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
290 :type 'arith-error |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
291 :exclude-subtypes t) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
292 :form (signal singularity-error nil) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
293 :condition (singularity-error) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
294 :fail-reason |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
295 "the error signalled was a subtype of the expected type"))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
296 )) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
297 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
298 (defmacro ert--test-my-list (&rest args) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
299 "Don't use this. Instead, call `list' with ARGS, it does the same thing. |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
300 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
301 This macro is used to test if macroexpansion in `should' works." |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
302 `(list ,@args)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
303 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
304 (ert-deftest ert-test-should-failure-debugging () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
305 "Test that `should' errors contain the information we expect them to." |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
306 (loop for (body expected-condition) in |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
307 `((,(lambda () (let ((x nil)) (should x))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
308 (ert-test-failed ((should x) :form x :value nil))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
309 (,(lambda () (let ((x t)) (should-not x))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
310 (ert-test-failed ((should-not x) :form x :value t))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
311 (,(lambda () (let ((x t)) (should (not x)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
312 (ert-test-failed ((should (not x)) :form (not t) :value nil))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
313 (,(lambda () (let ((x nil)) (should-not (not x)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
314 (ert-test-failed ((should-not (not x)) :form (not nil) :value t))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
315 (,(lambda () (let ((x t) (y nil)) (should-not |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
316 (ert--test-my-list x y)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
317 (ert-test-failed |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
318 ((should-not (ert--test-my-list x y)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
319 :form (list t nil) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
320 :value (t nil)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
321 (,(lambda () (let ((x t)) (should (error "Foo")))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
322 (error "Foo"))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
323 do |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
324 (let ((test (make-ert-test :body body))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
325 (condition-case actual-condition |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
326 (progn |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
327 (let ((ert-debug-on-error t)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
328 (ert-run-test test)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
329 (assert nil)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
330 ((error) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
331 (should (equal actual-condition expected-condition))))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
332 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
333 (ert-deftest ert-test-deftest () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
334 (should (equal (macroexpand '(ert-deftest abc () "foo" :tags '(bar))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
335 '(progn |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
336 (ert-set-test 'abc |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
337 (make-ert-test :name 'abc |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
338 :documentation "foo" |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
339 :tags '(bar) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
340 :body (lambda ()))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
341 (push '(ert-deftest . abc) current-load-list) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
342 'abc))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
343 (should (equal (macroexpand '(ert-deftest def () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
344 :expected-result ':passed)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
345 '(progn |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
346 (ert-set-test 'def |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
347 (make-ert-test :name 'def |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
348 :expected-result-type ':passed |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
349 :body (lambda ()))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
350 (push '(ert-deftest . def) current-load-list) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
351 'def))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
352 ;; :documentation keyword is forbidden |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
353 (should-error (macroexpand '(ert-deftest ghi () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
354 :documentation "foo")))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
355 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
356 (ert-deftest ert-test-record-backtrace () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
357 (let ((test (make-ert-test :body (lambda () (ert-fail "foo"))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
358 (let ((result (ert-run-test test))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
359 (should (ert-test-failed-p result)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
360 (with-temp-buffer |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
361 (ert--print-backtrace (ert-test-failed-backtrace result)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
362 (goto-char (point-min)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
363 (end-of-line) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
364 (let ((first-line (buffer-substring-no-properties (point-min) (point)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
365 (should (equal first-line " signal(ert-test-failed (\"foo\"))"))))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
366 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
367 (ert-deftest ert-test-messages () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
368 :tags '(:causes-redisplay) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
369 (let* ((message-string "Test message") |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
370 (messages-buffer (get-buffer-create "*Messages*")) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
371 (test (make-ert-test :body (lambda () (message "%s" message-string))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
372 (with-current-buffer messages-buffer |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
373 (let ((result (ert-run-test test))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
374 (should (equal (concat message-string "\n") |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
375 (ert-test-result-messages result))))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
376 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
377 (ert-deftest ert-test-running-tests () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
378 (let ((outer-test (ert-get-test 'ert-test-running-tests))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
379 (should (equal (ert-running-test) outer-test)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
380 (let (test1 test2 test3) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
381 (setq test1 (make-ert-test |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
382 :name "1" |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
383 :body (lambda () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
384 (should (equal (ert-running-test) outer-test)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
385 (should (equal ert--running-tests |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
386 (list test1 test2 test3 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
387 outer-test))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
388 test2 (make-ert-test |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
389 :name "2" |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
390 :body (lambda () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
391 (should (equal (ert-running-test) outer-test)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
392 (should (equal ert--running-tests |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
393 (list test3 test2 outer-test))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
394 (ert-run-test test1))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
395 test3 (make-ert-test |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
396 :name "3" |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
397 :body (lambda () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
398 (should (equal (ert-running-test) outer-test)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
399 (should (equal ert--running-tests |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
400 (list test3 outer-test))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
401 (ert-run-test test2)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
402 (should (ert-test-passed-p (ert-run-test test3)))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
403 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
404 (ert-deftest ert-test-test-result-expected-p () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
405 "Test `ert-test-result-expected-p' and (implicitly) `ert-test-result-type-p'." |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
406 ;; passing test |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
407 (let ((test (make-ert-test :body (lambda ())))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
408 (should (ert-test-result-expected-p test (ert-run-test test)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
409 ;; unexpected failure |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
410 (let ((test (make-ert-test :body (lambda () (ert-fail "failed"))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
411 (should-not (ert-test-result-expected-p test (ert-run-test test)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
412 ;; expected failure |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
413 (let ((test (make-ert-test :body (lambda () (ert-fail "failed")) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
414 :expected-result-type ':failed))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
415 (should (ert-test-result-expected-p test (ert-run-test test)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
416 ;; `not' expected type |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
417 (let ((test (make-ert-test :body (lambda ()) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
418 :expected-result-type '(not :failed)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
419 (should (ert-test-result-expected-p test (ert-run-test test)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
420 (let ((test (make-ert-test :body (lambda ()) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
421 :expected-result-type '(not :passed)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
422 (should-not (ert-test-result-expected-p test (ert-run-test test)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
423 ;; `and' expected type |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
424 (let ((test (make-ert-test :body (lambda ()) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
425 :expected-result-type '(and :passed :failed)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
426 (should-not (ert-test-result-expected-p test (ert-run-test test)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
427 (let ((test (make-ert-test :body (lambda ()) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
428 :expected-result-type '(and :passed |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
429 (not :failed))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
430 (should (ert-test-result-expected-p test (ert-run-test test)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
431 ;; `or' expected type |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
432 (let ((test (make-ert-test :body (lambda ()) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
433 :expected-result-type '(or (and :passed :failed) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
434 :passed)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
435 (should (ert-test-result-expected-p test (ert-run-test test)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
436 (let ((test (make-ert-test :body (lambda ()) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
437 :expected-result-type '(or (and :passed :failed) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
438 nil (not t))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
439 (should-not (ert-test-result-expected-p test (ert-run-test test))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
440 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
441 ;;; Test `ert-select-tests'. |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
442 (ert-deftest ert-test-select-regexp () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
443 (should (equal (ert-select-tests "^ert-test-select-regexp$" t) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
444 (list (ert-get-test 'ert-test-select-regexp))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
445 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
446 (ert-deftest ert-test-test-boundp () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
447 (should (ert-test-boundp 'ert-test-test-boundp)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
448 (should-not (ert-test-boundp (make-symbol "ert-not-a-test")))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
449 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
450 (ert-deftest ert-test-select-member () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
451 (should (equal (ert-select-tests '(member ert-test-select-member) t) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
452 (list (ert-get-test 'ert-test-select-member))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
453 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
454 (ert-deftest ert-test-select-test () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
455 (should (equal (ert-select-tests (ert-get-test 'ert-test-select-test) t) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
456 (list (ert-get-test 'ert-test-select-test))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
457 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
458 (ert-deftest ert-test-select-symbol () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
459 (should (equal (ert-select-tests 'ert-test-select-symbol t) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
460 (list (ert-get-test 'ert-test-select-symbol))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
461 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
462 (ert-deftest ert-test-select-and () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
463 (let ((test (make-ert-test |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
464 :name nil |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
465 :body nil |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
466 :most-recent-result (make-ert-test-failed |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
467 :condition nil |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
468 :backtrace nil |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
469 :infos nil)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
470 (should (equal (ert-select-tests `(and (member ,test) :failed) t) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
471 (list test))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
472 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
473 (ert-deftest ert-test-select-tag () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
474 (let ((test (make-ert-test |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
475 :name nil |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
476 :body nil |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
477 :tags '(a b)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
478 (should (equal (ert-select-tests `(tag a) (list test)) (list test))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
479 (should (equal (ert-select-tests `(tag b) (list test)) (list test))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
480 (should (equal (ert-select-tests `(tag c) (list test)) '())))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
481 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
482 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
483 ;;; Tests for utility functions. |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
484 (ert-deftest ert-test-proper-list-p () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
485 (should (ert--proper-list-p '())) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
486 (should (ert--proper-list-p '(1))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
487 (should (ert--proper-list-p '(1 2))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
488 (should (ert--proper-list-p '(1 2 3))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
489 (should (ert--proper-list-p '(1 2 3 4))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
490 (should (not (ert--proper-list-p 'a))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
491 (should (not (ert--proper-list-p '(1 . a)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
492 (should (not (ert--proper-list-p '(1 2 . a)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
493 (should (not (ert--proper-list-p '(1 2 3 . a)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
494 (should (not (ert--proper-list-p '(1 2 3 4 . a)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
495 (let ((a (list 1))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
496 (setf (cdr (last a)) a) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
497 (should (not (ert--proper-list-p a)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
498 (let ((a (list 1 2))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
499 (setf (cdr (last a)) a) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
500 (should (not (ert--proper-list-p a)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
501 (let ((a (list 1 2 3))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
502 (setf (cdr (last a)) a) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
503 (should (not (ert--proper-list-p a)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
504 (let ((a (list 1 2 3 4))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
505 (setf (cdr (last a)) a) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
506 (should (not (ert--proper-list-p a)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
507 (let ((a (list 1 2))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
508 (setf (cdr (last a)) (cdr a)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
509 (should (not (ert--proper-list-p a)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
510 (let ((a (list 1 2 3))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
511 (setf (cdr (last a)) (cdr a)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
512 (should (not (ert--proper-list-p a)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
513 (let ((a (list 1 2 3 4))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
514 (setf (cdr (last a)) (cdr a)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
515 (should (not (ert--proper-list-p a)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
516 (let ((a (list 1 2 3))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
517 (setf (cdr (last a)) (cddr a)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
518 (should (not (ert--proper-list-p a)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
519 (let ((a (list 1 2 3 4))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
520 (setf (cdr (last a)) (cddr a)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
521 (should (not (ert--proper-list-p a)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
522 (let ((a (list 1 2 3 4))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
523 (setf (cdr (last a)) (cdddr a)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
524 (should (not (ert--proper-list-p a))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
525 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
526 (ert-deftest ert-test-parse-keys-and-body () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
527 (should (equal (ert--parse-keys-and-body '(foo)) '(nil (foo)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
528 (should (equal (ert--parse-keys-and-body '(:bar foo)) '((:bar foo) nil))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
529 (should (equal (ert--parse-keys-and-body '(:bar foo a (b))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
530 '((:bar foo) (a (b))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
531 (should (equal (ert--parse-keys-and-body '(:bar foo :a (b))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
532 '((:bar foo :a (b)) nil))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
533 (should (equal (ert--parse-keys-and-body '(bar foo :a (b))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
534 '(nil (bar foo :a (b))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
535 (should-error (ert--parse-keys-and-body '(:bar foo :a)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
536 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
537 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
538 (ert-deftest ert-test-run-tests-interactively () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
539 :tags '(:causes-redisplay) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
540 (let ((passing-test (make-ert-test :name 'passing-test |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
541 :body (lambda () (ert-pass)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
542 (failing-test (make-ert-test :name 'failing-test |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
543 :body (lambda () (ert-fail |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
544 "failure message"))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
545 (let ((ert-debug-on-error nil)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
546 (let* ((buffer-name (generate-new-buffer-name " *ert-test-run-tests*")) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
547 (messages nil) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
548 (mock-message-fn |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
549 (lambda (format-string &rest args) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
550 (push (apply #'format format-string args) messages)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
551 (save-window-excursion |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
552 (unwind-protect |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
553 (let ((case-fold-search nil)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
554 (ert-run-tests-interactively |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
555 `(member ,passing-test ,failing-test) buffer-name |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
556 mock-message-fn) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
557 (should (equal messages `(,(concat |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
558 "Ran 2 tests, 1 results were " |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
559 "as expected, 1 unexpected")))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
560 (with-current-buffer buffer-name |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
561 (goto-char (point-min)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
562 (should (equal |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
563 (buffer-substring (point-min) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
564 (save-excursion |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
565 (forward-line 4) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
566 (point))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
567 (concat |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
568 "Selector: (member <passing-test> <failing-test>)\n" |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
569 "Passed: 1\n" |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
570 "Failed: 1 (1 unexpected)\n" |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
571 "Total: 2/2\n"))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
572 (when (get-buffer buffer-name) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
573 (kill-buffer buffer-name)))))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
574 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
575 (ert-deftest ert-test-special-operator-p () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
576 (should (ert--special-operator-p 'if)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
577 (should-not (ert--special-operator-p 'car)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
578 (should-not (ert--special-operator-p 'ert--special-operator-p)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
579 (let ((b (ert--gensym))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
580 (should-not (ert--special-operator-p b)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
581 (fset b 'if) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
582 (should (ert--special-operator-p b)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
583 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
584 (ert-deftest ert-test-list-of-should-forms () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
585 (let ((test (make-ert-test :body (lambda () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
586 (should t) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
587 (should (null '())) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
588 (should nil) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
589 (should t))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
590 (let ((result (let ((ert-debug-on-error nil)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
591 (ert-run-test test)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
592 (should (equal (ert-test-result-should-forms result) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
593 '(((should t) :form t :value t) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
594 ((should (null '())) :form (null nil) :value t) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
595 ((should nil) :form nil :value nil))))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
596 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
597 (ert-deftest ert-test-list-of-should-forms-observers-should-not-stack () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
598 (let ((test (make-ert-test |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
599 :body (lambda () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
600 (let ((test2 (make-ert-test |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
601 :body (lambda () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
602 (should t))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
603 (let ((result (ert-run-test test2))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
604 (should (ert-test-passed-p result)))))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
605 (let ((result (let ((ert-debug-on-error nil)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
606 (ert-run-test test)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
607 (should (ert-test-passed-p result)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
608 (should (eql (length (ert-test-result-should-forms result)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
609 1))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
610 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
611 (ert-deftest ert-test-list-of-should-forms-no-deep-copy () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
612 (let ((test (make-ert-test :body (lambda () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
613 (let ((obj (list 'a))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
614 (should (equal obj '(a))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
615 (setf (car obj) 'b) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
616 (should (equal obj '(b)))))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
617 (let ((result (let ((ert-debug-on-error nil)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
618 (ert-run-test test)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
619 (should (ert-test-passed-p result)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
620 (should (equal (ert-test-result-should-forms result) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
621 '(((should (equal obj '(a))) :form (equal (b) (a)) :value t |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
622 :explanation nil) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
623 ((should (equal obj '(b))) :form (equal (b) (b)) :value t |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
624 :explanation nil) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
625 )))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
626 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
627 (ert-deftest ert-test-remprop () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
628 (let ((x (ert--gensym))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
629 (should (equal (symbol-plist x) '())) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
630 ;; Remove nonexistent property on empty plist. |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
631 (ert--remprop x 'b) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
632 (should (equal (symbol-plist x) '())) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
633 (put x 'a 1) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
634 (should (equal (symbol-plist x) '(a 1))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
635 ;; Remove nonexistent property on nonempty plist. |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
636 (ert--remprop x 'b) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
637 (should (equal (symbol-plist x) '(a 1))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
638 (put x 'b 2) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
639 (put x 'c 3) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
640 (put x 'd 4) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
641 (should (equal (symbol-plist x) '(a 1 b 2 c 3 d 4))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
642 ;; Remove property that is neither first nor last. |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
643 (ert--remprop x 'c) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
644 (should (equal (symbol-plist x) '(a 1 b 2 d 4))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
645 ;; Remove last property from a plist of length >1. |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
646 (ert--remprop x 'd) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
647 (should (equal (symbol-plist x) '(a 1 b 2))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
648 ;; Remove first property from a plist of length >1. |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
649 (ert--remprop x 'a) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
650 (should (equal (symbol-plist x) '(b 2))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
651 ;; Remove property when there is only one. |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
652 (ert--remprop x 'b) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
653 (should (equal (symbol-plist x) '())))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
654 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
655 (ert-deftest ert-test-remove-if-not () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
656 (let ((list (list 'a 'b 'c 'd)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
657 (i 0)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
658 (let ((result (ert--remove-if-not (lambda (x) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
659 (should (eql x (nth i list))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
660 (incf i) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
661 (member i '(2 3))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
662 list))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
663 (should (equal i 4)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
664 (should (equal result '(b c))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
665 (should (equal list '(a b c d))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
666 (should (equal '() |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
667 (ert--remove-if-not (lambda (x) (should nil)) '())))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
668 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
669 (ert-deftest ert-test-remove* () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
670 (let ((list (list 'a 'b 'c 'd)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
671 (key-index 0) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
672 (test-index 0)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
673 (let ((result |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
674 (ert--remove* 'foo list |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
675 :key (lambda (x) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
676 (should (eql x (nth key-index list))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
677 (prog1 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
678 (list key-index x) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
679 (incf key-index))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
680 :test |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
681 (lambda (a b) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
682 (should (eql a 'foo)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
683 (should (equal b (list test-index |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
684 (nth test-index list)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
685 (incf test-index) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
686 (member test-index '(2 3)))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
687 (should (equal key-index 4)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
688 (should (equal test-index 4)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
689 (should (equal result '(a d))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
690 (should (equal list '(a b c d))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
691 (let ((x (cons nil nil)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
692 (y (cons nil nil))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
693 (should (equal (ert--remove* x (list x y)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
694 ;; or (list x), since we use `equal' -- the |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
695 ;; important thing is that only one element got |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
696 ;; removed, this proves that the default test is |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
697 ;; `eql', not `equal' |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
698 (list y))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
699 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
700 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
701 (ert-deftest ert-test-set-functions () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
702 (let ((c1 (cons nil nil)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
703 (c2 (cons nil nil)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
704 (sym (make-symbol "a"))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
705 (let ((e '()) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
706 (a (list 'a 'b sym nil "" "x" c1 c2)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
707 (b (list c1 'y 'b sym 'x))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
708 (should (equal (ert--set-difference e e) e)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
709 (should (equal (ert--set-difference a e) a)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
710 (should (equal (ert--set-difference e a) e)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
711 (should (equal (ert--set-difference a a) e)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
712 (should (equal (ert--set-difference b e) b)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
713 (should (equal (ert--set-difference e b) e)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
714 (should (equal (ert--set-difference b b) e)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
715 (should (equal (ert--set-difference a b) (list 'a nil "" "x" c2))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
716 (should (equal (ert--set-difference b a) (list 'y 'x))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
717 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
718 ;; We aren't testing whether this is really using `eq' rather than `eql'. |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
719 (should (equal (ert--set-difference-eq e e) e)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
720 (should (equal (ert--set-difference-eq a e) a)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
721 (should (equal (ert--set-difference-eq e a) e)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
722 (should (equal (ert--set-difference-eq a a) e)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
723 (should (equal (ert--set-difference-eq b e) b)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
724 (should (equal (ert--set-difference-eq e b) e)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
725 (should (equal (ert--set-difference-eq b b) e)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
726 (should (equal (ert--set-difference-eq a b) (list 'a nil "" "x" c2))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
727 (should (equal (ert--set-difference-eq b a) (list 'y 'x))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
728 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
729 (should (equal (ert--union e e) e)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
730 (should (equal (ert--union a e) a)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
731 (should (equal (ert--union e a) a)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
732 (should (equal (ert--union a a) a)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
733 (should (equal (ert--union b e) b)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
734 (should (equal (ert--union e b) b)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
735 (should (equal (ert--union b b) b)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
736 (should (equal (ert--union a b) (list 'a 'b sym nil "" "x" c1 c2 'y 'x))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
737 (should (equal (ert--union b a) (list c1 'y 'b sym 'x 'a nil "" "x" c2))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
738 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
739 (should (equal (ert--intersection e e) e)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
740 (should (equal (ert--intersection a e) e)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
741 (should (equal (ert--intersection e a) e)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
742 (should (equal (ert--intersection a a) a)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
743 (should (equal (ert--intersection b e) e)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
744 (should (equal (ert--intersection e b) e)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
745 (should (equal (ert--intersection b b) b)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
746 (should (equal (ert--intersection a b) (list 'b sym c1))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
747 (should (equal (ert--intersection b a) (list c1 'b sym)))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
748 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
749 (ert-deftest ert-test-gensym () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
750 ;; Since the expansion of `should' calls `ert--gensym' and thus has a |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
751 ;; side-effect on `ert--gensym-counter', we have to make sure all |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
752 ;; macros in our test body are expanded before we rebind |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
753 ;; `ert--gensym-counter' and run the body. Otherwise, the test would |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
754 ;; fail if run interpreted. |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
755 (let ((body (byte-compile |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
756 '(lambda () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
757 (should (equal (symbol-name (ert--gensym)) "G0")) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
758 (should (equal (symbol-name (ert--gensym)) "G1")) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
759 (should (equal (symbol-name (ert--gensym)) "G2")) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
760 (should (equal (symbol-name (ert--gensym "foo")) "foo3")) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
761 (should (equal (symbol-name (ert--gensym "bar")) "bar4")) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
762 (should (equal ert--gensym-counter 5)))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
763 (let ((ert--gensym-counter 0)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
764 (funcall body)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
765 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
766 (ert-deftest ert-test-coerce-to-vector () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
767 (let* ((a (vector)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
768 (b (vector 1 a 3)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
769 (c (list)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
770 (d (list b a))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
771 (should (eql (ert--coerce-to-vector a) a)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
772 (should (eql (ert--coerce-to-vector b) b)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
773 (should (equal (ert--coerce-to-vector c) (vector))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
774 (should (equal (ert--coerce-to-vector d) (vector b a))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
775 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
776 (ert-deftest ert-test-string-position () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
777 (should (eql (ert--string-position ?x "") nil)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
778 (should (eql (ert--string-position ?a "abc") 0)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
779 (should (eql (ert--string-position ?b "abc") 1)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
780 (should (eql (ert--string-position ?c "abc") 2)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
781 (should (eql (ert--string-position ?d "abc") nil)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
782 (should (eql (ert--string-position ?A "abc") nil))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
783 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
784 (ert-deftest ert-test-mismatch () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
785 (should (eql (ert--mismatch "" "") nil)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
786 (should (eql (ert--mismatch "" "a") 0)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
787 (should (eql (ert--mismatch "a" "a") nil)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
788 (should (eql (ert--mismatch "ab" "a") 1)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
789 (should (eql (ert--mismatch "Aa" "aA") 0)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
790 (should (eql (ert--mismatch '(a b c) '(a b d)) 2))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
791 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
792 (ert-deftest ert-test-string-first-line () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
793 (should (equal (ert--string-first-line "") "")) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
794 (should (equal (ert--string-first-line "abc") "abc")) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
795 (should (equal (ert--string-first-line "abc\n") "abc")) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
796 (should (equal (ert--string-first-line "foo\nbar") "foo")) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
797 (should (equal (ert--string-first-line " foo\nbar\nbaz\n") " foo"))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
798 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
799 (ert-deftest ert-test-explain-not-equal () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
800 (should (equal (ert--explain-not-equal nil 'foo) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
801 '(different-atoms nil foo))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
802 (should (equal (ert--explain-not-equal '(a a) '(a b)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
803 '(list-elt 1 (different-atoms a b)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
804 (should (equal (ert--explain-not-equal '(1 48) '(1 49)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
805 '(list-elt 1 (different-atoms (48 "#x30" "?0") |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
806 (49 "#x31" "?1"))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
807 (should (equal (ert--explain-not-equal 'nil '(a)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
808 '(different-types nil (a)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
809 (should (equal (ert--explain-not-equal '(a b c) '(a b c d)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
810 '(proper-lists-of-different-length 3 4 (a b c) (a b c d) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
811 first-mismatch-at 3))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
812 (let ((sym (make-symbol "a"))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
813 (should (equal (ert--explain-not-equal 'a sym) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
814 `(different-symbols-with-the-same-name a ,sym))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
815 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
816 (ert-deftest ert-test-explain-not-equal-improper-list () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
817 (should (equal (ert--explain-not-equal '(a . b) '(a . c)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
818 '(cdr (different-atoms b c))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
819 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
820 (ert-deftest ert-test-significant-plist-keys () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
821 (should (equal (ert--significant-plist-keys '()) '())) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
822 (should (equal (ert--significant-plist-keys '(a b c d e f c g p q r nil s t)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
823 '(a c e p s)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
824 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
825 (ert-deftest ert-test-plist-difference-explanation () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
826 (should (equal (ert--plist-difference-explanation |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
827 '(a b c nil) '(a b)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
828 nil)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
829 (should (equal (ert--plist-difference-explanation |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
830 '(a b c t) '(a b)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
831 '(different-properties-for-key c (different-atoms t nil)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
832 (should (equal (ert--plist-difference-explanation |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
833 '(a b c t) '(c nil a b)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
834 '(different-properties-for-key c (different-atoms t nil)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
835 (should (equal (ert--plist-difference-explanation |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
836 '(a b c (foo . bar)) '(c (foo . baz) a b)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
837 '(different-properties-for-key c |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
838 (cdr |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
839 (different-atoms bar baz)))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
840 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
841 (ert-deftest ert-test-abbreviate-string () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
842 (should (equal (ert--abbreviate-string "foo" 4 nil) "foo")) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
843 (should (equal (ert--abbreviate-string "foo" 3 nil) "foo")) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
844 (should (equal (ert--abbreviate-string "foo" 3 nil) "foo")) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
845 (should (equal (ert--abbreviate-string "foo" 2 nil) "fo")) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
846 (should (equal (ert--abbreviate-string "foo" 1 nil) "f")) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
847 (should (equal (ert--abbreviate-string "foo" 0 nil) "")) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
848 (should (equal (ert--abbreviate-string "bar" 4 t) "bar")) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
849 (should (equal (ert--abbreviate-string "bar" 3 t) "bar")) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
850 (should (equal (ert--abbreviate-string "bar" 3 t) "bar")) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
851 (should (equal (ert--abbreviate-string "bar" 2 t) "ar")) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
852 (should (equal (ert--abbreviate-string "bar" 1 t) "r")) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
853 (should (equal (ert--abbreviate-string "bar" 0 t) ""))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
854 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
855 (ert-deftest ert-test-explain-not-equal-string-properties () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
856 (should |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
857 (equal (ert--explain-not-equal-including-properties #("foo" 0 1 (a b)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
858 "foo") |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
859 '(char 0 "f" |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
860 (different-properties-for-key a (different-atoms b nil)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
861 context-before "" |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
862 context-after "oo"))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
863 (should (equal (ert--explain-not-equal-including-properties |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
864 #("foo" 1 3 (a b)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
865 #("goo" 0 1 (c d))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
866 '(array-elt 0 (different-atoms (?f "#x66" "?f") |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
867 (?g "#x67" "?g"))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
868 (should |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
869 (equal (ert--explain-not-equal-including-properties |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
870 #("foo" 0 1 (a b c d) 1 3 (a b)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
871 #("foo" 0 1 (c d a b) 1 2 (a foo))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
872 '(char 1 "o" (different-properties-for-key a (different-atoms b foo)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
873 context-before "f" context-after "o")))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
874 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
875 (ert-deftest ert-test-equal-including-properties () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
876 (should (equal-including-properties "foo" "foo")) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
877 (should (ert-equal-including-properties "foo" "foo")) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
878 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
879 (should (equal-including-properties #("foo" 0 3 (a b)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
880 (propertize "foo" 'a 'b))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
881 (should (ert-equal-including-properties #("foo" 0 3 (a b)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
882 (propertize "foo" 'a 'b))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
883 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
884 (should (equal-including-properties #("foo" 0 3 (a b c d)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
885 (propertize "foo" 'a 'b 'c 'd))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
886 (should (ert-equal-including-properties #("foo" 0 3 (a b c d)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
887 (propertize "foo" 'a 'b 'c 'd))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
888 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
889 (should-not (equal-including-properties #("foo" 0 3 (a b c e)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
890 (propertize "foo" 'a 'b 'c 'd))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
891 (should-not (ert-equal-including-properties #("foo" 0 3 (a b c e)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
892 (propertize "foo" 'a 'b 'c 'd))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
893 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
894 ;; This is bug 6581. |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
895 (should-not (equal-including-properties #("foo" 0 3 (a (t))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
896 (propertize "foo" 'a (list t)))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
897 (should (ert-equal-including-properties #("foo" 0 3 (a (t))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
898 (propertize "foo" 'a (list t))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
899 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
900 (ert-deftest ert-test-stats-set-test-and-result () |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
901 (let* ((test-1 (make-ert-test :name 'test-1 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
902 :body (lambda () nil))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
903 (test-2 (make-ert-test :name 'test-2 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
904 :body (lambda () nil))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
905 (test-3 (make-ert-test :name 'test-2 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
906 :body (lambda () nil))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
907 (stats (ert--make-stats (list test-1 test-2) 't)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
908 (failed (make-ert-test-failed :condition nil |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
909 :backtrace nil |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
910 :infos nil))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
911 (should (eql 2 (ert-stats-total stats))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
912 (should (eql 0 (ert-stats-completed stats))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
913 (should (eql 0 (ert-stats-completed-expected stats))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
914 (should (eql 0 (ert-stats-completed-unexpected stats))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
915 (ert--stats-set-test-and-result stats 0 test-1 (make-ert-test-passed)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
916 (should (eql 2 (ert-stats-total stats))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
917 (should (eql 1 (ert-stats-completed stats))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
918 (should (eql 1 (ert-stats-completed-expected stats))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
919 (should (eql 0 (ert-stats-completed-unexpected stats))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
920 (ert--stats-set-test-and-result stats 0 test-1 failed) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
921 (should (eql 2 (ert-stats-total stats))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
922 (should (eql 1 (ert-stats-completed stats))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
923 (should (eql 0 (ert-stats-completed-expected stats))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
924 (should (eql 1 (ert-stats-completed-unexpected stats))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
925 (ert--stats-set-test-and-result stats 0 test-1 nil) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
926 (should (eql 2 (ert-stats-total stats))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
927 (should (eql 0 (ert-stats-completed stats))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
928 (should (eql 0 (ert-stats-completed-expected stats))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
929 (should (eql 0 (ert-stats-completed-unexpected stats))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
930 (ert--stats-set-test-and-result stats 0 test-3 failed) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
931 (should (eql 2 (ert-stats-total stats))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
932 (should (eql 1 (ert-stats-completed stats))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
933 (should (eql 0 (ert-stats-completed-expected stats))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
934 (should (eql 1 (ert-stats-completed-unexpected stats))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
935 (ert--stats-set-test-and-result stats 1 test-2 (make-ert-test-passed)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
936 (should (eql 2 (ert-stats-total stats))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
937 (should (eql 2 (ert-stats-completed stats))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
938 (should (eql 1 (ert-stats-completed-expected stats))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
939 (should (eql 1 (ert-stats-completed-unexpected stats))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
940 (ert--stats-set-test-and-result stats 0 test-1 (make-ert-test-passed)) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
941 (should (eql 2 (ert-stats-total stats))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
942 (should (eql 2 (ert-stats-completed stats))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
943 (should (eql 2 (ert-stats-completed-expected stats))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
944 (should (eql 0 (ert-stats-completed-unexpected stats))))) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
945 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
946 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
947 (provide 'ert-tests) |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
948 |
c5917804ecad
Add ERT, a tool for automated testing in Emacs Lisp.
Christian Ohler <ohler@gnu.org>
parents:
diff
changeset
|
949 ;;; ert-tests.el ends here |